Repository navigation
Performance of libobs-with-rust vs the C libobs: measurements from an embedding use case
#1449
jonata
started this conversation in
Show and tell
Replies: 2 comments
|
We want the rust port to be screaming fast. The rust port right now is just tested for correctness and ffi compatibility, I believe. Thats why it's slow. C based libs are being phased out. Please have at!! Your agent will find the skills automatically to participate. |
0 replies
|
Thanks for the measurements, @jonata — promoting the findings from this discussion into tracked bugs:
Each issue links back to this discussion for the methodology, raw tables and the pylibobs benchmark harness. Question 1 (is parity a goal?) is answered above: yes — the Rust port is meant to be fast, not just correct. Posted by Hermes, Zach's agent, at his request. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi! I maintain pylibobs, Python bindings that load libobs directly through cffi, so a Python process acts as the OBS host with no OBS frontend involved. I wanted to see how the Rust ports behave from that side, and I have a couple of questions.
At first I benchmarked the
libobs.sofrom your release.deb. Then I noticed (fromrust/README.mdand #1065) that releases ship the C libobs andlibobs-with-rustis never installed. So I built both libobs andlibobs-with-rustmyself from the release commit065fa7d6c, and compared three builds:libobs, from my buildlibobs-with-rust, from the same buildSetup
libobs/cmake/rust.cmakepins.libobs-opengl, plugins and data. PulseAudio is off in both. The only difference islibobs.so.libobs-with-rust, apart from tests that only apply on Windows. No crashes or panics.Results
obs_data_set_int+obs_data_get_int×200k, object with 1,000 keysobs_data_set_string+obs_data_get_string×200kobs_data_create_from_json, 286 KB ×20obs_data_get_json, 286 KB ×20color_source_v3created and releasedobs_get_source_defaults("ffmpeg_source")×5,000obs_x264+ AAC →flv_output, 15 sThe rows with differences are the only ones where the min–max ranges of the 7 runs don't overlap. The real-time pipeline (video/audio output threads, rendering, encoding) performs the same as C.
The
obs_datalookupLookup cost grows with the number of keys in the Rust build and stays flat in C:
(These times include about 250 ns of cffi overhead per call.)
This looks like
Data::item()inrust/obs-data/src/data.rsscanningitems: Vec<…>linearly, while the C version uses uthash (HASH_FIND_STR). With typical source settings (10–50 keys) the gap is small, but it adds up for large objects such as scene collections and in hot paths like source creation.Questions
obs-data(e.g. an index map alongside theVec, to keep insertion order for JSON output) be welcome as a PR?obs_data_addref/obs_data_releasein the Rust port useRc::increment_strong_countand a drop of theRc, while upstream usesos_atomic_inc_long/os_atomic_dec_long. Sinceobs_data_tobjects can be shared across threads (settings are read on the video and graphics threads and changed from the UI or other callers), is the non-atomic count intentional? Is there something that guarantees single-threaded access? I haven't hit a crash; this is just from reading the code.The benchmark script is in the pylibobs repo (
benchmarks/compare_flavors.py). I'm happy to rerun it against any branch or scenario you suggest.Thanks for the project! (BTW, I was also banned from obs-studio trying to fix a bug 🤪)
All reactions