This Saturday I got rid of a lot of allocations in the GStreamer logging Rust bindings ✨
That was a lot of fun 😁
When using GStreamer 1.20 or newer, the only allocations that are left now are
- the formatted string if any formatting is necessary, i.e. if a string literal is logged no allocation is needed
- when the default GStreamer log output function is used, one allocation is needed for building the whole log line
Previously there were at least 4 additional heap allocations per log. When logging string literals this is now one heap allocation less than from C 🥳
Additionally, thanks to an awful Rust hack, all logging is actually using the function name instead of the module name for giving context information.
This required a couple of changes in gtk-rs that then made the following gstreamer-rs MR possible: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1160
There are probably other places that could be improved in the same way, but this seemed like something performance critical.
#GStreamer #Rust #RustLang #WeekendHacking