Repository navigation
perf(unordered_map): type-erase probing-sequence helper (-788 B LPC845; #3235 Tier 1C) - #3240
Conversation
Extracts the (cap <= 8 ? linear : quadratic-then-linear) probing index
computation from `unordered_map`'s `find_slot`, `find_index`, and
`find_unoccupied_index_using_bitset` into a single non-template
`fl::detail::unordered_map_probe_idx` helper under
`fl/stl/unordered_map_basic.h`.
The probe index sequence is purely a function of (hash, attempt_index,
cap) and has no dependency on K, V, Hash, or Equal. Per-instantiation
duplication of the inner probing logic shifts to one shared ~30 B body.
FL_NO_INLINE on the helper is load-bearing under LTO; runtime cost is
one indirect call per probe step, dwarfed by the bucket-state + bitset
work the caller is doing anyway.
## Verification (LPC845 / AutoResearch -- 2 distinct unordered_map types)
flash 48,332 B -> 47,544 B (-788 B saved)
RAM 9,984 B -> 9,984 B (unchanged)
The scope is intentionally narrow: only the index-computation logic is
shared. Bucket-state checks (which touch K via `_equal(bucket.key, key)`)
and the bitset reads remain in the templated body because they each
depend on per-instantiation state. Full type erasure of `find_slot` /
`find_index` would require a thicker context block; this narrow split
captures the pure-arithmetic piece that's a zero-leverage-threshold win.
Refs #3235 Tier 1C
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughIntroduces a new Changesunordered_map probe-sequence type-erasure
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ly (#3243) * perf(json): replace SizeVisitor + IsArrayVisitor with direct tag checks (#3235 Tier 2E Phase 1) Removes `SizeVisitor` and `IsArrayVisitor` -- two `data.visit(visitor)` patterns that each forced the variant to emit per-(T × Visitor) `visit_fn` thunks for all 10 `json_value::variant_t` alternatives (`nullptr_t`, `bool`, `i64`, `float`, `fl::string`, `json_array`, `json_object`, `vector<i16>`, `vector<u8>`, `vector<float>`). `json::is_array()` now inlines as 4 `data.is<T>()` tag checks; `json:: size()` inlines as 5 `data.ptr<T>()` tag-and-extract checks. Behavior preserved; the visitor structs themselves and their per-T thunk instantiations are gone. This is Phase 1 of the Tier 2E plan (validates the tag-table-lookup approach for visitors with simple result extraction). Phase 2 -- the `json_convert_to_<int/bool/float/string>_core` non-template helpers that collapse the heavier conversion visitors -- remains as a follow- on once the codebase has a sketch big enough to exercise the conversion path leverage. ## Verification (LPC845 / AutoResearch) flash 47,544 B -> 47,128 B (-416 B saved) RAM 9,984 B -> 9,984 B (unchanged) Predicted ~250 B; actual -416 B. The extra savings come from downstream DCE -- with no `visit_fn<T, SizeVisitor>` / `visit_fn<T, IsArrayVisitor>` references, the variant doesn't anchor the corresponding alternative-T copies into the thunk tables for those visitor types. Refs #3235 Tier 2E (Phase 1) * fix(unity-build): re-sort fl/stl/_build.cpp.hpp includes alphabetically PR #3240 (Tier 1C) added `unordered_map_basic.cpp.hpp` between `fstream` and `ieee754_string`, which the UnityBuildChecker flagged as out of alphabetical order ('u' > 'i'). Move it to its correct slot after `type_traits.cpp.hpp`. No behavior change.
Closes #3235 Tier 1C.
Lands fl::detail::unordered_map_probe_idx as a shared non-template helper for the open-addressed probing sequence. Per-instantiation duplication of the (cap<=8 linear vs quadratic-then-linear) branch logic across find_slot, find_index, and find_unoccupied_index_using_bitset collapses to one ~30 B body.
Numbers (LPC845 / AutoResearch, 2 distinct unordered_map types)
Before: 48,332 B flash
After: 47,544 B flash (-788 B, RAM unchanged at 9,984 B)
Scope
Narrow on purpose. Only the index-computation arithmetic is shared. Bucket-state inspection (touches K via _equal) and bitset reads remain in the templated body. Full type erasure of find_slot would need a thicker context block; this captures the pure-arithmetic piece that is a zero-leverage-threshold win.
Refs #3235 (Tier 1C)
Summary by CodeRabbit