Skip to content

[smile] Optimize async short ASCII string decoding - #767

Open
Dongnyoung wants to merge 1 commit into
FasterXML:3.xfrom
Dongnyoung:async-smile-short-ascii-string
Open

[smile] Optimize async short ASCII string decoding#767
Dongnyoung wants to merge 1 commit into
FasterXML:3.xfrom
Dongnyoung:async-smile-short-ascii-string

Conversation

@Dongnyoung

Copy link
Copy Markdown

Summary

This PR optimizes contiguous short-ASCII VALUE_STRING decoding in the Smile async parser.

NonBlockingByteArrayParser previously decoded these values by copying bytes into TextBuffer's char buffer and then materializing a String. When the complete short ASCII value is already available in the input buffer, this PR constructs the String directly from the input bytes using StandardCharsets.US_ASCII and resets the TextBuffer with that string.

This mirrors the approach already used by the synchronous Smile parser for the equivalent contiguous short-ASCII path.

Changes

  • Use direct byte[] to String decoding for contiguous short ASCII values in NonBlockingByteArrayParser
  • Preserve TextBuffer state with resetWithString(str)
  • Add async parser coverage for short ASCII string accessors with contiguous input

Benchmark

The benchmark exercises the actual async NonBlockingByteArrayParser path on JDK 21.0.7 using JMH 1.37.

Setup:

  • 5 forks
  • 5 × 1 s warmup
  • 8 × 1 s measurement
  • 4096 unique ASCII values per invocation
  • Complete Smile input supplied in one ByteArrayFeeder.feedInput() call
  • CHECK_SHARED_STRING_VALUES disabled
  • Lengths: 8, 32, and 64 (SmileConstants.MAX_SHORT_VALUE_STRING_BYTES)
  • GC profiler enabled

JsonParser.getString()

Length Base ns/value Candidate ns/value Reduction Base B/op Candidate B/op
8 13.661 ± 0.326 12.854 ± 0.278 5.9% 48.156 48.156
32 17.785 ± 0.580 12.630 ± 0.211 29.0% 72.156 72.156
64 23.674 ± 0.411 13.845 ± 0.374 41.5% 104.156 104.156

JsonParser.getStringCharacters()

Length Base ns/value Candidate ns/value Reduction Base B/op Candidate B/op
8 16.890 ± 0.727 14.379 ± 0.153 14.9% 80.156 80.156
32 21.764 ± 0.574 16.010 ± 0.136 26.4% 152.156 152.156
64 29.892 ± 1.058 19.436 ± 0.134 35.0% 248.156 248.156

Normalized allocation was effectively unchanged. The measured improvement therefore appears to come primarily from avoiding the intermediate byte-to-char decoding/copying step rather than from reducing allocation.

Testing

./mvnw -pl smile -Dtest=SimpleStringArrayTest -Dsurefire.useModulePath=false test

@Dongnyoung Dongnyoung changed the title Optimize async short ASCII string decoding [smile] Optimize async short ASCII string decoding Aug 30, 2026
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