Skip to content

repository: Avoid duplicate index lookup when loading blob/tree#2629

Closed
MichaelEischer wants to merge 1 commit intorestic:masterfrom
MichaelEischer:loadblob-autoalloc
Closed

repository: Avoid duplicate index lookup when loading blob/tree#2629
MichaelEischer wants to merge 1 commit intorestic:masterfrom
MichaelEischer:loadblob-autoalloc

Conversation

@MichaelEischer
Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer commented Mar 7, 2020

What is the purpose of this change? What does it change?

LoadBlob and LoadTree lookup the blob size in the index and use it to allocate a buffer for loadBlob which 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 read the Contribution Guidelines
  • I have enabled maintainer edits for this PR
  • I have added tests for all changes in this PR
  • [ ] I have added documentation for the changes (in the manual)
  • [ ] There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

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.
// 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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second return value is redundant. The []byte can be sliced to the right length before return.

@MichaelEischer MichaelEischer deleted the loadblob-autoalloc branch April 18, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants