Rewrite, optimize, repeat: Our journey porting a triemap from C to Rust
summary
Ported a C TrieMap used inside Redis’ query engine (the C codebase is ~63,000 LOC) into Rust, starting with a simplified baseline, adding microbenchmarks and FFI tests, then reimplementing a packed, single-allocation node layout using manual alloc, pointer metadata and custom DST-like handling. Resulting Rust module grows from ~1,000 C lines to ~1,900 Rust lines, uses single heap allocation layout, contains 128 unsafe expressions across 21 private unsafe methods but keeps unsafe <10% of code, achieves 96% test coverage, and matches or outperforms the original with only a few percent extra memory.
AI-written summary · about
chapters (9)
- 0:00Introduction and context
- 0:54Migration strategy
- 2:39Module graph and trie maps
- 4:28Data structure challenges
- 7:33Baseline and initial results
- 10:42Implementing the final version
- 13:58Managing unsafe code
- 18:25Results and conclusion
- 20:02Q&A session
related talks
33mRewrite, Optimize, Repeat
01h 02mRewriting of a small component from C to Rust
41mMigrating RediSearch from C to Rust - Challenges and Techniques
27mWhoops! I Rewrote It in Rust
34mWhoops! I Rewrote it in Rust
40mRust’s approach of getting things right
31mPorting Turborepo From Go To Rust
54mUnwrap()Ing Rust on Embedded Linux
