Skip to content

fix(scanner): keep StringPool's index across push_raw so macOS scans stay linear - #138

Open
huntharo wants to merge 1 commit into
tobi:mainfrom
huntharo:fix/string-pool-quadratic-intern
Open

huntharo wants to merge 1 commit into
tobi:mainfrom
huntharo:fix/string-pool-quadratic-intern

Conversation

@huntharo

@huntharo huntharo commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

What

StringPool::push_raw threw away the pool's lookup table, so the next intern rebuilt it from every name in the pool. Building the arena on macOS (and anywhere the non-Linux walker builds a BuiltChild tree, walk.rs) adds each directory with add_child_raw → push_raw and each file with add_child → intern. So every directory triggered a full rebuild, and a scan's time grew with directories × names. It came in with 2203025, when the hot walker moved to push_raw.

push_raw now updates the table when one exists: a vacant slot takes the new id; an occupied one records it in collisions, as ensure_index does. A pool filled only raw still never builds a table, so the zero-hash path is unchanged.

Numbers

Apple M5 Max, macOS, a cold in-memory scan (Scanner::new(StorageMode::InMemory, …) then scan_blocking) of a folder of git checkouts: 2,058,930 files, 362,568 directories.

scan peak memory
main (73bdbb3) 203 / 222 / 243 s 427–475 MB
this PR 6.0 / 6.4 s 467–473 MB
9b18b27, before the scanner rewrite 5.9 / 6.2 / 6.4 s 363–365 MB

Same file and directory counts before and after.

Tests

  • push_raw_keeps_a_built_index: fails on main, passes here.
  • push_raw_alone_builds_no_index: the raw-only path still never hashes.
  • mixed_push_raw_and_intern_match_a_map_model: random interleavings (fixed seed) against a set: intern returns an id holding its value and never re-adds a value the pool holds.

cargo xtask lint is green; cargo test -p disktree-scanner passes.

…stay linear

The arena build adds directories with add_child_raw (push_raw) and files
with add_child (intern). push_raw dropped the lookup table, so the next
intern rebuilt it over every name so far: once per directory, making a
scan quadratic in the names it holds. push_raw now updates a table that
exists and still builds none for a pool filled only raw.
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