Skip to content

Use varhandle for array access in CBORGenerator - #752

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

Use varhandle for array access in CBORGenerator#752
pjfanning wants to merge 7 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.24% 📉 -0.73%
🔀 Branches 68.10% 📉 -0.03%

Added comments explaining the choice of float representation in _writeFloatNoCheck method.
Removed commented-out code regarding float handling.
* Utility class that provides {@link VarHandle} instances for efficient
* multi-byte primitive writes to byte arrays. Falls back gracefully
* if VarHandles are not available (e.g., on some Android runtimes).
*/

@cowtowncoder cowtowncoder Aug 14, 2026

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.

@since 3.3

@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

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