Repository navigation
lib/fs: Optimize UnicodeLowercase - #6979
Conversation
|
I must confess that I don't know what's causing Overallocating a few bytes (say, 4 or 10) can decrease the alloc/op to 208B, but I don't understand why. The encoded output is never longer than the encoded input in the benchmark. |
b586f08 to
4693ff6
Compare
|
Found it, see updated benchmark results and comment in the code. |
Most notably, it now detects all-lowercase files and returns these as-is. The tests have been expanded with two cases and are now used as a benchmark (admittedly a rather trivial one). Benchmark results on Linux/amd64 (WalkCaseFakeFS100k creates all-lowercase filenames): name old time/op new time/op delta WalkCaseFakeFS100k/rawfs-8 388ms ± 1% 312ms ± 3% -19.64% (p=0.000 n=10+8) WalkCaseFakeFS100k/casefs-8 718ms ± 1% 587ms ± 1% -18.30% (p=0.000 n=10+10) UnicodeLowercaseMaybeChange-8 5.45µs ± 5% 4.59µs ± 2% -15.81% (p=0.000 n=10+10) UnicodeLowercaseNoChange-8 5.33µs ± 4% 3.25µs ± 1% -39.02% (p=0.000 n=10+10) name old B/entry new B/entry delta WalkCaseFakeFS100k/rawfs-8 590 ± 0% 530 ± 0% -10.17% (p=0.000 n=10+10) WalkCaseFakeFS100k/casefs-8 869 ± 0% 760 ± 0% -12.54% (p=0.000 n=10+10) name old allocs/entry new allocs/entry delta WalkCaseFakeFS100k/rawfs-8 15.7 ± 0% 12.1 ± 0% -22.93% (p=0.000 n=10+10) WalkCaseFakeFS100k/casefs-8 26.1 ± 0% 20.1 ± 0% -22.99% (p=0.000 n=10+10) name old ns/entry new ns/entry delta WalkCaseFakeFS100k/rawfs-8 2.57k ± 1% 2.06k ± 3% -19.65% (p=0.000 n=10+8) WalkCaseFakeFS100k/casefs-8 4.75k ± 1% 3.86k ± 1% -18.63% (p=0.000 n=10+10) name old alloc/op new alloc/op delta WalkCaseFakeFS100k/rawfs-8 89.2MB ± 0% 80.2MB ± 0% -10.08% (p=0.000 n=9+10) WalkCaseFakeFS100k/casefs-8 131MB ± 0% 115MB ± 0% -12.54% (p=0.000 n=9+10) UnicodeLowercaseMaybeChange-8 320B ± 0% 192B ± 0% -40.00% (p=0.000 n=10+10) UnicodeLowercaseNoChange-8 320B ± 0% 0B -100.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta WalkCaseFakeFS100k/rawfs-8 2.38M ± 0% 1.82M ± 0% -23.44% (p=0.002 n=8+10) WalkCaseFakeFS100k/casefs-8 3.95M ± 0% 3.04M ± 0% -23.10% (p=0.000 n=10+9) UnicodeLowercaseMaybeChange-8 16.0 ± 0% 10.0 ± 0% -37.50% (p=0.000 n=10+10) UnicodeLowercaseNoChange-8 16.0 ± 0% 0.0 -100.00% (p=0.000 n=10+10)
4693ff6 to
2d0a118
Compare
|
So this is neat, though I think the benchmarks aren't useful here. The improvement is equally large for the |
I'm not sure I follow completely. Should I remove the rawfs benchmark results from the commit message? The casefs ones? Both? |
name old time/op new time/op delta UnicodeLowercaseMaybeChange-8 4.59µs ± 2% 4.57µs ± 1% ~ (p=0.197 n=10+10) UnicodeLowercaseNoChange-8 3.26µs ± 1% 3.09µs ± 1% -5.27% (p=0.000 n=9+10)
| // even if it doesn't need all that space. Overallocate now to prevent | ||
| // it from ever triggering a reallocation. | ||
| rs.Grow(utf8.UTFMax - 1 + len(s)) | ||
| rs.WriteString(s[:i]) |
There was a problem hiding this comment.
I don't think this works in the general case. firstCaseChange returns the index of the first rune to have its case changed, while s[:i] is counted in bytes. This should break for strings with lowercase non-ASCII characters in the beginning, which may not be any of our current test cases
There was a problem hiding this comment.
My bad, this is fine. (Index in loop over string is in fact byte position, not rune number. TIL.)
* main: (50 commits) cmd/ursrv: Properly sort versions (fixes syncthing#6991) cmd/ursrv: Recognize new-style dev versions gui, man, authors: Update docs, translations, and contributors build: Dockerfile that expects ready baked binaries lib/model: Consider case conflicts when checking to be deleted items (syncthing#6986) lib/fs: Optimize UnicodeLowercase (syncthing#6979) lib/db, lib/syncthing: Don't repair DB on upgrade, but on error (fixes syncthing#6917) (syncthing#6971) lib/model: Consider existing file when handling symlink on windows (syncthing#6977) lib/model: Handle symlink deletion on windows (fixes syncthing#6972) (syncthing#6976) lib/model: Fix case-only renames on pull (syncthing#6978) lib/fs: More efficient casefs cache (syncthing#6974) lib/model: Don't fail over case-conflict on tempfile (fixes syncthing#6973) (syncthing#6975) gui, man, authors: Update docs, translations, and contributors lib/fs: Use generic case resolver on windows (fixes syncthing#6968) (syncthing#6969) lib/model: Prevent duplicate need count on recalculating metadata (syncthing#6964) lib/db, lib/protocol: Never need empty-version entries (fixes syncthing#6961) (syncthing#6962) lib/model: Correct completion perc. when globalBytes is 0 (syncthing#6963) lib/db: Don't hang on double iterator release with Badger (syncthing#6960) test, lib/model: Various integration test updates & improvements (syncthing#6956) lib/db: Copy returned, old FileVersion (syncthing#6952) ...
Most notably, it now detects all-lowercase files and returns these as-is. The tests have been expanded with two cases and are now used as a benchmark (admittedly a rather trivial one).
Benchmark results on Linux/amd64 (note that WalkCaseFakeFS100k creates all-lowercase filenames):