Skip to content

perf: speed up TOML manifestation#828

Merged
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:perf/toml-render-fastpath
May 11, 2026
Merged

perf: speed up TOML manifestation#828
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:perf/toml-render-fastpath

Conversation

@He-Pin
Copy link
Copy Markdown
Contributor

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

Motivation:

std.manifestTomlEx spends avoidable time and allocation while rendering TOML: regex matching for bare keys, intermediate escaped strings, per-value renderer allocation, Seq path copies, partition, and repeated sorting during table traversal.

Key Design Decision

Keep this PR TOML-only. The earlier repeated-join work is now handled separately in #825, so this branch was intentionally reduced to a single focused TOML rendering commit after rebasing onto latest master.

Modification:

  • Write TOML strings and keys directly to the existing StringWriter.
  • Replace bare-key regex matching with a small ASCII scanner.
  • Avoid string concatenations and unnecessary StringWriter.flush() calls while rendering arrays.
  • Reuse a TomlRenderer per table level and keep table paths in a mutable buffer.
  • Use sorted visible keys plus section flags instead of partition plus extra sorting.
  • Add directional golden coverage for TOML key escaping, non-section ordering, nested tables, and table arrays.

Benchmark Results:

JMH on JDK 21, ./mill -j 1 bench.runRegressions bench/resources/go_suite/manifestTomlEx.jsonnet, lower ms/op is better; ops/ms = 1 / ms_per_op, higher is better.

Case master ms/op PR ms/op master ops/ms PR ops/ms Delta
go_suite/manifestTomlEx.jsonnet 0.067 0.053 14.93 18.87 +26.4% ops/ms

Scala Native hyperfine, lower is better, comparing locally built Scala Native binaries and source-built jrsonnet 0.5.0-pre98.

Case master PR jrsonnet Result
go_suite/manifestTomlEx.jsonnet 5.3 ± 1.3 ms 5.3 ± 1.3 ms 4.0 ± 1.1 ms startup/noise dominated; PR and master are neutral
scaled TOML manifestation loop 29.0 ± 1.6 ms 12.1 ± 1.0 ms 10.0 ± 0.9 ms PR is ~58.3% faster than master; still ~1.21x jrsonnet

Analysis:

The output remains compatible with current sjsonnet behavior: local master and this PR produced identical output on the benchmark inputs and the new directional TOML golden test. The scaled Native comparison includes jrsonnet as a performance reference, but jrsonnet's TOML formatting differs from sjsonnet on these inputs, so sjsonnet-vs-sjsonnet output equality is the semantic gate.

References:

Result:

  • ./mill --no-server -j 1 __.reformat passed locally.
  • ./mill --no-server -j 1 __.test passed locally.
  • PR comments were reviewed; there are no review threads. The maintainer rebase request is addressed by this force-pushed TOML-only branch.

@He-Pin He-Pin changed the title perf: reduce TOML manifestation allocations perf: reduce TOML and repeated join allocations May 8, 2026
@stephenamar-db
Copy link
Copy Markdown
Collaborator

rebase

@He-Pin He-Pin force-pushed the perf/toml-render-fastpath branch 3 times, most recently from cf705bd to 2b5b106 Compare May 10, 2026 04:38
Motivation:

std.manifestTomlEx allocates avoidable intermediate strings, regex matchers, sequence paths, and table partition/sort structures while rendering TOML.

Modification:

Render TOML strings and keys directly to the existing writer, replace bare-key regex matching with an ASCII scan, reuse renderer/path buffers during table traversal, and classify sections with cached sorted keys.

Result:

Keeps output-compatible TOML rendering and adds directional golden coverage for key escaping, non-section ordering, nested tables, and table arrays.

References:

PR: databricks#828
@He-Pin He-Pin force-pushed the perf/toml-render-fastpath branch from 2b5b106 to 3efa453 Compare May 10, 2026 08:09
@He-Pin He-Pin changed the title perf: reduce TOML and repeated join allocations perf: speed up TOML manifestation May 10, 2026
@He-Pin
Copy link
Copy Markdown
Contributor Author

He-Pin commented May 10, 2026

Rebased onto latest master and reduced this PR to TOML-only so it no longer duplicates #825's repeated-join work. I refreshed the local validation and benchmark data in the PR description.

@stephenamar-db stephenamar-db merged commit db71dbe into databricks:master May 11, 2026
5 checks passed
@He-Pin He-Pin deleted the perf/toml-render-fastpath branch May 11, 2026 06:43
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.

2 participants