Skip to content

perf: reuse manifest json visitors#839

Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/reuse-manifest-json-visitors
Open

perf: reuse manifest json visitors#839
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/reuse-manifest-json-visitors

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin commented May 11, 2026

Motivation:
Reduce allocation pressure in std.manifestJson* paths that repeatedly materialize nested arrays and objects.

Key Design Decision:
The reused visitors are stateless with respect to the current container; container state remains in the renderer/materializer traversal, so reuse does not leak values between nested containers.

Modification:
MaterializeJsonRenderer reuses shared array and object visitors instead of allocating a new visitor instance per container.

Benchmark Results:

Benchmark master PR #839 Delta Notes
Scala Native hyperfine bench/resources/go_suite/manifestJsonEx.jsonnet 5.452 +/- 0.670 ms 5.330 +/- 0.590 ms -2.24% Output matched master.
Scala Native hyperfine kube-prometheus exploration 235.971 +/- 12.925 ms 224.975 +/- 11.550 ms -4.66% Stacked exploration result; source-built jrsonnet same run: 88.576 +/- 0.915 ms.
Focused JMH guards manifestJsonEx 0.052 ms/op, realistic2 40.068 ms/op, large_string_template 1.137 ms/op stable No guard regression observed in exploration.

Analysis:
This targets allocation overhead in manifestation without changing rendered JSON semantics.

References:
Source exploration commit: He-Pin/sjsonnet aac92b03.

Result:
Local ./mill --no-server -j 1 __.reformat and ./mill --no-server -j 1 __.test passed on this split branch (2066/2066).

Motivation:
Reduce container visitor allocation in manifestJsonEx-heavy workloads.

Modification:
Reuse stateless MaterializeJsonRenderer array and object visitors instead of allocating a new visitor for each container.

Result:
JSON manifestation keeps the same output while reducing allocation pressure in nested arrays and objects.
@He-Pin He-Pin marked this pull request as ready for review May 11, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant