-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use optimal block length to generate deltas
Previously, we used a block length hardcoded to 512 bytes. Our measurements have shown that this value was generally inadequate: it produced relatively large deltas and took relatively long times to do that. librsync, by default, uses block length equals to the square root of the old (basis) file. This value results in significantly smaller deltas and shorter run times. In this commit, we do one more optimization and round this value up to the next power of two value. Since librsync-go has a code path optimized for buffers with sizes that are powers of two, this gives us another performance gain.
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package images | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"testing" | ||
) | ||
|
||
func Test_deltaBlockSize(t *testing.T) { | ||
tests := []struct { | ||
x int64 | ||
want uint32 | ||
}{ | ||
{0, 1}, | ||
{1, 1}, | ||
{100, 16}, | ||
{256, 16}, | ||
{288, 16}, | ||
{289, 32}, | ||
{1_024, 32}, | ||
{33_333, 256}, | ||
{88_887, 512}, | ||
{262_144, 512}, | ||
{262_145, 512}, | ||
{777_111, 1024}, | ||
{22_654_123, 8192}, | ||
{1_333_555_888, 65536}, | ||
{35_000_000_000, 262144}, | ||
{123_456_678_901, 524288}, | ||
{4_611_686_018_427_387_904, 2147483648}, | ||
{5_000_000_000_000_000_000, 2147483648}, | ||
{math.MaxInt64, 2147483648}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(fmt.Sprintf("deltaBlockSize(%v)", tt.x), func(t *testing.T) { | ||
if got := deltaBlockSize(tt.x); got != tt.want { | ||
t.Errorf("got deltaBlockSize(%v) = %v, want %v", tt.x, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |