Skip to content

Refit only the cells that can change - #15

Merged
vaprdev merged 4 commits into
mainfrom
dirty-cells
Oct 10, 2026
Merged

vaprdev merged 4 commits into
mainfrom
dirty-cells

Conversation

@vaprdev

@vaprdev vaprdev commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Summary

Most cells show the same thing frame after frame, yet every cell was refit every frame. Now the canvas records what each frame draws over the cached background, and the engine refits only the cells that can have changed and reuses last frame's fit for the rest.

Canvas
  restore(background?)    # copy the still frame back, clear touched
  touched: [x0,y0,x1,y1…] # every draw primitive and sky/weather helper adds its box; touch() for custom loops
  finish()                # static-bloom's blocks: re-bloom and tone-map only blocks under touched,
  changed: [x0,y0,x1,y1…] # and list the pixel runs that differ from last frame
engine paint()
  refit cells under changed (widened by the bloom radius) + text/scrim edits
  reuse the stored fit for every other cell
  quieten()               # unchanged; runs after both paths

This branch's own incremental finish() overlapped with static-bloom's; the merge keeps static-bloom's block bloom (its accuracy, and simpler) and feeds changed from it. bun dev/check.ts --verify-dirty plays every combination twice (full refit vs dirty refit, with text edits, redraws and agent events mixed in) and fails on any cell that differs.

Evidence

Engine + scene per frame, dev/check.ts tundra ocean city jungle (36 combinations), origin/main vs this branch, back to back twice: 8.9 → 6.1 ms/frame.

Left: the scene; right: cells refitted per frame (magenta).

dirty cells

Verified: typecheck, build, dev/check.ts --max-ms=60 in octant and quadrant mode (0 failed), --verify-dirty 90/90 bit-identical, screenshots up to date.

Merge Danger

Door: two-way

Blast Radius: every wallpaper; a scene that draws outside its touched boxes leaves stale cells until they change (--verify-dirty catches it). WALLPAPER_DIRTY=0 refits everything.

# Conflicts:
#	CONTRIBUTING.md
#	src/canvas.ts
#	src/engine.tsx
#	src/sky.ts
#	wallpapers/beach.ts
#	wallpapers/city.ts
#	wallpapers/desert.ts
#	wallpapers/farm.ts
#	wallpapers/jungle.ts
#	wallpapers/ocean.ts
#	wallpapers/prehistoric.ts
#	wallpapers/template.ts
#	wallpapers/tundra.ts
#	wallpapers/zen.ts
@vaprdev
vaprdev merged commit 4f947df into main Oct 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant