Skip to content

refactor: separate renderer initialization from resize - #164

Open
cowboyd wants to merge 1 commit into
mainfrom
refactor/native-renderer-lifecycle
Open

cowboyd wants to merge 1 commit into
mainfrom
refactor/native-renderer-lifecycle

Conversation

@cowboyd

@cowboyd cowboyd commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Why?

The context of this is that I spiked out a caching techique where as part of the ElementInfo returned for each element in a RenderResul it has not only the bounding box, but also a replay operation:

interface ElementInfo {
  bounds: BoundingBox;
  replay: Op;
}

This replay is an operation that is a drop in replacement for the list of ops that rendered the element in the first place. Internally, it is just a byte offset and length to operations in the last frame, so when tty sees it, it just copies those bytes directly from the last frame into the current one.

It performed 25% better than the snapshotting mechanism, and it means that every element that gets replayed takes up only 2 bytes in the transfer buffer.

But, as a result it requires that we not destroy that information on a resize which currently re-initializes the entire native renderer.

What

Split this into clayterm_init(), which initializes the instance once, and clayterm_resize(), which rebuilds cells, the output buffer, and Clay's arena while invalidating the old layout and diff state.

Capabilities and the emitted pointer shape now stay on the native instance across resizes. Remove the JavaScript save/restore bookkeeping and the unused native pointer-shape accessors. Regression coverage checks growth, shrink, and capability changes interleaved with resizing.

Based on main after #162 merged. This is an internal refactor preparing the renderer lifecycle for replay; no public API change or separate issue.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (deno task test: 29 suites, 387 steps)
  • Files are formatted (deno task fmt and deno task fmt:check)
  • I have added/updated tests for my changes
  • I have added a changeset (not applicable: internal refactor)

Also verified the WASM build, deno lint, deno task verify, and git diff --check.

AI-generated code disclosure

  • This PR includes AI-generated code

@bombshell-cooper

Copy link
Copy Markdown
Contributor

No changeset needed

This pull request is classified as no_release_impact: no published package

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tty@164

commit: e7f5b2b

@github-actions

Copy link
Copy Markdown

Size Reduced — -0.3 KB

129.2 KB unpacked

@cowboyd
cowboyd added this pull request to stack #165 October 23, 2026 14:26
Base automatically changed from cleanup/renderer-directive-constants to main October 23, 2026 19:16
@cowboyd
cowboyd force-pushed the refactor/native-renderer-lifecycle branch from 7460265 to e7f5b2b Compare October 23, 2026 19:25
@cowboyd cowboyd mentioned this pull request Oct 23, 2026
6 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant