-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid char array allocation in Starlark format
#23763
base: master
Are you sure you want to change the base?
Conversation
@tetromino Friendly ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on some internal testing on bazel query $VERY_LARGE_TARGET
, this delivers a measurable CPU time savings, but does not translate into a statistically significant effect on overall wall time.
My only concern is in bench_string.star
- you were running "".format(...)
, so the measurements you showed are probably not representative.
src/test/java/net/starlark/java/eval/testdata/bench_string.star
Outdated
Show resolved
Hide resolved
Thanks, I fixed and reran the benchmark. It now shows that the new implementation is only better with the Latin-1 string encoding, but worse in UTF-8 standalone Starlark. Not sure whether that makes it a good idea. |
Interesting. In that case, we may want different behavior depending on whether the string is Latin1... |
You will probably be interested in #24417 :-) |
Positional access via `String#charAt` is slightly faster than precreating the char array for Latin-1 strings and much faster for UTF-8 strings. It allocates less in both cases. Also adds a `--latin1` flag to the `Benchmarks` tool that allows benchmarking against Bazel's way of parsing Starlark files. Before: ``` INFO: Running command line: bazel-bin/src/test/java/net/starlark/java/eval/Benchmarks --filter bench_format --seconds 20 File src/test/java/net/starlark/java/eval/testdata/bench_string.star: benchmark ops cpu/op wall/op steps/op alloc/op bench_format 134217727 169ns 168ns 7 495B INFO: Running command line: bazel-bin/src/test/java/net/starlark/java/eval/Benchmarks --filter bench_format --seconds 20 --latin1 File src/test/java/net/starlark/java/eval/testdata/bench_string.star: benchmark ops cpu/op wall/op steps/op alloc/op bench_format 268435455 122ns 121ns 7 495B ``` After: ``` INFO: Running command line: bazel-bin/src/test/java/net/starlark/java/eval/Benchmarks --filter bench_format --seconds 20 File src/test/java/net/starlark/java/eval/testdata/bench_string.star: benchmark ops cpu/op wall/op steps/op alloc/op bench_format 268435455 110ns 109ns 7 479B INFO: Running command line: bazel-bin/src/test/java/net/starlark/java/eval/Benchmarks --filter bench_format --seconds 20 --latin1 File src/test/java/net/starlark/java/eval/testdata/bench_string.star: benchmark ops cpu/op wall/op steps/op alloc/op bench_format 268435455 113ns 112ns 7 479B ```
Positional access via
String#charAt
is slightly faster than precreating the char array for Latin-1 strings and much faster for UTF-8 strings. It allocates less in both cases.Also adds a
--latin1
flag to theBenchmarks
tool that allows benchmarking against Bazel's way of parsing Starlark files.Before:
After: