Optimize ASCII-safe string rendering#831
Open
He-Pin wants to merge 2 commits intodatabricks:masterfrom
Open
Conversation
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.
Summary
String#getBytes(srcBegin, srcEnd, dst, dstBegin)to copy low bytes directly into the renderer buffer without allocation.std.base64Decoderesults so decoded ASCII text can use the same renderer fast path.Motivation
The docs base64 benchmarks fold into long ASCII-safe strings, then spend visible time rendering those strings. This keeps the same ASCII-safe precondition but moves JVM/Native to a platform copy path that is friendlier to JIT and GC, and extends the same tagging to decoded base64 text when the decoded bytes are JSON-safe ASCII.
Benchmarks
Baseline is
upstream/masterat8b67cb1e.JMH, docs regression cases:
go_suite/base64.jsonnetgo_suite/base64Decode.jsonnetgo_suite/base64_byte_array.jsonnetNative CLI hyperfine against latest source-built jrsonnet master
5b43fa8(jrsonnet 0.5.0-pre98):go_suite/base64.jsonnetValidation
git diff --check./mill -i __.checkFormat./mill -i 'sjsonnet.jvm[3.3.7].test'./mill -i 'sjsonnet.js[3.3.7].test'./mill -i 'sjsonnet.native[3.3.7].test'./mill -i 'sjsonnet.jvm[2.12.21].compile' 'sjsonnet.jvm[2.13.18].compile' 'sjsonnet.native[2.13.18].compile' 'sjsonnet.js[2.13.18].compile'./mill -i 'sjsonnet.native[3.3.7].nativeLink'./mill -i bench.runRegressions bench/resources/go_suite/base64Decode.jsonnet bench/resources/go_suite/base64.jsonnet bench/resources/go_suite/base64_byte_array.jsonnethyperfine --warmup 10 --min-runs 50String#getBytes(int, int, byte[], int)method used here.References
ba10f26a71bacd88ce0a476f9157a3f56c0f3c1d5b43fa88b8c43856dd5a2daa9c5c251153c5e14d