fastproto exposes Rust protobuf structs (generated by prost) to Python.
Both Rust and Python code share the same memory layout.
Python code accessing a field [123, 456, 789]
will get a reference to Vec instead of copying them to PyList.
# decoding (secs)
2021 2023
Python: 14.008996680990094 Python: 0.3742136040236801
Rust : 0.5708326659951126 Rust : 0.47216512804152444
# encoding (secs)
2021 2023
Python: 8.68384731200058 Python: 0.26067180099198595
Rust : 0.3029898940003477 Rust : 0.23681609996128827
===========
PythonTweet
===========
b'\n\x11Hi this is a text\x10\xfb\x99K"\x1b\n\x03Who\x12\x14https://example.com/*\x06@trump*\x06@obama'
===========
RustTweet
===========
b'\n\x11Hi this is a text\x10\xfb\x99K"\x1b\n\x03Who\x12\x14https://example.com/*\x06@trump*\x06@obama'
All you need is adding a single line
.type_attribute(".", "#[::pyo3_prost::pyclass_for_prost_struct]")
to your prost or tonic build.
- Go to
examples/proto-gen
andcargo run
. This will generateexamples/rupy_proto/src/app.rs
. - Go to
examples/rupy_proto
andcargo build --release
. - Move
examples/rupy_proto/target/release/librupy_proto.so
toexamples/rupy_proto/rupy_proto.so
. - Run the bench
cd examples/rupy_proto && PYTHONPATH=. python bench_{decode, encode}.py
.
- rename pyo3-prost
- oneof fields
- enum