Skip to content

perf(folsom): avoid copying ASCII response tokens - #247

Open
petedmarsh wants to merge 4 commits into
spotify:masterfrom
petedmarsh:perf/ascii-decoder-no-copy
Open

petedmarsh wants to merge 4 commits into
spotify:masterfrom
petedmarsh:perf/ascii-decoder-no-copy

Conversation

@petedmarsh

Copy link
Copy Markdown

Parse ASCII response tokens as offsets into the existing line buffer instead of copying each token into a second buffer. Add tests for multi-value, fragmented, UTF-8 stats, and scalar responses.

Benchmark

Decoder-only JMH 1.37 on JDK 25.0.1 with ActiveProcessorCount=32. Times are mean +/- JMH 99.9% error.

Response Clean baseline Optimized run 1 Optimized run 2 Allocation, before and after (Unchanged)
Single 64-byte hit 110.483 +/- 0.663 ns/op 74.805 +/- 0.567 ns/op 76.021 +/- 0.584 ns/op 400 B/op
16 hits 1370.720 +/- 20.757 ns/op 1329.864 +/- 7.220 ns/op 1344.472 +/- 34.787 ns/op 2440 B/op

petedmarsh and others added 4 commits September 23, 2026 11:37
Co-Authored-By: Codex <noreply@openai.com>
JMH 1.37, JDK 25.0.1, arm64 Docker Desktop (18 available CPUs), -XX:ActiveProcessorCount=32. One thread, two forks, 4x1s warmup and 5x1s measurement per fork; -prof gc. The benchmark reuses its decoder, ByteBuf and output list, measuring direct decode of 64-byte values without socket or scheduling costs.

Baseline (mean ns/op +/- JMH 99.9% error; allocated B/op): single hit 120.037 +/- 41.132, 400.001; batch of 16 hits 1386.719 +/- 31.427, 2440.010; miss 15.109 +/- 0.147, approximately zero. One noisy 197 ns single-hit iteration inflated that mean; the batch result is the more stable comparison.

Co-Authored-By: Codex <noreply@openai.com>
Parse tokens as offsets into the existing response-line buffer instead of copying each token into a second ByteBuffer. Keep key and value ownership unchanged. Decoder and adjacent ASCII request tests pass; formatting check passes.

Clean A/B JMH rerun (JDK 25.0.1, arm64 Docker, ActiveProcessorCount=32, 2 forks, 4x1s warmup, 5x1s measurement, gc profiler): single 64-byte hit 110.483 +/- 0.663 ns/op baseline versus 74.805 +/- 0.567 and 76.021 +/- 0.584 ns/op in two changed-code runs (about 31-32% lower). Batch of 16 hits 1370.720 +/- 20.757 ns/op baseline versus 1329.864 +/- 7.220 and 1344.472 +/- 34.787 ns/op (about 2-3% lower; small enough to be sensitive to run noise). Allocation is unchanged: 400 B/single hit and 2440 B/batch16. The benchmark isolates decode, not end-to-end client CPU.

Co-Authored-By: Codex <noreply@openai.com>
Keep the baseline and before/after JMH results in the preceding commit messages while leaving the production branch with only decoder tests and the measured optimization. Focused decoder and adjacent ASCII request tests and fmt:check pass after removal.

Co-Authored-By: Codex <noreply@openai.com>

@spkrka spkrka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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.

3 participants