Repository navigation
Conversation
Opening and closing transactions constantly is rather expensive, and transaction semantics don't actually matter for bare Update() calls, so just use a more efficient Batch there instead. In a test of importing 2k packages, this cut the runtime from ~1m48s to ~1m6s, an improvement of nearly 40%.
When importing a large number of files, most of the time can just end up
spent computing checksums, as all of MD5/SHA1/SHA256/SHA512 are computed
in sequential order. However, parallelizing the hashing algorithms
themselves is difficult, because they all take very different lengths of
time, and trying an inner layer of parallelism if the caller is already
using its own parallelism won't actually make anything faster.
Instead, we can attack this from multiple angles:
- The process of computing the checksums as a whole can be run in
parallel across different files.
- Since the checksums themselves still run in sequence, processing
large files towards the front gives better performance, because
if they end up towards the end, then the large ones will be stuck
continuing to be processed while the other goroutines sit idle.
- ChecksumsForReader and its callers can now optionally take a custom
buffer, allowing the use of a larger read buffer than the 32KiB
io.Copy default.
- This can't be created in ChecksumsForReader itself, because then Go
will spill the buffer to the heap on every invocation, whereas the
caller can create the buffer once and reuse it for all invocations.
To avoid a confusing idle period before any progress is printed, an
additional progress bar is shown with the checksum progress.
In a test of importing 2k packages, this cut the runtime from ~1m6s to
~28s, an improvement of over 56%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the Change
This is a set of two optimizations to package importing:
The individual commits have further descriptions of the changes.
In a test where I took a random sample of 2k packages from the apertis target component, the import time across these two changes from ~1m48s to ~28s, nearly 4x faster.
Checklist
AUTHORS