perf: reuse manifest json visitors#839
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
MaterializeJsonRendererreuses shared array and object visitors instead of allocating a new visitor instance per container.Benchmark Results:
bench/resources/go_suite/manifestJsonEx.jsonnet5.452 +/- 0.670 ms5.330 +/- 0.590 ms-2.24%235.971 +/- 12.925 ms224.975 +/- 11.550 ms-4.66%88.576 +/- 0.915 ms.manifestJsonEx 0.052 ms/op,realistic2 40.068 ms/op,large_string_template 1.137 ms/opAnalysis:
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 __.reformatand./mill --no-server -j 1 __.testpassed on this split branch (2066/2066).