HashTable: grow DJB string-key index + hash-first writes (#36408) - #36420
Merged
Conversation
The 8-bucket hash index never resized, so isset/insert on large associative arrays devolved to O(n) chains (~n² probes). Double buckets at load factor ≥1 and route all setStringKey* paths through hash lookup instead of list walks. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Sep 2, 2026
Closed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensureStrHashIndexnow doubles the DJB bucket table at load factor ≥1 and rehashes all nodes (was fixed 8 buckets forever → O(n) chains on large arrays).setStringKey*write paths use hash-index lookup vialookupStringKeyForWriteBranchinstead of walking the insertion-order linked list (insert was O(n²) for fresh keys).Closes #36408
Root cause
#36191 added an 8-bucket hash index used on read, but never grew it and still walked the linked list on every insert/update. At 20k keys: isset probe ~2.4s AOT vs 0.037s Zend; at 100k: timeout.
Verify
Not covered
script/differential-sweep.sh --aot --repeat 3(started but CI lock contention; tier-0 VM differential green via dev-verify-fast).foreachorder / ksort differential cases from issue Done-when (no regressions expected; hash index does not reorder strKeys list).Made with Cursor