Skip to content

memfs: Speed up store.put and removeAll#9

Merged
mojatter merged 2 commits into
mainfrom
perf/memfs-store
Apr 6, 2026
Merged

memfs: Speed up store.put and removeAll#9
mojatter merged 2 commits into
mainfrom
perf/memfs-store

Conversation

@mojatter
Copy link
Copy Markdown
Owner

@mojatter mojatter commented Apr 6, 2026

store.put previously called sort.Strings on the entire keys slice for every insert, making bulk loads O(n^2 log n). Replace it with a SearchStrings + slice insert that is O(n) per put. removeAll did a linear scan to find the end of the prefix range; replace it with a binary search since the slice is already sorted.

Behavior is unchanged; add a benchmark for store.put so future regressions are visible.

BenchmarkStore_put results:

ns/op B/op allocs/op
Before (sort.Strings on every put) ~43,800,000 1,076,656
After (SearchStrings) ~1,402,000 1,076,664

store.put previously called sort.Strings on the entire keys slice for
every insert, making bulk loads O(n^2 log n). Replace it with a
SearchStrings + slice insert that is O(n) per put. removeAll did a
linear scan to find the end of the prefix range; replace it with a
binary search since the slice is already sorted.

Behavior is unchanged; add a benchmark for store.put so future
regressions are visible.
@mojatter mojatter changed the title memfs: speed up store.put and removeAll memfs: Speed up store.put and removeAll Apr 6, 2026
@mojatter mojatter merged commit 3a77c3f into main Apr 6, 2026
1 check passed
@mojatter mojatter deleted the perf/memfs-store branch April 6, 2026 04:57
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.

1 participant