Skip to content

perf: speed up constant string joins#825

Open
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/constant-array-join
Open

perf: speed up constant string joins#825
He-Pin wants to merge 1 commit intodatabricks:masterfrom
He-Pin:perf/constant-array-join

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

@He-Pin He-Pin commented May 7, 2026

Summary

  • Keep large constant std.makeArray(... literal) arrays as an O(1) constant array view.
  • Fast-path std.join over constant/repeated string arrays with exact StringBuilder sizing.
  • Mark ASCII JSON-safe joined/repeated strings so byte rendering can skip escape scanning and UTF-8 encoding.
  • Add JVM/Native UTF-16-lane SWAR ascii-safe checks; Scala.js keeps a scalar fallback.
  • Drop remaining private[this] in touched Scala sources.

Benchmarks

Baseline: upstream/master (04e5707c). This PR: 7dd77cb7.

Full JMH sweep was run on both sides with ./mill -i bench.runRegressions. Only the standout result is listed here.

Benchmark upstream/master This PR Delta
bench/resources/cpp_suite/large_string_join.jsonnet 0.542 ms/op 0.268 ms/op -50.6%

GC profiler for the same benchmark:

Metric upstream/master This PR Delta
gc.alloc.rate.norm 1,531,405 B/op 633,079 B/op -58.7%

Scala Native hyperfine (--shell=none --warmup 5 --runs 50, output via -o /dev/null):

Command Mean
sjsonnet native, upstream/master 5.0 ms
sjsonnet native, this PR 4.0 ms
jrsonnet 3.4 ms

This narrows the large_string_join Scala Native gap to jrsonnet from ~1.45x slower to ~1.15x slower.

Validation

  • ./mill -i __.checkFormat
  • git diff --check
  • ./mill -i 'sjsonnet.jvm[3.3.7].test'
  • ./mill -i 'sjsonnet.js[3.3.7].test'
  • ./mill -i 'sjsonnet.js[3.3.7].compile' 'sjsonnet.native[3.3.7].compile'
  • ./mill -i 'sjsonnet.native[3.3.7].nativeLink'

@He-Pin He-Pin marked this pull request as draft May 7, 2026 19:20
@He-Pin He-Pin marked this pull request as ready for review May 7, 2026 19:53
@He-Pin He-Pin force-pushed the perf/constant-array-join branch from 7dd77cb to 9e7c7f1 Compare May 7, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant