Repository navigation
Description
Parent: #3244 (Phase 3 burn-down).
Goal
Phase 1 (#3241) replaced SizeVisitor + IsArrayVisitor with direct data.is<T>() / data.ptr<T>() tag checks, saving 416 B on LPC845.
This issue is Phase 2: collapse the conversion visitors (JsonToIntegerVisitor<T>, JsonToFloatVisitor<T>, JsonToBoolVisitor, JsonToStringVisitor) into 4 non-template json_convert_to_<X>_core(tag, storage, out) helpers. Each conversion visitor today emits 10 per-alternative operator() overloads × 1-2 templated T values = 20-30 instantiated bodies; the core approach collapses that to one dispatch per output type.
Reproduction (baseline)
bash bloat lpc845brk --example AutoResearch --top 15
# Look for JsonToIntegerVisitor / JsonToFloatVisitor / BoolConversionVisitor /
# StringConversionVisitor entries -- they total ~2-3 KB on the LPC845 build.
The conversion visitors are reached from json::as<T>() / json::try_as<T>() and from the RPC arg-conversion path (JsonArgConverter).
Acceptance
- PR introduces 4 non-template helpers under
fl/stl/json/dispatch.cpp.hpp:TypeConversionResult json_convert_to_integer_core(json_tag, const void* storage, i64* out)TypeConversionResult json_convert_to_bool_core(json_tag, const void* storage, bool* out)TypeConversionResult json_convert_to_float_core(json_tag, const void* storage, float* out)TypeConversionResult json_convert_to_string_core(json_tag, const void* storage, fl::string* out)
Each does a single switch over the 10 alternatives.
-
JsonToIntegerVisitor<T>/JsonToFloatVisitor<T>/JsonToBoolVisitor/JsonToStringVisitorbecome thin templated wrappers that call the core + apply per-T narrowing (e.g.static_cast<T>(i64_result)+ range check). -
json_valueexposes a publictag()+raw_storage()accessor so the cores can read the variant without going through visit(). - Existing host tests in
tests/test_json_*.cpppass unchanged. - Measured savings on LPC845-BRK / AutoResearch: ≥ 1.5 KB net flash drop (audit predicted ~2-3 KB; the higher figure assumed Large-memory targets where the float/double conversion machinery is also active).
Design reference
The JSON visitor codegen audit run during #3235 catalogued the quadratic (visitor × alternative) thunk explosion and the proposed dispatch-core shape. Summary in #3235's meta body; full sub-agent report available from this session's transcript.
Risk
json_value::visit(Visitor)is public API. External code (user sketches doingj.visit(my_visitor)) must keep working —variant::visitstays intact; the dispatch redesign is additive (a parallel non-template path used internally by the conversion + serializer entry points).default_value_visitor<T>uses SFINAE on integer/float conversion — leave it untouched in this PR.SerializerVisitorrecursion (serialize_value(json_value*)callingdata.visit(*this)) is the trickiest case; defer to a Phase 3 follow-on (file a new sub-issue if it's worth attacking).
Out of scope
default_value_visitor<T>— not worth touching for the savings.SerializerVisitorrecursive case — defer.- The
jsontoken tag enum surface change (if any) — should stay internal tofl/stl/json/.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(json): collapse JsonToType<T> visitor dispatch into non-template…