Summary by TwinMind · 37m 16s

Summary by TwinMind · 37m 16s

React's Magic Compiler You Can't Use (Yet)

React's Magic Compiler You Can't Use (Yet)

Theo - t3․gg

Theo - t3․gg

React Forget Background & Original Promise (2021)

  • Announced December 2021 at React Conf - over 2 years ago
  • Original developer (Jean) left Meta, causing concern about project abandonment
  • Core problem: React aggressively re-renders components when parent changes
    • All todo items re-render when adding/toggling one item
    • Virtual DOM validation overhead on every render
    • Manual memoization required to opt out
  • Complex memoization makes code harder to read, maintain
    • Arrows showing dependencies create visual complexity
    • Loses React's simple top-to-bottom readability
    • Developer experience vs performance tradeoff

React Forget Vision & Technical Approach

  • Goal: Write simple React code without manual memoization while achieving optimal performance
  • Compiler automatically memorizes components and hooks at build time
  • Uses memo cache with dependency tracking
    • Each value gets cache key
    • Falls back to cached value when dependencies unchanged
    • Automatic dependency detection via JavaScript analysis
  • Preserves original code structure inside memoization blocks
  • More efficient than manual useMemo - avoids function expressions, dynamic arrays

Production Implementation Timeline

  • Solid foundation established by early 2023
  • 8 months ago (March 2023): began production experiments
  • Over 500 tests covering JavaScript edge cases
  • Currently running on 2 major Meta products

Quest Store VR Implementation

  • First production deployment on Quest Store (React Native VR app)
  • Store already hand-optimized by engineers using useMemo/useCallback
  • Cautious rollout: every test ran twice (with/without Forget)
  • Product Details page fully compiled by Forget
  • React Profiler comparison showed dramatic reduction in re-rendered components
    • Over 50% fewer green boxes (rendered components)
    • Significant performance improvement over hand-optimized code
  • Improved interaction responsiveness and faster visual completion metrics

Instagram Web Implementation

  • Instagram.com confirmed as React app
  • Forget deployed on pages like profile in production
  • Performance metrics:
    • Less than 1% increase in compressed code size
    • No meaningful memory usage change
    • No increase in memory crashes or startup time
    • Slight improvements in visual completion
  • 95% of Instagram components understood by compiler
  • Zero product code changes required - pure compiler transformation

Current Status & Release Timeline

  • Stage: Small number of products with feedback/iteration
  • Next: Scale up to all Meta products
  • Final: Public release after stress testing
  • High confidence in major design decisions
  • Still refining small details based on production data
  • 2024 potentially last year requiring manual memos in React

Technical Implementation Details

  • Internal compiler playground for development
  • $-prefixed variables for memo cache operations
  • Source maps preserve debugging locations
  • Handles complex dependency chains automatically
  • Memorizes JSX elements themselves for react.memo-like behavior
  • Static JavaScript code generation for JS engine optimization