perf: speed up simple integer parsing#830
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
Conversation
Motivation: The jrsonnet docs std.base64 byte-array benchmark is dominated by parsing a large literal array of small integer byte values. Parser.number currently sends every numeric literal through String.toDouble, which is unnecessary for plain unsigned integer literals. Modification: Add a tight parser fast path for simple unsigned integer literals up to 18 digits. Literals with underscores, decimal points, exponents, or larger digit counts keep the existing validation and String.toDouble path. Result: bench/resources/go_suite/base64_byte_array.jsonnet: upstream/master 0.801 ms/op, this change 0.719 ms/op (-10.2%). Verification: ./mill -i 'sjsonnet.jvm[3.3.7].test' ./mill -i 'sjsonnet.jvm[3.3.7].reformat' ./mill -i __.checkFormat git diff --check ./mill -i bench.runRegressions bench/resources/go_suite/base64_byte_array.jsonnet ./mill --no-server 'sjsonnet.native[3.3.7]'.nativeLink
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 jrsonnet docs
std.base64 (byte array)benchmark is a large literal array of small integer byte values. In sjsonnet that path spends meaningful time in the parser, andParser.numbercurrently routes every numeric literal throughString.toDouble.Plain unsigned integer literals do not need the full decimal/exponent parser.
Modification
The implementation is allocation-free beyond the existing parsed token string and uses a tight
Longaccumulation loop, so it is GC- and JIT-friendly.Result
JMH, same machine/JDK, docs-aligned case:
bench/resources/go_suite/base64_byte_array.jsonnet0.801 ms/op0.719 ms/op-10.2%Native hyperfine was attempted but not reported: the local machine was under heavy system load and produced unusable outlier-heavy data (
55.8 ± 51.0 msfor sjsonnet on this same docs case). I am intentionally excluding that result rather than making a noisy claim.Verification
./mill -i 'sjsonnet.jvm[3.3.7].test'./mill -i 'sjsonnet.jvm[3.3.7].reformat'./mill -i __.checkFormatgit diff --check./mill -i bench.runRegressions bench/resources/go_suite/base64_byte_array.jsonnet./mill --no-server 'sjsonnet.native[3.3.7]'.nativeLinkBoundary Checks
std.base64encoding itself.String.toDoublepath.String.toDoublepath to avoid changing large-number rounding behavior.