AI summary by TwinMind
I'm Gonna Try Zed Now (RIP VSCode)
Theo - t3․gg
13m 37s
Initial Performance Problem
- Theo made video about Zed VSCode killer, written in Rust, recently open sourced
- Zed scroll performance stuttery on Theo's computer despite 120Hz screen
- VSCode felt smoother than Zed during scrolling
- Assumed Mac-only editor would handle high refresh displays better
Direct Team Intervention
- Zed's 3 founders happened to be in SF that week
- Team reached out directly to Theo, came to his apartment
- Fixed scrolling issue on Theo's laptop in his kitchen
- Team published blog post about optimizations after visit
Technical Root Cause Analysis
- Enabled Metal HUD on Theo's M2 MacBook to investigate
- Key discovery: Zed running in direct mode on M2 vs composited mode on M1s
- Direct mode: writes directly to display's primary frame buffer
- Composited mode: writes to intermediate surfaces combined by Quartz compositor
- Direct mode triggered on M1s only when running full screen
- Counterintuitively, bypassing compositor made performance worse
Metal Pipeline Synchronization Issues
- Problem: logic in Metal renderer causing synchronization issues
- Default CA Metal layer presentation doesn't block OS window drawing
- OS interpolates previous frame contents by stretching until next frame ready
- Solution: enabled
presentsWithTransactionon CA Metal layer - Coordinated layer content presentation with Core Animation transaction
Thread Blocking Strategy
- Key fix: blocking main thread on
waitUntilCompletefor command buffer - Ensures frame completion before other background processes run
- Prevents window drawing until content presentation finished
- Counterintuitive but solved jitter by ensuring proper frame sequencing
Direct vs Composited Mode Bug
waitUntilCompleteworked in composited mode but not direct mode- In composited: completed = pixels written to intermediate buffer
- In direct: completed = pixels written to frame buffer on graphics card
- Direct mode blocking took much longer, reducing frame rate significantly
- Solution: switched to
waitUntilScheduledinstead ofwaitUntilComplete - Ensures content scheduled in sync while avoiding long blocking period
Memory Corruption Race Condition
- Antonio built binary on Theo's dining room table, airdropped for testing
- Multiple failed binaries before working solution
- Switching to
waitUntilScheduledintroduced race condition - GPU reading memory from frame N while Zed writing to same memory for next frame
- Like "vertical tearing but for memory"
Triple Buffering Implementation
- Replaced single instance buffer with pool of multiple instance buffers
- Acquire buffer from pool at frame start
- Release asynchronously once command buffer completed
- Buffer pool prevents memory race conditions
- Associate command buffer with completed handler returning buffer to pool
ProMotion Display Issues
- Scrolling smooth but cursor movement laggy
- Both had cursor repeat rates at 10ms
- Intermittent dropped frames in direct mode despite 4ms frame times
- Metal HUD didn't provide needed debugging info
- Timeline in Instruments revealed frames rendered under 4ms but not delivered at that rate
ProMotion Variable Refresh Rate Problem
- ProMotion modulates display refresh rate to save battery
- Variable 120Hz: adjusts based on application needs
- Can drop to 24Hz for 24fps video content
- Erroneously dropping frame rate when shouldn't
- Going from 120Hz to 30Hz creates visible jank
- Disabling ProMotion eliminated hitches
Display Link API Solution
- CA Display Link API synchronizes with display refresh rate
- Calls back each time display presents frame
- Discovery: consistent drawable presentation maintains constant frame rate
- Neglecting to draw frame causes refresh rate drop
- Solution: render repeated frames for 1 second after last input event
- Ensures maximum responsiveness during interaction
- Allows downclock after inactivity period for power saving
Platform Complexity Justification
- Demonstrates why Mac-only approach makes sense initially
- Getting performance right at this level nearly impossible
- Linux support would require similar effort for multiple rendering systems (Wayland, X server)
- Shows depth of optimization needed for quality software
- Windows/Linux support planned but requires similar intensive work
Results and Impact
- Significantly improved cursor movement at 10ms repeat rate
- Night and day difference in responsiveness
- Page up/down functions work as expected
- Cursor moves immediately without lag
- Team gained much deeper Graphics programming knowledge
