React Compiler: Make AbstractValue Copy to reduce heap allocation
The Issue & Context
The React compiler's AbstractValue type was causing significant heap allocations and memory usage due to its reliance on an IndexSet structure, leading to larger memory footprint and slower compile times.
Root Cause Analysis
AbstractValue's use of IndexSet resulted in frequent heap allocations and a large memory size of 72 bytes plus additional allocations, causing inefficient memory usage and performance bottlenecks during compilation.
Solution Strategy & Architectural Pattern
The PR replaced the IndexSet with a simple inline array to replicate its behavior, reducing AbstractValue's size from 72 bytes to 18 bytes and eliminating heap allocations, which significantly decreased peak memory usage and improved compile times across multiple benchmarks.
Key Takeaway for Contributors
Optimizing internal data structures by minimizing heap allocations and reducing object size can lead to substantial performance improvements in compiler infrastructure, as demonstrated by the reduced memory and faster compile times in React's AbstractValue.