Skip to content

Port hot-path optimizations from #102 - #129

Merged
uw4 merged 1 commit into
mainfrom
perf-hotspots-102
Nov 5, 2026
Merged

uw4 merged 1 commit into
mainfrom
perf-hotspots-102

Conversation

@aeberhart

Copy link
Copy Markdown
Contributor

Takes the two hot-path changes from #102 (thanks @sergeevik) and leaves the rest, to keep the code close to jsonata-js.

  • Tokenizer: the number regex is compiled once instead of on every token. This matches the regex literal in jsonata-js.
  • Signature.validate: loops over match.toCharArray() instead of match.split(""), which compiled a regex on every function call. The supplied signature is built with a StringBuilder.
  • HotspotTest: correctness tests for both paths, plus timing loops that warm up first. Use -Dhotspot.iterations=N for longer runs.

Timings at 500k iterations with warmup (JDK 25), two runs each:

before after
Tokenizer (50k parses) 5995 / 5790 ms 2463 / 2613 ms
Signature (500k calls) 734 / 705 ms 748 / 776 ms

The Signature change doesn't show up in end-to-end timings. On its own, split("") takes about 150 ns per call and toCharArray() about 4 ns. The change is kept to reduce allocations.

The full test suite passes (1743 tests).

🤖 Generated with Claude Code

- Tokenizer: compile the number regex once instead of per token
  (matches the regex literal in jsonata-js); ~2.3x faster parsing of
  number-heavy expressions after warmup
- Signature.validate: iterate chars instead of split(""), which compiled
  a regex on every function call; build supplied signature with a
  StringBuilder
- HotspotTest: correctness tests and timing loops for both paths
  (-Dhotspot.iterations=N for longer runs)

Co-authored-by: Sergeev Viktor <sergeevViktor017@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aeberhart
aeberhart requested a review from uw4 November 4, 2026 11:55
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Test Results

1 813 tests  +7   1 811 ✅ +7   8s ⏱️ +2s
  123 suites +1       2 💤 ±0 
  123 files   +1       0 ❌ ±0 

Results for commit c8609a0. ± Comparison against base commit 6850f8d.

@uw4
uw4 merged commit f84d2a8 into main Nov 5, 2026
2 checks passed
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