Supporting faster file load times with memory optimizations in Rust
Figma's Rust multiplayer server represented each file node as a BTreeMap from u16 property IDs to pointers, and memory profiling showed this map used over 60% of a file's memory. Because the schema has fewer than 200 fields and nodes average about 60 keys, the team swapped it for a flat sorted vector. Despite worse big-O complexity, the cache-friendly layout cut p99 deserialization time by 20% and fleet memory by about 20%. A further experiment stored the field ID in the unused top 16 bits of x86-64 pointers, saving only about 5% more RSS. That change was not shipped because of the risk of getting reference counts wrong and corrupting memory.
Related posts
- Improving performance in the layers panel
Figma mediumAdept
Figma rebuilt its layers panel to fix two problems: it computed data for every expanded node, and it recomputed everything after any change. Splitting data gathering into two passes means full row data is computed only for the few dozen windowed rows. Modeling the row tree with lazy, cached derived properties (spreadsheet-like dependency tracking) means only the affected subtree recomputes. A rope-like recursive list for cached ordered children avoids O(n²) memory, cutting memory by up to 99%, and key interactions got 30–50% faster in large files, with smoother editing overall.
- The effect of switching to TCMalloc on RocksDB memory use
Cloudflare mediumAdeptQuicksilver's memory roughly doubled after its storage moved to RocksDB, climbing from about 15GB to 30GB over several days. Heap profiling showed the heap was about a third of RSS, which pointed to the allocator rather than a leak. glibc malloc gives threads independent per-thread arenas (60-80 arenas for about 25 threads), and memory cannot move between them, so fragmentation multiplies. Mitigations such as MALLOC_ARENA_MAX, periodic malloc_trim and M_MMAP_THRESHOLD each cost lock contention or syscalls, while TCMalloc's middle-end moves freed memory between per-core caches and cut memory use by 2.5x.
- We Have to Start Over: From Atom to Zed
Zed easyNoviceZed's co-founders explain why they abandoned Atom's Electron/JavaScript stack and rebuilt a code editor in Rust: JavaScript's pointer-chasing arrays, uncontrollable GC pauses, and the costly JS/C++ boundary for multithreading made performance work feel like fighting the platform. Rust's ownership model pushed them toward a copy-on-write B-tree (SumTree) rope built on Arc, letting snapshots move to background threads in O(1), and high-level Rust code cut a find-all-matches operation from 1s to 4ms. GPU rendering with custom shaders and signed distance fields came out of necessity after Pathfinder proved too slow. Owning the stack (Tree-sitter, GPUI) lets them change anything, such as adding WASM language extensions, at the cost of building more themselves.
- iddqd, or the hardest kind of unsafe Rust
Oxide hardMaster
iddqd is a Rust map library, used in Oxide's Omicron control plane, where keys are borrowed from the values themselves. That avoids both passing key and value around separately and duplicating the key in both places. Internally each map pairs a slab-like ItemSet (a Vec of Occupied/Vacant slots with a free chain) with a hashbrown HashTable or B-tree index of slot indices, and BiHashMap and TriHashMap keep two or three such indexes over the same records. Because these generic structures call back into user-supplied trait code, their unsafe code (notably mutable iteration) must stay sound even against adversarial safe Rust. That is a harder standard than the slice-local or module-local reasoning needed for cases like split_at_mut, illustrated with a broken ExactSizeIterator example.
- This Week at Zed Industries: #1
Zed mediumAdeptZed grew out of Xray, the experimental editor Nathan Sobo and Antonio worked on at GitHub in 2018, and this weekly update recaps the path from there to a company and a private alpha. It also describes the team's first "quality week" of bug fixing, which they plan to repeat every six weeks. Multibuffer performance in project-wide search got much faster after two fixes. Rope fingerprints, computed with the monoid-homomorphic bromberg_sl2 hash and aggregated through a B-tree, are now stored as HashMatrix values instead of allocated Strings. Excerpts are also built on a background thread and streamed into the multibuffer so the main thread no longer blocks.