bi-04 step 02 — Dirty marking and queued observation
Goal
Discover, by building it, why mutation records rather than recomputes — and why observers are batched.
Tasks
- Dirty marking. Mutations mark nodes; nothing is recomputed until an explicit
flush(). - Two implementations. Build naive (recompute everything on flush) and scoped (recompute only marked subtrees). Measure both on a 10,000-node tree and record operations/second.
- Find the crossover. At what tree size and what mutation rate does scoped invalidation start winning? Explain the shape of the curve, not just the numbers.
- A
MutationObserver-alike with microtask-queued delivery. Then deliberately make delivery synchronous and construct a case where a callback observes a half-built tree. - Observer storm. Write an observer that mutates in response to mutations. Predict the outcome before running: infinite loop, or something subtler? Explain via the microtask checkpoint.
Done when
- Ops/sec table for naive vs scoped, with the crossover identified
- Synchronous-delivery bug reproduced and explained
- You can state the requirement that forces queuing, in one sentence