You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python bindings copy binary payloads byte-by-byte, capping publish_video at ~18 fps (fixed in uniffi 0.32) #2946
The Python bindings copy every binary payload with a per-byte Python loop, which
costs ~120 ns/byte. At 640x360 that is ~41 ms of pure Python per I420 video
frame before the encoder is even reached, capping publish_video at ~18 fps and
preventing it from scaling across threads.
uniffi fixed this upstream in 0.32.0; rs/moq-ffi/Cargo.toml pins uniffi = "0.31".
The code
uniffi_bindgen 0.31.2, src/bindings/python/templates/RustBufferTemplate.py,
reproduced into the generated moq_ffi/_uniffi/moq.py:
Isolated, on one 640x360 I420 frame (345,600 bytes):
per-byte python loop: 41.58 ms (120.3 ns/byte)
ctypes.memmove: 0.04 ms ( 0.121 ns/byte)
Impact
Measured through BroadcastProducer.publish_video (H.264), feeding pre-converted
I420 so no colour conversion is involved. Cost is linear in payload size, and
identical for the openh264 and NVENC backends, because it is spent in Python
before either one runs:
resolution
before
after
160x96
3.94 ms/frame
0.19 ms/frame
320x180
13.72 ms/frame
0.36 ms/frame
640x360
54.49 ms/frame
1.13 ms/frame
1280x720
216.03 ms/frame
4.94 ms/frame
It also serialises publishing, since the loop holds the GIL. Two threads each
publishing their own track, 640x360 I420:
threads
before
after
1
18.7 fps total
838 fps total
2
17.2 fps total
1598 fps total
Before the fix a second publisher buys nothing; after it, throughput scales
about linearly.
This is not video specific. Every binary payload through the Python bindings
pays it, MoqAudioFrame.data and publish_track payloads included.
Reproducing
Patching the generated moq.py in place with the 0.32 memmove version
produces the "after" column above, which is what identifies the loop rather than
the codec as the cost.
Found while publishing two 640x360 CARLA camera feeds from one Python process:
both trucks sat at ~3.4 fps, and went to a full 30 fps each with the copy fixed.
Suggested fix
Bump uniffi from 0.31 to 0.32 in rs/moq-ffi/Cargo.toml (three entries:
the main dependency, the wasm one, and the build-dependency).
Environment: Linux x86_64, CPython 3.12, moq-ffi 0.3.11 built from adad52b, release profile.
#2462 - build(rust): pin the toolchain and correct the MSRV claims [merged] #2465 - build(moq-video): bump moq-vaapi to 0.0.3 (dlopen libva) [merged] #2503 - refactor(moq-video)!: one raw Frame type, and carry timestamps through encode [merged] #2608 - feat(bindings): publish raw video with a native encoder [merged] #2911 - feat(moq-ffi): compile for wasm32 [merged]
📝 Issue Planner
Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.
Create Plan
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
💬 Have feedback or questions? Drop into our discord!
Activity
coderabbitai commentedon Aug 19, 2026
🔗 Related PRs
#2462 - build(rust): pin the toolchain and correct the MSRV claims [merged]
#2465 - build(moq-video): bump moq-vaapi to 0.0.3 (dlopen libva) [merged]
#2503 - refactor(moq-video)!: one raw Frame type, and carry timestamps through encode [merged]
#2608 - feat(bindings): publish raw video with a native encoder [merged]
#2911 - feat(moq-ffi): compile for wasm32 [merged]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
fix(moq-ffi): bump uniffi to 0.32 so Python copies payloads with memmove