Java¶
Java’s serialization landscape spans JSON (Jackson, Gson, Fastjson2, DSL-JSON, Moshi, jsoniter), high-performance native binary (Kryo, Apache Fory, Protostuff, Hessian2, java.io), portable binary (MessagePack, CBOR, Smile, Ion, BSON, Kiln), schema/IDL stacks (Protocol Buffers, Avro, FlatBuffers, Cap’n Proto, SBE), and columnar files (Arrow IPC, Parquet, ORC). The registry has 30 serializers.
Runtime¶
What it is¶
Java compiles to bytecode, which is an intermediate instruction set. A Java Virtual Machine (JVM) then runs that bytecode. The JVM used here is HotSpot. It starts by interpreting bytecode and later JIT-compiles (just-in-time compiles) hot methods into native machine code. Unused objects are reclaimed by a garbage collector.
The JDK (Java Development Kit) includes both the compiler (javac) and the JVM. A JRE (Java Runtime Environment) is the virtual machine without the compiler. This suite needs a JDK because it compiles the runner before it times anything.
The language is specified by the Java Language Specification for Java SE 21. The virtual machine is specified by the Java Virtual Machine Specification for the same release. A short overview is Java.
| This suite | |
|---|---|
| Target | Java 21 (maven.compiler.release) |
| Host JDK | JDK 21 or newer. maven.compiler.release is 21, so JDK 17 cannot compile this tree. The install script places Temurin 21. |
| Build | Maven 3.9 or newer |
| Prepare | ./scripts/install-host-requirements.sh java installs into ~/.local/jdk-21 and ~/.local/maven |
| Run | java/scripts/run-benchmarks.sh (mvn package) |
| Memory | JVM garbage collector (HotSpot) |
What this suite runs¶
We compile and run as Java 21. Kotlin uses the same kind of JVM. Java is built with Maven. Kotlin is built with the Gradle wrapper that lives inside kotlin/.
What changes the numbers¶
The first repetitions pay for JIT warmup. Later repetitions are closer to the steady state the Dashboard reports. Reusing mappers and buffers, such as Jackson’s ObjectMapper and Kryo’s Output, keeps allocation down. Libraries that use reflection, and the built-in java.io serialization, allocate more. Those formats are also not portable to other languages.
These milliseconds cannot be ranked against C# or Python. The virtual machines are different.
Suite-specific gotchas¶
kryo, fory, hessian, protostuff, and java-serialization encode JVM object graphs. They are not universal cross-language wires.
Some JSON codecs shorten floating-point digits. Fidelity checks use a numeric tolerance for that reason.
Stream mode is native only where the serializer table says so. Elsewhere the stream path is the bytes path written through a buffer.
Where to go next¶
The steps to install the toolchain and run the benchmark are in java/README.md. Oracle’s overview is Java SE 21. For garbage collection and latency, see Latency tails and GC.
Benchmark runner¶
- Directory:
java/(repository root) - Output: monorepo
logs/java/YYYY-MM-DD-HHMMSS.csv(Language=java, times in nanoseconds) - Runner:
java/scripts/run-benchmarks.sh {smoke|all-single|full|research} - Registration:
java/src/main/java/benchmark/serializers/Registry.java
Serializers¶
| Serializer | Category | Package | Native path | Stream | Notes |
|---|---|---|---|---|---|
| avro | Schema | avro | ReflectDatum* | native | Schema once; encoder reuse |
| bson | Document | org.mongodb:bson | DocumentCodec | adapted | Domain→Document in prepare |
| dsl-json | JSON | dsl-json | runtime DslJson | native | Reused JsonWriter buffer |
| fastjson2 | JSON | fastjson2 | FieldBased API | adapted | toJSONBytes / parseObject |
| fory | Binary | fory-core 1.7.4 | serialize/deserialize | adapted | Apache Fory; register types before freeze |
| gld-kiln | Binary | gld-kiln-java 0.2.0 | Kiln.encodeTo / decode | adapted | Schema once; reused buffer. A batch is one list |
| gson | JSON | gson | Gson + Type | native | disableHtmlEscaping; JsonWriter/Reader |
| hessian | Binary | hessian | Hessian2 write/readObject | native | Dubbo-era RPC binary |
| ion | Document | jackson-dataformat-ion | IonObjectMapper | native | Amazon Ion binary |
| jackson | JSON | jackson-databind | ObjectWriter/Reader | native | Reused ObjectMapper; no pretty-print |
| jackson-cbor | CBOR | jackson-dataformat-cbor | CBORMapper | native | IETF CBOR |
| jackson-smile | Binary JSON | jackson-dataformat-smile | SmileMapper | native | Elasticsearch ecosystem |
| java-serialization | Native | JDK | ObjectOutputStream | native | Language baseline |
| jsoniter | JSON | jsoniter | DYNAMIC + javassist | adapted | JsonStream / JsonIterator |
| kryo | Binary | kryo | writeClassAndObject | native | Reused Kryo + Output/Input |
| moshi | JSON | moshi | JsonAdapter | native | Okio Buffer; Square stack |
| msgpack | MessagePack | jackson-dataformat-msgpack | MessagePackMapper | native | Official msgpack-java binding |
| protobuf | Schema | protobuf-java | MessageLite wire | native | Domain convert untimed |
| protostuff | Binary | protostuff-runtime | RuntimeSchema | native | LinkedBuffer reuse; list APIs |
| jackson-yaml | YAML | jackson-dataformat-yaml | YAMLFactory | native | Jackson YAML |
| jtoon | Text | jtoon | JToon.encode / decode |
adapted | Decode returns a JSON tree. toDomain is untimed. Size is UTF-8 bytes |
| json-io | Text | json-io | toToon / fromToon |
adapted | toDomain is untimed. Size is UTF-8 bytes |
| flatbuffers | Schema | flatbuffers-java | FlatBufferBuilder | adapted | Generated tables for the original five ids. Columnar types are hand-built in Java |
| capnproto | Schema | runtime | message builder | adapted | Bytes path copied to the stream |
| arrow-ipc | Columnar | arrow-vector | ArrowStreamWriter | adapted | IPC stream bytes, not the Arrow file format. table_project loads f_float_0 only |
| parquet | Columnar | parquet-avro | AvroParquetWriter | adapted | Snappy. parquet-java 1.18.1 defaults to UNCOMPRESSED, so this row sets the codec |
| parquet-uncompressed | Columnar | parquet-avro | AvroParquetWriter | adapted | CompressionCodecName.UNCOMPRESSED |
| orc | Columnar | orc-core nohive |
OrcFile.Writer | adapted | No compress() call. ORC 2.3.1 default is ZSTD. blockPadding(false) |
| orc-uncompressed | Columnar | orc-core nohive |
OrcFile.Writer | adapted | CompressionKind.NONE. blockPadding(false) |
| sbe | Schema | sbe-tool / agrona | flyweight | adapted | Tool 1.40.2. No nested_table. Flyweight filled inside the timed serialize |
Specifics¶
Why each library exists, what problem it was written to solve, and how. Names link to the source repository (or the stdlib / in-tree path this suite times).
avro¶
Apache Avro was created for Hadoop-era pipelines: compact binary records with the schema stored out of band. Official language runtimes implement that encoding. This row times the platform's Avro library.
bson¶
BSON (Binary JSON) was created for MongoDB so documents could be stored and traversed without a text parse. Official language drivers implement that spec. This row times that library's serialize/deserialize path.
dsl-json¶
dsl-json was written for very high-performance JSON on the JVM with compile-time binding. The problem was reflection mappers allocating too much. It reuses a JsonWriter buffer on the hot path.
fastjson2¶
fastjson2 is Alibaba's rewrite of fastjson for high-performance JSON on the JVM. The problem was JSON cost in large Java services (and security issues in fastjson 1.x). fastjson2 solves it with a new FieldBased API.
fory¶
Apache Fory (formerly Fury) was created for high-performance, cross-language serialization. The problem was that JVM-centric binary codecs and slow portable formats left a gap. Fory registers types and serializes with a compact binary protocol.
gld-kiln¶
gld-kiln (leo-gan) is a positional little-endian codec. The timed path reuses one writer. There are no field tags on the wire. This row times encode and decode of the suite structs. On the tensor data set this row runs every type. tensor_view borrows the float32 payload and does not copy the matrix.
gson¶
Gson was created at Google to convert Java objects to JSON and back with a simple API. The problem was boilerplate-heavy Java JSON. Gson solves it with reflection over POJOs and a JsonWriter/Reader stream API.
hessian¶
Hessian is Caucho's compact binary web-service protocol from the Dubbo/Caucho era. The problem was SOAP/XML RPC overhead. Hessian2 write/readObject is the binary that this row times.
ion¶
Amazon Ion was created as a rich, self-describing superset of JSON (text and binary) for Amazon services. Official Ion libraries and Jackson Ion modules implement that model.
jackson¶
Jackson was created as the standard data-binding toolkit for Java JSON (and later many binary/text formats). The problem was that Java needed a fast, annotation-driven mapper for REST and services. Jackson solves it with ObjectMapper / ObjectWriter and format modules (CBOR, Smile, YAML, Ion, MessagePack).
jackson-cbor¶
Jackson was created as the standard data-binding toolkit for Java JSON (and later many binary/text formats). The problem was that Java needed a fast, annotation-driven mapper for REST and services. Jackson solves it with ObjectMapper / ObjectWriter and format modules (CBOR, Smile, YAML, Ion, MessagePack). This row times Jackson's CBOR mapper.
jackson-smile¶
Jackson was created as the standard data-binding toolkit for Java JSON (and later many binary/text formats). The problem was that Java needed a fast, annotation-driven mapper for REST and services. Jackson solves it with ObjectMapper / ObjectWriter and format modules (CBOR, Smile, YAML, Ion, MessagePack). This row times Jackson's Smile (binary JSON) mapper.
java-serialization¶
Java Object Serialization (ObjectOutputStream) is the language's built-in graph serializer. It exists so the JVM can persist and RMI Java objects. It is not a portable wire format.
jsoniter¶
jsoniter for Java was created as a high-performance JSON library with an optional codegen path. The problem was Jackson/Gson overhead. This suite uses DYNAMIC mode plus javassist.
kryo¶
Kryo was written as a fast binary serializer for JVM object graphs (games, caches, RPC). The problem was Java serialization being slow and verbose. Kryo solves it with a compact binary and reusable Output/Input.
moshi¶
Moshi was created at Square as a modern JSON library for Java and Android, successor-minded to Gson. The problem was Gson's older model on Android. Moshi solves it with JsonAdapter, codegen or reflection, and Okio.
msgpack¶
msgpack-java is the official MessagePack library for the JVM. MessagePack exists as compact binary JSON. This suite times the Jackson MessagePack mapper on that stack.
protobuf¶
Protocol Buffers were created at Google so many languages could share a compact, evolving binary contract without hand-written parsers. The problem was ad-hoc binary formats and verbose XML. Protobuf solves it with an IDL, generated code, and a documented tag/length wire format.
protostuff¶
protostuff was created to serialize Java objects with protobuf-like efficiency without writing .proto files. The problem was protobuf's IDL tax for internal graphs. Runtime schemas and LinkedBuffer reuse are the solution this row times.
jackson-yaml¶
Jackson was created as the standard data-binding toolkit for Java JSON (and later many binary/text formats). The problem was that Java needed a fast, annotation-driven mapper for REST and services. Jackson solves it with ObjectMapper / ObjectWriter and format modules (CBOR, Smile, YAML, Ion, MessagePack). This row times Jackson's YAML mapper.
jtoon¶
jtoon is the official Java codec for TOON. JToon.encode writes the text. JToon.decode returns a JSON tree, and the untimed toDomain step turns that tree into the suite type. The Size column is the UTF-8 byte length.
json-io¶
json-io writes TOON with toToon and reads it with fromToon. This row turns strictToon on. The untimed toDomain step turns the decoded tree into the suite type. The Size column is the UTF-8 byte length.
flatbuffers¶
FlatBuffers was created at Google so games and clients could access serialized data without an unpack step. The problem was that protobuf-style decode allocated a full object graph. FlatBuffers solves it with a schema and a binary layout that can be traversed in place.
capnproto¶
Cap'n Proto was created by Kenton Varda (after protobuf 2) so RPC and storage could use a binary layout that is already the in-memory representation — no encode step. The problem was protobuf's parse/serialize cost. Cap'n Proto solves it with an IDL and packed/unpacked segments.
arrow-ipc¶
Apache Arrow was created so analytic engines could share columnar batches without copying each one into a private layout. The problem was a convert-at-every-boundary tax. Arrow IPC is the stream format for those batches. This row times arrow-vector 19.0.0 ArrowStreamWriter inside the bytes API, not the Arrow file format and not arrow-dataset. The schema is built in prepare. Row-to-column conversion stays inside serializeBytes. table_project loads f_float_0 only. No compliance decoder.
parquet¶
Apache Parquet was created as a columnar file for scans that touch a few fields of many rows. The problem was row files that made every reader parse every column. This row times parquet-avro 1.18.1 AvroParquetWriter. parquet-java's default codec is UNCOMPRESSED, so this row sets CompressionCodecName.SNAPPY. table_project sets AvroReadSupport requested projection to f_float_0. No compliance decoder.
parquet-uncompressed¶
This is the same parquet-avro writer as parquet, with CompressionCodecName.UNCOMPRESSED. The name is the override. No compliance decoder.
orc¶
Apache ORC was created as a columnar file with stripe indexes for scans. This row times orc-core 2.3.1 (classifier nohive). OrcConf.COMPRESS defaults to ZSTD, so orc does not call compress(). orc-uncompressed sets CompressionKind.NONE. Both rows set blockPadding(false) so a small file is not padded toward the 256MB HDFS block. table_project includes f_float_0 only. No compliance decoder.
orc-uncompressed¶
This is the same orc-core writer as orc, with CompressionKind.NONE and blockPadding(false). The name is the override. No compliance decoder.
sbe¶
SBE (Simple Binary Encoding) was created for word-aligned financial messages: a fixed block, then repeating groups, then variable-length data. The problem was tag/length codecs that touch every field on the hot path. This row fills the sbe-tool 1.40.2 Java flyweight inside serializeBytes. Agrona is the runtime. The generator jar is sbe-all, copied from Maven at build time. It encodes table, table_project, and signal. nested_table is not an SBE body. The signal wire order is fixed fields, then the legs group, then symbol and venue. No compliance decoder.
Columnar and SBE¶
The six new rows support table, table_project, nested_table, and signal only. SBE returns false for nested_table because that body is not in the schema. The original codecs still support message, document, telemetry, strings, and event. Jackson, protobuf, flatbuffers, and the reflect Avro row also round-trip the four new ids.
prepare builds the Arrow schema, the Parquet/Avro schema, and the ORC TypeDescription plus writer options. Row-to-column conversion and the SBE flyweight wrap run inside timed serializeBytes. There is no compliance decoder. Stream methods on these rows are the adapted bytes path. Columnar smoke times bytes only.
table_project serializes the full row and deserializes f_float_0 only, including when N is 1. The runner compares that column (Fidelity.expectedForFidelity), not the full rows. Arrow reads that column with MessageChannelReader, MessageSerializer.deserializeRecordBatch, and VectorLoader on a one-field schema. Parquet sets AvroReadSupport.setRequestedProjection and setAvroReadSchema. ORC sets Reader.Options.include with the root and f_float_0 column ids. Peers full-decode, then slice inside deserialize.
orc and orc-uncompressed both set blockPadding(false). Default padding would extend a small file toward the 256MB HDFS block. That flag is not a compression override. ORC 2.3.1's own default compression is ZSTD (OrcConf.COMPRESS), so orc does not call compress(). orc-uncompressed sets CompressionKind.NONE. The nohive jars relocate Hive vectors to org.apache.orc.storage and protobuf to org.apache.orc.protobuf. orc-core nohive is paired with orc-format nohive 1.1.1; the default orc-format jar is compiled against com.google.protobuf and does not link. parquet-java 1.18.1 defaults to UNCOMPRESSED, so parquet sets CompressionCodecName.SNAPPY and parquet-uncompressed sets UNCOMPRESSED.
Call-path contract (same idea as Go/Python/Rust)¶
prepare(fixture) # untimed: mappers, schemas, Fory register, proto convert
for rep:
serialize_bytes / stream # timed
deserialize_bytes / stream # timed (codec only)
toDomain (if needed) # untimed (e.g. protobuf Message → model)
fidelity(expected, actual) # untimed
Caveats¶
- java-serialization, kryo, fory, hessian, protostuff are not universal cross-language wire formats.
- protobuf domain conversion is outside the timer (fair codec measurement).
- Stream mode is native only where noted; others are adapted bytes+buffer.
- Some JSON codecs (e.g. jsoniter) shorten floating-point digits; fidelity uses float tolerance.
Also: java/README.md. Families.
Numbers¶
Measured numbers for this language live on the Dashboard (pre-filtered). Claim level is L1 (one machine, one session) — see Claims and replication.
Design choices¶
- Prepare outside the loop — ObjectMapper/ObjectWriter, Kryo buffers, Fory type registration, Avro schema, protobuf messages.
- Optimal APIs — library-recommended encode/decode; no pretty-print.
- Dual mode —
bytesandstreamwithStreamModemetadata. - Shared domain types in
benchmark.model.v2with public fields for reflection codecs.