Skip to content

perf(surface): batch immutable text writes - #91

Open
ben-ranford wants to merge 3 commits into
bug/44-wide-cell-edgefrom
feat/61-batch-surface-text
Open

ben-ranford wants to merge 3 commits into
bug/44-wide-cell-edgefrom
feat/61-batch-surface-text

Conversation

@ben-ranford

Copy link
Copy Markdown
Owner

Summary

Closes #61.

Surface.WithText previously cloned and finalized the full immutable surface for every grapheme cluster. It now creates one seeded Builder over a single clone, uses the same normalized cluster traversal as Builder.WithText, and finalizes once. The seeded indexes retain the existing first-match style and link IDs, including surfaces reconstructed from a patch with duplicate interned entries.

The regression coverage compares the immutable and seeded Builder results across tabs, clipping, wide graphemes, links, and successive style writes; confirms input immutability and diff/patch round trips; and constrains the allocation envelope. On the checked workload, immutable WithText uses 16 allocations and the Builder uses 15.

Scope firewall

A review item is in scope only when it directly prevents #61 acceptance and is an incremental correction in surface/surface.go or surface/surface_test.go. Sharing a file or a rendering concern is not sufficient.

Validation

  • go test ./surface -run 'TestWithText' -count=1 -v
  • go test -race ./surface -run 'TestWithText' -count=1
  • go test ./surface -count=1
  • git diff --check
  • make ci → exit 0 (captured in /tmp/stave-61-make-ci-final.log and /tmp/stave-61-make-ci-final.exit)

Release Notes

Improves the allocation behavior of immutable Surface.WithText without changing its public signature or rendering semantics.

@ben-ranford ben-ranford added area:rendering Capabilities, colour, themes, layout, surfaces, and renderers type:refactor Behavior-preserving restructuring or measured performance refactor labels Sep 13, 2026
@ben-ranford ben-ranford self-assigned this Sep 13, 2026
@ben-ranford ben-ranford added the priority:p1 Foundational or high-impact milestone work label Sep 13, 2026
@ben-ranford ben-ranford added this to the v1.1.0 milestone Sep 13, 2026
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 12:17
@ben-ranford
ben-ranford requested a lite review from Copilot September 13, 2026 12:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-13T13:40:52.184218Z 42da3a2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3844e48ca2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread surface/surface.go
Comment thread surface/surface.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved moderate issues remain in zero-size handling and regression-test coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Batches immutable Surface.WithText updates through a seeded Builder to reduce allocations while preserving rendering and interning behavior.

Changes:

  • Shares normalized text traversal between immutable and Builder paths.
  • Seeds existing style and link indexes.
  • Adds parity, immutability, allocation, and patch-roundtrip tests.
File summaries
File Description
surface/surface.go Implements batched immutable text writes.
surface/surface_test.go Adds regression and allocation coverage.
Review details

Suppressed comments (1)

surface/surface_test.go:126

  • This snapshot is only a shallow copy, so before shares the cells, styles, and links backing arrays with base. A regression that mutates the input in place would mutate both values and still pass this immutability assertion; take a deep snapshot before invoking WithText so the acceptance check can detect that failure.
	before := base
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread surface/surface.go Outdated
Comment thread surface/surface_test.go Outdated
@ben-ranford
ben-ranford requested a lite review from Copilot September 13, 2026 13:38
@ben-ranford
ben-ranford marked this pull request as draft September 13, 2026 13:38
@ben-ranford
ben-ranford marked this pull request as ready for review September 13, 2026 13:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:rendering Capabilities, colour, themes, layout, surfaces, and renderers priority:p1 Foundational or high-impact milestone work type:refactor Behavior-preserving restructuring or measured performance refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants