Skip to content

perf(json): SizeVisitor + IsArrayVisitor → direct tag checks (-416 B LPC845; #3235 Tier 2E) - #3241

Merged
zackees merged 1 commit into
masterfrom
feat/json-visit-dispatch-phase1-3235-tier2e
Jun 18, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/json-visit-dispatch-phase1-3235-tier2e

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Closes #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.

Numbers (LPC845 / AutoResearch)

Before: 47,544 B flash
After: 47,128 B flash (-416 B, RAM unchanged)

Predicted ~250 B; actual -416 B (downstream DCE from removing the visitor anchors gives extra savings).

Phase 2 of Tier 2E (the json_convert_to_<int/bool/float/string>_core helpers that collapse the heavier conversion visitors) deferred to a follow-on once a sketch big enough to exercise the conversion-path leverage lands.

Refs #3235 (Tier 2E)

Summary by CodeRabbit

  • Refactor
    • Optimized internal JSON type handling implementation for improved performance and code efficiency without affecting public functionality.

…ks (#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)
@zackees
zackees merged commit e1c0908 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: 90ce17f4-4888-4a0b-8487-b26e281930fb

📥 Commits

Reviewing files that changed from the base of the PR and between 9a2269b and f490bc9.

📒 Files selected for processing (1)
  • src/fl/stl/json/types.h

📝 Walkthrough

Walkthrough

In src/fl/stl/json/types.h, json_value::is_array() and json_value::size() are rewritten to use direct data.is<T>() and data.ptr<T>() tag checks against json_array, json_object, and the packed vector alternatives (fl::vector<i16>, fl::vector<u8>, fl::vector<float>), removing the SizeVisitor and IsArrayVisitor structs entirely.

Changes

JSON Visitor Struct Removal

Layer / File(s) Summary
Replace SizeVisitor/IsArrayVisitor with direct tag checks
src/fl/stl/json/types.h
Removes SizeVisitor and IsArrayVisitor structs; is_array() now uses data.is<T>() and size() uses data.ptr<T>() for json_array, json_object, and packed vector types, returning 0 for non-matching alternatives.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

🐇 Hop, hop — the visitors are gone!
No thunks to summon, no structs to spawn.
A tag check here, a pointer peek there,
The array is found with nary a care.
Less flash to flash, more room to play! ✨

✨ 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/json-visit-dispatch-phase1-3235-tier2e

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.

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