Optimizing a Rust AV1 Decoder: Avoiding Unnecessary Zeroing and Optimizing Struct Comparisons

2025-05-22
Optimizing a Rust AV1 Decoder: Avoiding Unnecessary Zeroing and Optimizing Struct Comparisons

By comparing the performance of the Rust-based AV1 decoder rav1d and the C-based dav1d, the author, using a sampling profiler, identified two performance bottlenecks. The first was unnecessary zeroing of a buffer in rav1d on ARM architecture, leading to performance degradation. The second was an inefficient implementation of struct comparisons in rav1d. By using `MaybeUninit` to avoid unnecessary zeroing and optimizing struct comparisons, the author improved rav1d's performance by almost 2%.

Read more
Development AV1 Decoder

Rust Learns from Python's Dynamic Capabilities: Reflection with Serde

2025-05-15
Rust Learns from Python's Dynamic Capabilities: Reflection with Serde

This article details how the author used Rust and the Serde library to mimic Python's dynamic attribute access (__getattr__) mechanism, creating a clean and user-friendly API for accessing system information. The article thoroughly explains the implementation process, including custom trait, Deserializer, and Visitor implementations, and how to leverage Serde's derive(Deserialize) feature to simplify the code. Ultimately, the author successfully built an efficient and user-friendly Rust library that achieves a Python-like concise API, and discusses alternative approaches and trade-offs.

Read more
Development

The Insane __init__ Method That Almost Broke My Sanity

2025-04-19
The Insane __init__ Method That Almost Broke My Sanity

A Python service test intermittently failed due to a bizarre __init__ method. The FooBarWidget class, in its __init__, starts a new thread to execute its parent class FooWidget's __init__ and run methods. This design attempts to avoid blocking the main thread because zmq.Socket objects can't be moved between threads. However, closing a FooBarWidget instance too early might leave FooWidget's __init__ unfinished, resulting in a missing 'should_exit' attribute and an error. This humorous account details the debugging ordeal and explores the rationale behind this unconventional design.

Read more
Development