perf: fast-path strict json imports#840
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
Conversation
Motivation: Kube-prometheus imports large strict JSON files; parsing them through the full Jsonnet parser creates avoidable AST and materialization work. Modification: Add a strict .json import fast path shared by CachedResolver and Preloader, trim visitor work, build race-free inline-array objects for imported JSON, and reuse the no-offset position for imported literals. Result: Strict JSON imports keep Jsonnet fallback semantics for non-strict inputs while reducing parse and manifestation overhead for large imported JSON data.
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:
Real-world workloads such as kube-prometheus import large strict JSON files. Parsing those files through the full Jsonnet parser creates avoidable parser, AST, and manifestation work.
Key Design Decision:
The fast path only accepts strict
.jsoninput and falls back to normal Jsonnet parsing for malformed JSON, duplicate keys, non-finite numbers, parser-depth overflow, and defensive numeric parse failures. Imported JSON objects use a race-free inline-arrayVal.Objlayout: field caching is disabled for parse-cache-shared literals, and single-field objects avoid lazyvalue0mutation. JSON value positions reusefileScope.noOffsetPosbecause strict JSON imports do not execute code and per-element positions are not consumed for stack traces.Modification:
Add a shared strict JSON import visitor in
CachedResolver, wire it intoPreloader, trim duplicate-key/string visitor work, use inline object layout for imported JSON objects, and add shared-cache/concurrency regression tests.Benchmark Results:
entry-kube-prometheus.jsonnet -J vendor)223.351 +/- 12.742 ms139.041 +/- 2.847 ms-37.75%~235 msstarting stack135.9 +/- 1.2 ms~ -42%cumulative88.087 +/- 1.737 ms, remaining gap1.54x.manifestJsonEx 0.053,realistic2 39.485,large_string_template 1.102,gen_big_object 0.801Analysis:
The PR keeps Jsonnet compatibility by treating the JSON parser as an optional strict fast path, not a replacement parser. The added JVM-only concurrency tests exercise shared parse-cache reuse; cross-platform JSON import tests cover the platform-neutral behavior.
References:
Source exploration commits: He-Pin/sjsonnet
995b0822,114bd69f,52e22696,ca6f24d5.Result:
Local
./mill --no-server -j 1 __.reformatand./mill --no-server -j 1 __.testpassed on this split branch (2066/2066).