benchmarking serialization frameworks
  • Rust 94.9%
  • Nix 5.1%
Find a file
renovate 1195ca9e1f
All checks were successful
check / check (push) Successful in 30s
chore(deps): update spotdemo4/nix-init action to v1.58.0 (#11)
2026-07-15 05:21:45 -04:00
.forgejo chore(deps): update spotdemo4/nix-init action to v1.58.0 (#11) 2026-07-15 05:21:45 -04:00
.vscode Initial commit 2026-06-22 08:41:31 -04:00
.zed Initial commit 2026-06-22 08:41:31 -04:00
benches feat(benchmarks): replace rpc payloads with checkout scenarios 2026-06-22 17:35:28 -04:00
.envrc.project Initial commit 2026-06-22 08:41:31 -04:00
.gitignore Initial commit 2026-06-22 08:41:31 -04:00
AGENTS.md Initial commit 2026-06-22 08:41:31 -04:00
Cargo.lock chore(deps): lock file maintenance (#10) 2026-07-12 05:39:27 -04:00
Cargo.toml feat(bench): add serde_json serialization benchmark 2026-06-22 16:36:32 -04:00
CLAUDE.md Initial commit 2026-06-22 08:41:31 -04:00
flake.lock chore(deps): lock file maintenance (#10) 2026-07-12 05:39:27 -04:00
flake.nix feat(bench): add serde_json serialization benchmark 2026-06-22 16:36:32 -04:00
LICENSE Initial commit 2026-06-22 08:41:31 -04:00
main.rs refactor(fory): switch benchmark to xlang mode 2026-06-22 10:04:32 -04:00
README.md feat(benchmarks): replace rpc payloads with checkout scenarios 2026-06-22 17:35:28 -04:00
treefmt.toml Initial commit 2026-06-22 08:41:31 -04:00

serialization-bench

check vulnerable rust

Benchmarking serialization frameworks for encode/decode throughput and payload size.

Benchmark

cargo bench
nix run .#bench

Individual benchmarks can also be run directly:

cargo bench --bench flatbuffers
cargo bench --bench fory
cargo bench --bench json
cargo bench --bench protobuf
nix run .#bench-flatbuffers
nix run .#bench-fory
nix run .#bench-json
nix run .#bench-protobuf

The FlatBuffers benchmark uses flatbuffers with generated-style Rust table accessors committed in the benchmark source. The Apache Fory benchmark uses fory xlang mode. The JSON benchmark uses serde_json. The protobuf benchmark uses prost. All benchmarks print encoded payload size.

Suites

The shared safe full-decode suite measures encode, verified/safe decode into owned Rust values, and round-trip throughput for every framework.

suite frameworks payloads operations
safe full decode FlatBuffers, Apache Fory xlang, JSON/serde_json, Protobuf/prost telemetry event, checkout request, checkout response encode, decode, round-trip
verified access all FlatBuffers telemetry event verify buffer and read every field through accessors without materializing owned values
verified access partial FlatBuffers telemetry event verify buffer and read routing/latest-sample fields through accessors
optimized struct vector FlatBuffers telemetry event encode, decode, and round-trip with metric samples modeled as FlatBuffers structs

Results

Run on debian (x86_64, Linux 6.17.13-3-pve) with Rust 1.95.0. Each benchmark used Criterion with 10 seconds of warmup, 60 seconds of measurement, and 200 samples per operation. Values are Criterion point estimates with throughput in parentheses.

Safe Full Decode

payload framework encoded size encode decode round-trip
telemetry event Apache Fory xlang 1,597 B 1.4118 us (1.0535 GiB/s) 1.7537 us (868.46 MiB/s) 3.1475 us (483.87 MiB/s)
telemetry event JSON/serde_json 8,217 B 7.4642 us (1.0253 GiB/s) 11.828 us (662.54 MiB/s) 19.821 us (395.36 MiB/s)
telemetry event Protobuf/prost 2,079 B 3.7013 us (535.68 MiB/s) 3.7038 us (535.31 MiB/s) 7.4827 us (264.97 MiB/s)
telemetry event FlatBuffers 4,984 B 6.5584 us (724.73 MiB/s) 7.8142 us (608.27 MiB/s) 14.601 us (325.53 MiB/s)
checkout request Apache Fory xlang 814 B 1.1173 us (694.78 MiB/s) 1.0175 us (762.94 MiB/s) 2.4682 us (314.51 MiB/s)
checkout request JSON/serde_json 1,025 B 1.5293 us (639.17 MiB/s) 2.2278 us (438.77 MiB/s) 4.1954 us (233.00 MiB/s)
checkout request Protobuf/prost 460 B 1.0685 us (410.58 MiB/s) 1.2409 us (353.53 MiB/s) 2.5096 us (174.80 MiB/s)
checkout request FlatBuffers 944 B 1.4313 us (629.00 MiB/s) 1.8834 us (477.99 MiB/s) 3.8634 us (233.02 MiB/s)
checkout response Apache Fory xlang 594 B 787.43 ns (719.41 MiB/s) 696.20 ns (813.68 MiB/s) 1.6172 us (350.28 MiB/s)
checkout response JSON/serde_json 738 B 1.1074 us (635.53 MiB/s) 1.4298 us (492.23 MiB/s) 2.7675 us (254.32 MiB/s)
checkout response Protobuf/prost 371 B 816.76 ns (433.19 MiB/s) 810.40 ns (436.59 MiB/s) 1.6526 us (214.09 MiB/s)
checkout response FlatBuffers 688 B 1.0368 us (632.81 MiB/s) 1.2257 us (535.31 MiB/s) 2.4768 us (264.91 MiB/s)

FlatBuffers Specific

suite encoded size operation result
verified access all 4,984 B access all 7.5116 us (632.77 MiB/s)
verified access partial 4,984 B access partial 7.3807 us (643.99 MiB/s)
optimized struct vector 3,424 B encode 1.1754 us (2.7130 GiB/s)
optimized struct vector 3,424 B decode 930.92 ns (3.4255 GiB/s)
optimized struct vector 3,424 B round-trip 2.2738 us (1.4024 GiB/s)

Payloads

The telemetry event is a larger batch-style message with service metadata, tags, four attributes, and 128 metric samples.

The checkout request is a CheckoutService.PlaceOrder request with request metadata, customer/session IDs, currency, three line items, shipping address, payment method, coupon codes, and four attributes.

The checkout response is a successful order response with request metadata, order status, subtotal/discount/tax/shipping/total amounts, two shipments, and four attributes.