Optimizing Rust code with Flamegraph and DHAT – a practical example with Dust DDS

submited by
Style Pass
2024-06-22 08:30:04

In this article, we describe in detail the process we went through in the latest execution speed optimization of Dust DDS, a Rust-based implementation of the Data Distribution Service (DDS) standard. Utilizing benchmarks and tools like Flamegraph and Valgrind’s Dynamic Heap Analysis Tool (DHAT), we identified areas to improve the message send and receive cycle times of the middleware. Our optimizations included reducing memory allocation overhead in UDP message reception, improving serialization and deserialization efficiency, and removing the usage of async traits to avoid excessive memory allocations. These changes collectively resulted in performance gains of up to 50%.

The practical steps and insights shared in this article highlight the importance of combining benchmark-driven development with robust profiling tools to uncover and address performance bottlenecks. By systematically applying these techniques, we hope to provide inspiration for other developers aiming to optimize their own Rust applications.

Data Distribution Service (DDS) is a middleware standard for dependable, real-time, scalable data exchanges using a publish-subscribe communication pattern. As a foundational technology for applications in robotics, aerospace and automotive industries, performance is a crucial aspect of any DDS implementation. Dust DDS, our implementation of the standard, is built using Rust, a systems programming language renowned for its performance and safety. However, despite Rust’s inherent efficiency and optimization capabilities, there comes a point where detailed software analysis and engineering trade-offs are necessary to achieve maximum performance under the conditions most relevant to the system’s use.

Leave a Comment