Skip to content

UTF8JsonGenerator: writeNumber fast path that avoids extra String allocation - #1657

Merged
cowtowncoder merged 10 commits into
FasterXML:3.2from
pjfanning:utf8-writenum-fast-path
Aug 14, 2026
Merged

cowtowncoder merged 10 commits into
FasterXML:3.2from
pjfanning:utf8-writenum-fast-path

Conversation

@pjfanning

@pjfanning pjfanning commented Aug 12, 2026

Copy link
Copy Markdown
Member

Partially related to #1656
The new XJBWriter has support for writing the number to a pre-existing byte array and avoid String allocations.
It's possible that 1656 will get nowhere but I thought that it might be worth considering this change as a completely separate change.
I modified the existing Schubfach code to allow String allocation to be skipped when writing numbers in UTF8JsonGenerator.
And if we do switch to XJB, the NumberOutput class can be modified to use XJB instead of Schubfach but this PR tests UTF8JsonGenerator in isolation.

This change only kicks in if you enable StreamWriteFeature.USE_FAST_DOUBLE_WRITER

@pjfanning

Copy link
Copy Markdown
Member Author

@cowtowncoder this change gives quite a boost when using Utf8JsonGenerator with USE_FAST_DOUBLE_WRITER enabled. I'll put the numbers in https://github.com/pjfanning/double-reader-writer readme.
But basically,

Benchmark                                         Mode  Cnt    Score    Error   Units
JsonGeneratorBenchmark.baselineWriteDoubleArray  thrpt    3   93.082 ± 38.279  ops/ms
JsonGeneratorBenchmark.pr1657WriteDoubleArray    thrpt    3  146.721 ± 78.125  ops/ms
JsonGeneratorBenchmark.xjbWriteDoubleArray       thrpt    3  189.703 ± 59.990  ops/ms

Where baselineWriteDoubleArray is existing jackson-core, pr1657WriteDoubleArray is with this change and xjbWriteDoubleArray is with this change plus the XJB Writer from #1656.

@pjfanning

Copy link
Copy Markdown
Member Author

@cowtowncoder I think this change is small enough that it might be worth considering including it in the next 3.2 release or even the nest 3.1 LTS release. There is an argument that the related PR1656 is too big to add until 3.3.0.

@cowtowncoder

Copy link
Copy Markdown
Member

@pjfanning If you can rebase against 3.2, sure -- I am now releasing 3.1.6 so maybe not 3.1.

@cowtowncoder

cowtowncoder commented Aug 14, 2026

Copy link
Copy Markdown
Member

Needs release-notes/VERSION entry.

EDIT: added.

@pjfanning
pjfanning changed the base branch from 3.x to 3.2 August 14, 2026 20:36
@pjfanning
pjfanning force-pushed the utf8-writenum-fast-path branch from 26fd7a6 to 6593e64 Compare August 14, 2026 20:37
@pjfanning
pjfanning force-pushed the utf8-writenum-fast-path branch from 6593e64 to 2fb2911 Compare August 14, 2026 20:40
@pjfanning

Copy link
Copy Markdown
Member Author

Retargeted PR to 3.2 branch

@cowtowncoder cowtowncoder added performance Issue related to performance problems or enhancements 3.2 labels Aug 14, 2026
@cowtowncoder cowtowncoder added this to the 3.2.2 milestone Aug 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📈 Overall Code Coverage

Metric Coverage Change
Instructions coverage 83.76% 📈 +0.070%
Branches branches 76.64% 📈 +0.040%

Overall project coverage from JaCoCo test results. Change values compare against the latest base branch build.

@cowtowncoder
cowtowncoder merged commit ebd18e4 into FasterXML:3.2 Aug 14, 2026
6 checks passed
@pjfanning
pjfanning deleted the utf8-writenum-fast-path branch August 14, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.2 performance Issue related to performance problems or enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants