Skip to content

Fix: Rehash slot_lookup_ tombstones to stop ghost entries under churn - #769

Merged
ashvardanian merged 1 commit into
unum-cloud:main-devfrom
desertfury:feat/ghost_repro
Jul 10, 2026
Merged

ashvardanian merged 1 commit into
unum-cloud:main-devfrom
desertfury:feat/ghost_repro

Conversation

@desertfury

Copy link
Copy Markdown
Contributor

Problem

b779c47 (#753) bounded the saturated probe but left tombstones unreclaimed, turning the CPU-spin hang into silent ghost keys.

Fix

Track tombstones and rehash to reclaim them before saturation, so live keys stay findable under churn.

Tests

cpp/ghost_repro.cpp now asserts zero ghosts; previously it leaked 1616 at a tight reserve.

`remove` marks a slot deleted but leaves it populated, so probes walk past it. The
resize decision only counted live entries, and under `remove`+`add` churn the live
count stays flat, so the table never grew and never rehashed. Tombstones accumulated
until no empty slot remained; probes could then no longer terminate, `equal_range`
returned `end()` for a key that was still live, and `remove` took the empty-range
branch reporting nothing removed. The entry became a ghost: `contains` kept finding
it, `remove` silently no-oped, and `size()` drifted above the true live count.

Count tombstones toward the load factor so churn triggers a rehash, which reclaims
them in place when the live count does not warrant growth.

The copy constructor and copy assignment had the same defect from the other side.
They re-placed live entries at their original slot indices and dropped tombstones,
which silently breaks probe chains: an entry displaced past a tombstone becomes
unreachable once that slot reads empty. Both now share one `rehash_into` helper with
`try_reserve`, so entries are always re-probed from their hash into a zeroed table
and chains are rebuilt rather than reproduced. That is the only way entries move
between tables now.

`test_slot_lookup_churn` covers both paths and fails against the previous code.
@ashvardanian
ashvardanian changed the base branch from main to main-dev July 10, 2026 14:54
@ashvardanian
ashvardanian merged commit c6d634c into unum-cloud:main-dev Jul 10, 2026
@ashvardanian

Copy link
Copy Markdown
Member

Thank you, @desertfury! Sorry it took a bit of time. I'm finalising new NumKong/StringZilla/ForkUnion releases to feed into USearch v3 🤗

ashvardanian pushed a commit that referenced this pull request Jul 10, 2026
### Minor

- Add: Expose `stats()` in Rust SDK (#768) (3713af9)
- Add: Rust compact binding (#771) (749d03b)

### Patch

- Make: Modernize CI toolchains, pin cibuildwheel (017fad3)
- Fix: Reclaim `slot_lookup_` tombstones under churn (#769) (c6d634c)
- Fix: Mix integer key hashes with SplitMix64 (#773) (9fc3500)
- Make: Build JavaScript Windows x64 prebuilds (#774) (7240652)
- Make: Bundle NumKong runtime with C# native artifacts (9c0ed29)
titusz pushed a commit to iscc/usearch that referenced this pull request Aug 3, 2026
`remove` marks a slot deleted but leaves it populated, so probes walk past it. The
resize decision only counted live entries, and under `remove`+`add` churn the live
count stays flat, so the table never grew and never rehashed. Tombstones accumulated
until no empty slot remained; probes could then no longer terminate, `equal_range`
returned `end()` for a key that was still live, and `remove` took the empty-range
branch reporting nothing removed. The entry became a ghost: `contains` kept finding
it, `remove` silently no-oped, and `size()` drifted above the true live count.

Closes unum-cloud#753

Co-Authored-By: Misha Chichvarin <[email protected]>
Co-Authored-By: Ash Vardanian <[email protected]>
(cherry picked from commit c6d634c)
titusz added a commit to iscc/usearch that referenced this pull request Aug 3, 2026
…() fixes

Cherry-picks from upstream unum-cloud/usearch:
- Mix integer key hashes with SplitMix64 (unum-cloud#773)
- Bounded probe in equal_iterator_gt::operator++
- Preserve hash lookup capacity across thread reserves (unum-cloud#765)
- Keep vectors_lookup_ capacity after clear() (unum-cloud#759)
- Reclaim slot_lookup_ tombstones under churn (unum-cloud#769)

Fork fixes:
- Rebuild key lookups after compact(), preserve the nodes buffer
  capacity, and abort cleanly on progress cancellation (#9)
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