Use Java 17 string and hex fast paths#810
Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
Open
Conversation
Collaborator
|
rebase |
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
This PR uses the Java 17 baseline to move a few hot string/encoding paths onto JIT/GC-friendlier implementations while keeping Scala.js and Scala Native behavior covered by platform fallbacks.
String.repeatfor repeated string padding /std.repeatandHexFormatfor digest-to-hex.Platform.repeatStringfallbacks; Native also gets a manual digest-to-hex loop instead of per-byteString.format.StandardCharsets.UTF_8instead of charset names / default charset.std.splitLimitadvances withString.indexOf,std.resolvePathuseslastIndexOf, and CLI binding parsing avoids regexString.split.bench/resources/jdk17_suiteas supplemental targeted coverage.I intentionally did not use
Files.readString: its malformed-input behavior is not equivalent to the currentnew String(Files.readAllBytes(...), UTF_8)decode path. I also left stream/matcher helpers andString.strip/isBlank/lines/formattedout of scope because they either change Jsonnet semantics, add allocation-heavy pipelines, or do not map to the current hot paths.This is not claimed as a broad existing-suite speedup or as the theoretical limit of all Java 17 APIs. The existing JMH suite is mostly neutral/noisy; the measurable wins are concentrated in the string repeat/split/resolve/hash paths shown below.
JMH
Environment:
master(3a9a4928, Java 17 compile level)-wi 3 -i 5 -w 1s -r 2s -f 1 -jvmArgsAppend -Xss100m -prof gc-wi 3 -i 5 -w 1s -r 2s -f 1 -prof gcExisting JMH Suite
This run uses the 36 existing
bench/resources/{bug_suite,cpp_suite,go_suite,sjsonnet_suite}inputs and excludes the newjdk17_suitefiles.Top existing-suite timing movements:
bench/resources/cpp_suite/bench.07.jsonnetbench/resources/cpp_suite/bench.01.jsonnetbench/resources/go_suite/manifestYamlDoc.jsonnetbench/resources/go_suite/manifestTomlEx.jsonnetbench/resources/go_suite/lstripChars.jsonnetbench/resources/cpp_suite/realistic2.jsonnetbench/resources/cpp_suite/bench.02.jsonnetbench/resources/sjsonnet_suite/setInter.jsonnetbench/resources/cpp_suite/large_string_join.jsonnetbench/resources/go_suite/substr.jsonnetMost allocation-positive existing-suite movements:
bench/resources/cpp_suite/bench.09.jsonnetbench/resources/go_suite/escapeStringJson.jsonnetbench/resources/bug_suite/assertions.jsonnetbench/resources/go_suite/base64_stress.jsonnetbench/resources/go_suite/comparison.jsonnetInterpretation: allocation is effectively flat on the existing suite, with no >= +1% allocation regressions. Timing is mixed and slightly slower on geomean in this single run; the largest slower entries have essentially unchanged allocation, so I am treating the existing-suite result as neutral/noisy rather than a throughput win. I am therefore not claiming an existing-suite throughput improvement from this PR.
Full existing-suite table
bench/resources/bug_suite/assertions.jsonnetbench/resources/cpp_suite/bench.01.jsonnetbench/resources/cpp_suite/bench.02.jsonnetbench/resources/cpp_suite/bench.03.jsonnetbench/resources/cpp_suite/bench.04.jsonnetbench/resources/cpp_suite/bench.06.jsonnetbench/resources/cpp_suite/bench.07.jsonnetbench/resources/cpp_suite/bench.08.jsonnetbench/resources/cpp_suite/bench.09.jsonnetbench/resources/cpp_suite/gen_big_object.jsonnetbench/resources/cpp_suite/large_string_join.jsonnetbench/resources/cpp_suite/large_string_template.jsonnetbench/resources/cpp_suite/realistic1.jsonnetbench/resources/cpp_suite/realistic2.jsonnetbench/resources/go_suite/base64.jsonnetbench/resources/go_suite/base64Decode.jsonnetbench/resources/go_suite/base64DecodeBytes.jsonnetbench/resources/go_suite/base64_byte_array.jsonnetbench/resources/go_suite/base64_stress.jsonnetbench/resources/go_suite/comparison.jsonnetbench/resources/go_suite/comparison2.jsonnetbench/resources/go_suite/escapeStringJson.jsonnetbench/resources/go_suite/foldl.jsonnetbench/resources/go_suite/lstripChars.jsonnetbench/resources/go_suite/manifestJsonEx.jsonnetbench/resources/go_suite/manifestTomlEx.jsonnetbench/resources/go_suite/manifestYamlDoc.jsonnetbench/resources/go_suite/member.jsonnetbench/resources/go_suite/parseInt.jsonnetbench/resources/go_suite/reverse.jsonnetbench/resources/go_suite/rstripChars.jsonnetbench/resources/go_suite/stripChars.jsonnetbench/resources/go_suite/substr.jsonnetbench/resources/sjsonnet_suite/setDiff.jsonnetbench/resources/sjsonnet_suite/setInter.jsonnetbench/resources/sjsonnet_suite/setUnion.jsonnetCommand:
Supplemental Targeted JMH
These new inputs isolate the paths changed in this PR; they are supplemental and are not a replacement for the existing-suite comparison above.
bench/resources/jdk17_suite/hash.jsonnetbench/resources/jdk17_suite/repeat_format.jsonnetbench/resources/jdk17_suite/split_resolve.jsonnetTargeted geomean:
Command:
./mill --no-server bench.runJmh sjsonnet.bench.RegressionBenchmark.main \ -p path=bench/resources/jdk17_suite/hash.jsonnet,bench/resources/jdk17_suite/repeat_format.jsonnet,bench/resources/jdk17_suite/split_resolve.jsonnet \ -wi 3 -i 5 -w 1s -r 2s -f 1 \ -prof gc \ -rf json -rff /private/tmp/sjsonnet-jdk17-bench/{base,opt}-targeted2.jsonCorrectness / Tests
All passed locally.