Skip to content

Use varhandle for array access in CBORGenerator - #752

Open
pjfanning wants to merge 8 commits into
FasterXML:3.xfrom
pjfanning:varhandle
Open

Use varhandle for array access in CBORGenerator#752
pjfanning wants to merge 8 commits into
FasterXML:3.xfrom
pjfanning:varhandle

Conversation

@pjfanning

Copy link
Copy Markdown
Member

The VarHandle path is a single store instruction on most JVMs, versus 8 separate shift-cast-store operations. The same utility could be shared with the Smile module if desired.

Fallback to existing code if var handles are not supported, eg Android.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

🧪 Code Coverage Report

Coverage Type Coverage Change
📝 Instructions 76.37% 📉 -0.73%
🔀 Branches 68.27% 📉 -0.03%

Added comments explaining the choice of float representation in _writeFloatNoCheck method.
Removed commented-out code regarding float handling.
@cowtowncoder cowtowncoder changed the title use varhandle for array access Use varhandle for array access Aug 14, 2026
@cowtowncoder

Copy link
Copy Markdown
Member

@pjfanning Any chance for brief jmh perf verification?

@cowtowncoder cowtowncoder changed the title Use varhandle for array access Use varhandle for array access in CBORGenerator Aug 14, 2026
@pjfanning

pjfanning commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

@cowtowncoder I added a benchmark to https://github.com/pjfanning/double-reader-writer

Got these results on my laptop (Java 25)

Benchmark                                             Mode  Cnt     Score     Error   Units
CBORGeneratorBenchmark.cborBaselineWriteDoubleArray  thrpt    3   870.669 ± 247.838  ops/ms
CBORGeneratorBenchmark.pr752CborWriteDoubleArray     thrpt    3  1326.809 ±  15.509  ops/ms

cborBaselineWriteDoubleArray is current 3.x code
pr752CborWriteDoubleArray is with this PR change

@pjfanning pjfanning changed the title Use varhandle for array access in CBORGenerator Use varhandle for array access in CBORGenerator Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants