Skip to content

perf(unordered_map): type-erase probing-sequence helper (-788 B LPC845; #3235 Tier 1C) - #3240

Merged
zackees merged 1 commit into
masterfrom
feat/unordered-map-basic-3235-tier1c
Jun 18, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/unordered-map-basic-3235-tier1c

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

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

  • Refactor
    • Consolidated internal unordered_map probing sequence logic into a shared helper for improved code maintainability.

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
@zackees
zackees merged commit 9a2269b into master Jun 18, 2026
10 checks passed
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c4fee8ea-bf31-4dab-ae57-96c31bf0a3d9

📥 Commits

Reviewing files that changed from the base of the PR and between be2fbd5 and 92d9684.

📒 Files selected for processing (4)
  • src/fl/stl/_build.cpp.hpp
  • src/fl/stl/unordered_map.h
  • src/fl/stl/unordered_map_basic.cpp.hpp
  • src/fl/stl/unordered_map_basic.h

📝 Walkthrough

Walkthrough

Introduces a new unordered_map_basic module (unordered_map_basic.h + unordered_map_basic.cpp.hpp) that centralizes probe-sequence computation in a single FL_NO_INLINE non-template function fl::detail::unordered_map_probe_idx. The existing unordered_map.h template methods find_slot and find_unoccupied_index_using_bitset are updated to delegate to this helper, and the new implementation unit is registered in the unity build header.

Changes

unordered_map probe-sequence type-erasure

Layer / File(s) Summary
New unordered_map_basic probe helper (header + impl)
src/fl/stl/unordered_map_basic.h, src/fl/stl/unordered_map_basic.cpp.hpp
Declares and implements fl::detail::unordered_map_probe_idx(h, i, mask, cap) as FL_NO_INLINE FL_NOEXCEPT. Defines kUnorderedMapLinearProbeOnlyThreshold = 8 and kUnorderedMapQuadraticProbingTries = 8 constants. Implementation branches on cap and i to select linear, quadratic, or linear-fallback probing and masks the result.
unordered_map.h refactored to use helper + unity build wiring
src/fl/stl/unordered_map.h, src/fl/stl/_build.cpp.hpp
Adds #include "fl/stl/unordered_map_basic.h". Replaces ~68 lines of inline probe logic in find_slot and find_unoccupied_index_using_bitset with detail::unordered_map_probe_idx(...) calls. Updates member enum values kLinearProbingOnlySize and kQuadraticProbingTries to source from detail constants. Registers unordered_map_basic.cpp.hpp in the unity build header.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hops through the hash table, probing with care,
One shared little function now lives everywhere.
No more inline clones bloating the flash,
A single FL_NO_INLINE handles the dash!
Quadratic or linear — the helper decides,
And the rabbit saves bytes on each embedded ride. ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/unordered-map-basic-3235-tier1c

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

zackees added a commit that referenced this pull request Jun 18, 2026
…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.
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 18, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 18, 2026
@zackees
zackees deleted the feat/unordered-map-basic-3235-tier1c branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

META: type-erasure burn-down -- collapse template-instantiation taxes across containers / RPC / visitors / fl::function / chipset controllers

1 participant