perf: buffer json file output#870
Open
He-Pin wants to merge 1 commit into
Open
Conversation
Motivation: The Native stdout buffering win showed downstream buffering can materially reduce large-output write overhead. JSON outputFile rendering still wrote ByteRenderer chunks directly to the file output stream. Modification: Wrap the JSON outputFile ByteRenderer target in a BufferedOutputStream with a 256 KiB buffer. Keep YAML, expect-string, stdout, and renderer semantics unchanged. Result: Native kube-prometheus file-output A/B on the 0.5.12 stack improved in both orders: forward median 196.625 ms clean vs 183.491 ms candidate; reverse median 175.878 ms candidate vs 193.394 ms clean. Output matched by cmp; reformat, full tests, and bench regressions passed.
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:
The Native stdout buffering follow-up showed that downstream buffering can materially reduce large-output write overhead. JSON
-ooutput still sentByteRendererchunks directly to the file output stream, relying only onByteBuilder's internal flush threshold.Key Design Decision:
Keep the change local to the JSON output-file fast path. Rather than changing
ByteBuilderthresholds globally, wrap the file output stream in aBufferedOutputStreamwith the same 256 KiB output buffer size used for the Native stdout buffering follow-up. YAML, expect-string, stdout, and renderer semantics stay unchanged.Modification:
OutputBufferSize = 256 * 1024inSjsonnetMainBase.ByteRenderertargets inBufferedOutputStream(out, OutputBufferSize).Benchmark Results:
Workload:
jrsonnet/tests/realworld/entry-kube-prometheus.jsonnet -J vendor -o /tmp/fileout-*.jsonCandidate was benchmarked on the Scala Native 0.5.12 stacked exploration branch after the Native stdout buffering commit.
Output equality matched by
cmp.Validation:
./mill --no-server --ticker false --color false __.reformat./mill --no-server --ticker false --color false -j 1 __.test— 444 passed, 0 failed./mill --no-server --ticker false --color false bench.runRegressionsAnalysis:
This preserves the existing rendering pipeline and only changes the buffering layer for file output. It avoids global
ByteBuilderthreshold changes, keeps stdout behavior separate, and does not affect YAML or expect-string paths.References:
Result:
Large JSON file output writes are buffered more effectively while preserving byte-identical output and the existing flush/close contract.