You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Materializer walks the Val tree and feeds a ujson visitor (which builds a ujson.Value or streams to a writer depending on the renderer).
Output is collected into a StringWriter, then .toString copies the buffer into a new String, then Val.Str wraps it.
Each visitor call is a virtual dispatch. For the nested test object this is ~40–50 visits + indent logic.
jrsonnet appears to render directly from its Val to a String/IStr in a single pass, without an intermediate visitor AST.
Directions
Specialize ManifestJsonEx to walk the Val tree directly and emit to a single CharBuilder / StringBuilder — skipping the Materializer + ujson indirection entirely. The main tradeoff is code duplication with the renderer — could be mitigated by sharing escape/number utilities.
Since kube-prometheus (real-world) ends up materializing large JSON, this gap likely contributes to the ~2.8× real-world gap identified in performance optimization #666. High-impact.
Part of the jrsonnet-parity effort tracked in #666.
Tracking issue for a specific perf gap found while comparing sjsonnet (native, master) against jrsonnet (master). Parent comparison: #666.
Observation
std.manifestJsonExis 1.74× slower than jrsonnet.Scenario:
bench/resources/go_suite/manifestJsonEx.jsonnet.Repro:
Code
sjsonnet/src/sjsonnet/stdlib/ManifestModule.scala:76-105—ManifestJsonEx. CallsMaterializer.apply0(v, MaterializeJsonRenderer(...))(ev).toString.Hypothesis
Two-stage rendering:
Materializerwalks theValtree and feeds aujsonvisitor (which builds aujson.Valueor streams to a writer depending on the renderer).StringWriter, then.toStringcopies the buffer into a newString, thenVal.Strwraps it.Each visitor call is a virtual dispatch. For the nested test object this is ~40–50 visits + indent logic.
jrsonnet appears to render directly from its
Valto aString/IStrin a single pass, without an intermediate visitor AST.Directions
ManifestJsonExto walk theValtree directly and emit to a singleCharBuilder/StringBuilder— skipping theMaterializer+ujsonindirection entirely. The main tradeoff is code duplication with the renderer — could be mitigated by sharing escape/number utilities.Part of the jrsonnet-parity effort tracked in #666.