Repository navigation
Optimize OrderedDict performance - #167
oscardssmith wants to merge 6 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Also fix dict_sorting.jl OrderedDict/OrderedSet sort! to operate on the live 1:len prefix (Memory buffers have an undef tail). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Empty dicts alias a shared read-only 1-slot table so ht_keyindex needs no emptiness guard; ht_keyindex2 likewise drops its branch (the update/lookup path), with the grow handled in _setindex! (insert-only). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ht_keyindex returns a validated position, so the value-return access needs no bounds check. Removes the bounds check that made Memory-backed reads ~18% slower than Vector, and speeds up the hit path overall. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The @inbounds fix addressed the real getindex regression (a value-read bounds check), so the empty-table sentinel is unnecessary: a predicted sz==0 branch is effectively free on read and update paths. Simpler: length-0 empty slots, no shared mutable global, no slot recompute in _setindex!. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the 3-condition heuristic (mixing nk/cnt/sz with a chained >4 and a redundant nk>=sz) with two clear terms: 3*nk > 2*sz (occupancy/capacity; uses len/nk so it bounds slot occupancy, not just live count) and 4*ndel >= 3*nk (tombstone reclamation). nk>=sz is subsumed by the load term. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| ptrs = !isbitstype(K) && !isbitsunion(K) | ||
| # Mark live positions by walking the old slot table, then compact in | ||
| # ascending position order so insertion order is preserved. | ||
| live = falses(oldlen) |
There was a problem hiding this comment.
Allocating this here doesn't look great. Ref #169 for a probably better solution.
There was a problem hiding this comment.
seems reasonable. Will rebase once that merges.
|
According to the robot this has bugs so should not be merged.
Existing |
By moving the storage from
VectortoMemory(on 1.11+) we can save a couple pointer indirections (and a little bit of struct size). We also speed upht_keyindexby splitting thedirectparameter into 2 separate functions which removes theif/elsefrom the probing loop. We also remove themaxprobeparameter which just seems worse for performance. The benchmarks show that this version is consistently faster for insertions, and slightly faster for lookup of existing keys.Coauthored by claude (but carefully reviewed)