Skip to content

Simplify Repository.LoadBlob usage#2640

Merged
MichaelEischer merged 2 commits intorestic:masterfrom
greatroar:simplify-loadblob-usage
Apr 23, 2020
Merged

Simplify Repository.LoadBlob usage#2640
MichaelEischer merged 2 commits intorestic:masterfrom
greatroar:simplify-loadblob-usage

Conversation

@greatroar
Copy link
Copy Markdown
Contributor

@greatroar greatroar commented Mar 10, 2020

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

Repository.LoadBlob currently requires its caller to compute the size of the buffer it needs. It then checks whether the buffer has the right size, and its helper loadBlob checks again. This leads to much duplicated, yet subtly different, code for computing sizes as well as repeated index lookups.

This PR changes LoadBlob to just return a freshly allocated buffer if insufficient space was passed in. The benchmarks show that fewer allocations have to be performed. The simplified code also makes it easier to add compression, since LoadBlob callers no longer need to know how big their buffers need to be (they'd have to know about compression as well as encryption).

name              old time/op    new time/op    delta
LoadTree-8           479µs ± 2%     481µs ± 2%    ~     (p=0.684 n=10+10)
LoadBlob-8          11.6ms ± 2%    11.6ms ± 2%    ~     (p=0.393 n=10+10)
LoadAndDecrypt-8    13.2ms ± 2%    13.3ms ± 3%    ~     (p=0.604 n=10+9)
LoadIndex-8         33.4ms ± 2%    33.2ms ± 1%    ~     (p=0.161 n=9+9)

name              old alloc/op   new alloc/op   delta
LoadTree-8          41.2kB ± 0%    41.1kB ± 0%  -0.23%  (p=0.000 n=10+10)
LoadBlob-8          2.28kB ± 0%    2.18kB ± 0%  -4.21%  (p=0.000 n=10+10)
LoadAndDecrypt-8    2.10MB ± 0%    2.10MB ± 0%    ~     (all equal)
LoadIndex-8         5.22MB ± 0%    5.22MB ± 0%    ~     (p=0.853 n=10+10)

name              old allocs/op  new allocs/op  delta
LoadTree-8             652 ± 0%       651 ± 0%  -0.15%  (p=0.000 n=10+10)
LoadBlob-8            24.0 ± 0%      23.0 ± 0%  -4.17%  (p=0.000 n=10+10)
LoadAndDecrypt-8      30.0 ± 0%      30.0 ± 0%    ~     (all equal)
LoadIndex-8          30.2k ± 0%     30.2k ± 0%    ~     (p=0.664 n=10+10)

name              old speed      new speed      delta
LoadBlob-8        86.2MB/s ± 2%  85.9MB/s ± 2%    ~     (p=0.393 n=10+10)
LoadAndDecrypt-8  75.7MB/s ± 2%  75.4MB/s ± 3%    ~     (p=0.603 n=10+9)

There is one functional change, which is the error message from LoadTree will now say "id %v not found in repository" rather than "tree %v not found in repository".

Was the change discussed in an issue or in the forum before?

Closes #2629.

Checklist

@greatroar greatroar force-pushed the simplify-loadblob-usage branch from 0fe2a73 to 49e582d Compare March 10, 2020 17:03
@greatroar
Copy link
Copy Markdown
Contributor Author

greatroar commented Mar 10, 2020

I also tested this with restic dump on a 4GB file. It's neither slower, nor faster. The SHA256 checks out.

@MichaelEischer
Copy link
Copy Markdown
Member

So I guess this obsoletes #2629 ?

@greatroar
Copy link
Copy Markdown
Contributor Author

Yes. Sorry, I had forgotten about that one.

Copy link
Copy Markdown
Member

@MichaelEischer MichaelEischer left a comment

Choose a reason for hiding this comment

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

I've got just two minor points, see the review comments. Once these and the merge conflict are resolved, the PR is ready for merging.

@MichaelEischer MichaelEischer mentioned this pull request Apr 19, 2020
7 tasks
@greatroar greatroar force-pushed the simplify-loadblob-usage branch from 251e80f to 096c495 Compare April 22, 2020 12:55
@greatroar
Copy link
Copy Markdown
Contributor Author

I've merged with the earliest commit on master that resolved the merge conflict to get the CI working again. I hope that's ok.

@greatroar greatroar force-pushed the simplify-loadblob-usage branch from 657c119 to 726cc87 Compare April 22, 2020 17:01
@MichaelEischer
Copy link
Copy Markdown
Member

Could you rebase the branch on the current master, that would lead to a much cleaner commit history (I could also do the rebase, if that's easier for you)? Sorry for being unclear on what I had in mind to resolve the merge conflict.

greatroar added 2 commits April 23, 2020 10:04
Benchmark results for internal/repository:

name              old time/op    new time/op    delta
LoadTree-8           479µs ± 2%     478µs ± 1%   ~     (p=0.780 n=10+9)
LoadBlob-8          11.6ms ± 2%    11.6ms ± 1%   ~     (p=0.631 n=10+10)
LoadAndDecrypt-8    13.2ms ± 2%    13.3ms ± 3%   ~     (p=0.631 n=10+10)

name              old alloc/op   new alloc/op   delta
LoadTree-8          41.2kB ± 0%    41.2kB ± 0%   ~     (all equal)
LoadBlob-8          2.28kB ± 0%    2.28kB ± 0%   ~     (all equal)
LoadAndDecrypt-8    2.10MB ± 0%    2.10MB ± 0%   ~     (all equal)

name              old allocs/op  new allocs/op  delta
LoadTree-8             652 ± 0%       652 ± 0%   ~     (all equal)
LoadBlob-8            24.0 ± 0%      24.0 ± 0%   ~     (all equal)
LoadAndDecrypt-8      30.0 ± 0%      30.0 ± 0%   ~     (all equal)

name              old speed      new speed      delta
LoadBlob-8        86.2MB/s ± 2%  86.4MB/s ± 1%   ~     (p=0.594 n=10+10)
LoadAndDecrypt-8  75.7MB/s ± 2%  75.4MB/s ± 3%   ~     (p=0.617 n=10+10)
Pushing the allocation logic down into the former loadBlob body means
that fewer allocations have to be performed:

name              old time/op    new time/op    delta
LoadTree-8           478µs ± 1%     481µs ± 2%    ~     (p=0.315 n=9+10)
LoadBlob-8          11.6ms ± 1%    11.6ms ± 2%    ~     (p=0.393 n=10+10)
LoadAndDecrypt-8    13.3ms ± 3%    13.3ms ± 3%    ~     (p=0.905 n=10+9)
LoadIndex-8         33.6ms ± 2%    33.2ms ± 1%  -1.15%  (p=0.028 n=10+9)

name              old alloc/op   new alloc/op   delta
LoadTree-8          41.2kB ± 0%    41.1kB ± 0%  -0.23%  (p=0.000 n=10+10)
LoadBlob-8          2.28kB ± 0%    2.18kB ± 0%  -4.21%  (p=0.000 n=10+10)
LoadAndDecrypt-8    2.10MB ± 0%    2.10MB ± 0%    ~     (all equal)
LoadIndex-8         5.22MB ± 0%    5.22MB ± 0%    ~     (p=0.631 n=10+10)

name              old allocs/op  new allocs/op  delta
LoadTree-8             652 ± 0%       651 ± 0%  -0.15%  (p=0.000 n=10+10)
LoadBlob-8            24.0 ± 0%      23.0 ± 0%  -4.17%  (p=0.000 n=10+10)
LoadAndDecrypt-8      30.0 ± 0%      30.0 ± 0%    ~     (all equal)
LoadIndex-8          30.2k ± 0%     30.2k ± 0%    ~     (p=0.610 n=10+10)

name              old speed      new speed      delta
LoadBlob-8        86.4MB/s ± 1%  85.9MB/s ± 2%    ~     (p=0.393 n=10+10)
LoadAndDecrypt-8  75.4MB/s ± 3%  75.4MB/s ± 3%    ~     (p=0.858 n=10+9)
@greatroar greatroar force-pushed the simplify-loadblob-usage branch from 726cc87 to e7d7b85 Compare April 23, 2020 08:16
@greatroar
Copy link
Copy Markdown
Contributor Author

I was hesitant to rebase because the last time it triggered a re-review, but I did it now.

@MichaelEischer MichaelEischer merged commit d4bd32a into restic:master Apr 23, 2020
@MichaelEischer
Copy link
Copy Markdown
Member

Merged, thanks! Github seems to have detected the rebase. Btw, your master branch seems to be slightly out of date.

@greatroar greatroar deleted the simplify-loadblob-usage branch April 24, 2020 07:27
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