perf: use ISO_8859_1 for ASCII fast path in ClassFile.utf()#66
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit intomainfrom Apr 9, 2026
Merged
Conversation
On Java 9+, new String(byte[], offset, length, ISO_8859_1) allows the JVM to adopt the byte array directly as the compact string encoding, avoiding the byte-by-byte validation step that US_ASCII requires. Since class-file UTF8 entries are almost always pure ASCII, and the code already confirms this with a scan before reaching the fast path, using ISO_8859_1 is safe and equivalent — both charsets produce identical results for bytes 0x00–0x7F. Benchmark results (class-match module, spring-web.jar dataset): Baseline: ClassFileBenchmark.testClassHeader avgt 5 782.666 ± 30.761 us/op ClassFileBenchmark.testClassOutline avgt 5 1989.423 ± 34.237 us/op After: ClassFileBenchmark.testClassHeader avgt 5 764.186 ± 97.926 us/op ClassFileBenchmark.testClassOutline avgt 5 1879.470 ± 40.856 us/op ~2.4% header improvement, ~5.5% outline improvement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Use
ISO_8859_1instead ofUS_ASCIIfor the ASCII fast path inClassFile.utf()to improve string decoding performance.new String(byte[], offset, length, ISO_8859_1)is faster thanUS_ASCIIon all Java versions:Since the code already confirms all bytes are ASCII before reaching this fast path, using
ISO_8859_1is safe and produces identical results for bytes 0x00–0x7F.Motivation
Benchmarking
ClassFile.header()andClassFile.outline()against spring-web.jar (~700 classes) showed measurable improvement:testClassHeadertestClassOutlineThe outline improvement is larger because
utf()is called for every method name, field name, and descriptor — not just class/super/interface names.ASM baselines (unchanged code) confirmed system conditions were comparable across runs.
Additional Notes
utf()fast path is changed (1 line)Contributor Checklist
Jira ticket: N/A — performance optimization, no ticket
🤖 Generated with Claude Code