repository: Avoid duplicate index lookup when loading blob/tree#2629
Closed
MichaelEischer wants to merge 1 commit intorestic:masterfrom
Closed
repository: Avoid duplicate index lookup when loading blob/tree#2629MichaelEischer wants to merge 1 commit intorestic:masterfrom
MichaelEischer wants to merge 1 commit intorestic:masterfrom
Conversation
loadBlob() must lookup the blob in the index anyways. loadBlob can now allocate a blob buffer. This removes the need for size lookups in LoadTree.
greatroar
reviewed
Mar 8, 2020
| // large enough to hold the complete blob. | ||
| func (r *Repository) loadBlob(ctx context.Context, id restic.ID, t restic.BlobType, plaintextBuf []byte) (int, error) { | ||
| debug.Log("load %v with id %v (buf len %v, cap %d)", t, id, len(plaintextBuf), cap(plaintextBuf)) | ||
| func (r *Repository) loadBlob(ctx context.Context, id restic.ID, t restic.BlobType, plaintextBuf []byte) ([]byte, int, error) { |
Contributor
There was a problem hiding this comment.
The second return value is redundant. The []byte can be sliced to the right length before return.
6 tasks
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.
What is the purpose of this change? What does it change?
LoadBlobandLoadTreelookup the blob size in the index and use it to allocate a buffer forloadBlobwhich has to run another index lookup. Especially for large repositories index lookups are rather expensive, see #2523 .This PR lets
loadBlob()allocate the blob buffer itself and thus removes the duplicate index lookup.I did not include a changelog entry as this PR only slightly improves performance.
Was the change discussed in an issue or in the forum before?
No, the inefficiency showed up during work on #2328.
Checklist
[ ] I have added documentation for the changes (in the manual)[ ] There's a new file inchangelog/unreleased/that describes the changes for our users (template here)gofmton the code in all commits