Skip to content

Commit 0145307

Browse files
committed
Add Rust protobuf serialization/deserialization benchmark
Adds a benchmark testing Protocol Buffers encoding and decoding using prost. The benchmark processes ~1.0MB of protobuf binary data representing 100 user records with nested structures. Tests both deserialization (protobuf binary → Rust structs) and serialization (Rust structs → protobuf binary) in a single benchmark cycle. Includes a converter utility to generate protobuf binary data from JSON.
1 parent f3dacd4 commit 0145307

File tree

19 files changed

+1850
-2
lines changed

19 files changed

+1850
-2
lines changed

benchmarks/Dockerfile.rust

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
FROM rust:1.87
22
RUN rustup target add wasm32-wasip1
3+
# Install protobuf compiler for rust-protobuf benchmark
4+
RUN apt-get update && apt-get install -y protobuf-compiler && rm -rf /var/lib/apt/lists/*
35
WORKDIR /usr/src
4-
ADD rust-benchmark rust-benchmark
5-
WORKDIR /usr/src/rust-benchmark
6+
# Copy any additional files (like schema.proto for rust-protobuf)
7+
ADD . benchmark-src
8+
WORKDIR /usr/src/benchmark-src/rust-benchmark
69
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
710
RUN cargo build --release --target wasm32-wasip1
811
RUN mkdir /benchmark
18.2 KB
Binary file not shown.
5.16 KB
Binary file not shown.
-676 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
benchmark.wasm
2+
temp_data.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Dockerfile.rust

benchmarks/rust-protobuf/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Rust Protocol Buffers Serialization/Deserialization Benchmark
2+
3+
This benchmark tests Protocol Buffers encoding and decoding performance using the `prost` crate, a pure Rust implementation of Protocol Buffers.
4+
5+
## What it tests
6+
7+
The benchmark performs both deserialization (protobuf binary → Rust structs) and serialization (Rust structs → protobuf binary) on a realistic dataset representing user data with nested structures:
8+
9+
- 100 user records
10+
- Each user has a profile, settings, and multiple posts
11+
- Nested data structures including maps, repeated fields, and optional fields
12+
- Total input size: ~1.0 MB of protobuf binary data
13+
14+
## Input Data
15+
16+
The `default.input` file contains 100 user records encoded in Protocol Buffers binary format. The protobuf schema is defined in `schema.proto`.
17+
18+
To regenerate the input data:
19+
1. Run `python3 generate_input.py` to create JSON data
20+
2. Run `cargo run --release --bin converter` to convert JSON to protobuf binary
21+
22+
## Implementation
23+
24+
Uses:
25+
- `prost` 0.13 for Protocol Buffers encoding/decoding
26+
- `prost-build` for compile-time protobuf code generation
27+
- Measures full round-trip: decode protobuf binary → encode back to protobuf binary
28+
29+
## Notes
30+
31+
Protobuf binary format is more compact than JSON (~1.0 MB vs ~1.3 MB for the same data), making it useful for testing serialization performance with different data formats.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[rust-protobuf] processed 100 users
2+
[rust-protobuf] serialized size: 1081619 bytes

benchmarks/rust-protobuf/benchmark.stdout.expected

Whitespace-only changes.
-2.48 KB
Binary file not shown.

0 commit comments

Comments
 (0)