A deep dive into optimizing a browser-based spreadsheet engine by reducing the fixed cost of cell recalculation. The bottleneck was a method called `_makeCalcCellEvaluationContext` consuming 12.5% of recalculation time by eagerly constructing a large evaluation context object for every cell. The fix involved two techniques: switching eager property computation to lazy getters, and replacing per-cell object creation with a single shared immutable context object (via a new `CellEvaluator` class) whose dynamic parts are updated by mutating private properties. This eliminated repeated object spreading and reduced garbage collector pressure. The result was a ~10% median performance improvement across real-world spreadsheet documents, validated by a dedicated performance and regression testing suite.

8m read timeFrom alexharri.com
Post cover image
Table of contents
GRID’s Spreadsheet EngineThe cost of recalculationEvaluating the fixed costEliminating the fixed costEvaluating the impactConclusion

Sort: