Part VI — The Blueprint · Lesson 11.12
HLD – Google Sheets
In one lineA virtualized grid over a dependency graph — render what's visible, recalculate only what changed.
Where you've seen itTyping a number into A1 and having exactly the cells that reference it update, instantly, in a sheet with a million rows.
Diagram
| Step 1–2 | Scope and scale |
|---|---|
| In scope | grid · editing · formulas · scroll · selection · collab |
| Out of scope | charts · pivot tables · apps script · import/export |
| Scale | up to 10M cells · 1M rows × 26 cols visible-addressable · only ~1,000 cells on screen at any moment |
Lessons in this diagram10.7 Infinite Scroll
6b · DEEP DIVE — KEEPING EDITS AT 60fps
parse formula once → AST, cached per cell
recalc in a Web Worker when the dirty set is large (5.1)
batch renders: one paint per frame, not per recalculated cell
canvas rendering for the grid body if DOM cells prove too slow
virtualize selection: a 10,000-cell range is a rectangle,
not 10,000 selected elementsHow it works
- Sparse storage: a map keyed by
"R3C7", so empty cells cost nothing. - Virtualize both axes, with frozen headers rendered as separate panes.
- Build a dependency graph as formulas are parsed; edits walk reverse edges and recalculate topologically.
- Detect cycles at parse time and report
#CIRCULAR!rather than hanging. - Collaborate per cell — unlike prose (11.11), cells are independent, so per-cell last-write-wins is usually acceptable.
Trade-offs
| Choice | Cost |
|---|---|
| DOM cells | Easy styling and a11y; slower past a few thousand |
| Canvas grid | Fast at any size; you rebuild a11y and editing |
| Full recalc | Trivial to write; unusable at scale |
| DAG recalc | Fast and correct; graph maintenance complexity |
Interview angle
"How do you recalculate a sheet with 10 million cells?"
- You don't recalculate the sheet — you recalculate the dependents of the edited cell, found via reverse edges in a DAG and ordered topologically.
- Detect cycles at parse time so a circular reference errors instead of hanging the tab.
- If the dirty set is large, run recalculation in a Web Worker and batch one repaint per frame so typing stays responsive.
Recap
- Virtualize both axes; only ~1,000 cells ever exist in the DOM.
- The dependency DAG is what makes editing fast — recalc the dependents, not the sheet.
- Cells are independent, so collaboration is far simpler here than in a document.