Skip to content

⚡ Bolt: single-scalar fast path + O(log n) range lookups in world-surface - #10468

Merged
dezren39 merged 2 commits into
mainfrom
perf/bolt-world-surface-single-scalar
Nov 17, 2026
Merged

dezren39 merged 2 commits into
mainfrom
perf/bolt-world-surface-single-scalar

Conversation

@dezren39

@dezren39 dezren39 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

💡 What

renderWorldSurface in pkgs/id/web/src/world-surface.ts is the hot path for every world screen frame (up to 6000 cells). Two changes:

  1. Single-scalar fast path. The previous optimization only fast-pathed printable ASCII (U+0020..U+007E). Every other single Unicode scalar value (box-drawing borders, accented Latin, CJK, emoji, Greek, Cyrillic, …) still paid Intl.Segmenter.segment() (~3 µs/cell) plus per-cell Array.from/map/reduce allocations. A single scalar value is always exactly one grapheme cluster (verified exhaustively over U+0000..U+10FFFF against Intl.Segmenter), so all of them now skip segmentation and compute their width directly via codePointWidth. U+200D is deliberately kept on the general path because its graphemeWidth shortcut diverges from codePointWidth.
  2. O(log n) range lookups. isWideCodePoint, isTextPresentationCodePoint and isEmojiPresentationSeqBase scanned their 80–180 entry tables linearly with .some(), once per non-ASCII cell. The tables are now flattened into Int32Arrays and queried with binary search (all three tables verified sorted and disjoint).

🎯 Why

A 120×50 frame of box-drawing glyphs took ~52 ms of CPU (≈8.6 µs/cell) instead of ~2 ms, because each cell paid the full linear scan and a full Intl.Segmenter segmentation. That breaks the 20 fps (50 ms/frame) budget for any non-ASCII world.

📊 Impact

Measured in Bun/JSC with document.createElement stubbed (per .jules/bolt.md, happy-dom element creation dominates and hides the renderer's own CPU), full 6000-cell frame:

workload before after speedup
box-drawing (─) 51.9 ms 2.1 ms ~25×
emoji (😀) 27.3 ms 1.2 ms ~23×
latin1 (é) 20.5 ms 0.8 ms ~26×

The DOM/element-creation cost is unchanged.

🔬 Measurement

  • bun run typecheck (tsc) — clean.
  • bun run test (vitest) — 828 tests pass, 9 skipped.
  • Exhaustive equivalence check over U+0000..U+10FFFF: single-scalar fast-path width matches the general path for every scalar except the excluded U+200D; binary-search predicate results match the linear scans for every code point.
  • The shared screen-cell-parity.json Rust/TS corpus continues to pass on both sides.

🔗 References


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…face

Extend the ASCII-only fast path in renderWorldSurface to every single
Unicode scalar value (box-drawing, accented Latin, CJK, emoji, ...) and
replace the three linear .some() scans over the wide/text-presentation/
emoji-presentation range tables with binary search over flattened
Int32Arrays.

A single scalar is always exactly one grapheme cluster (verified
exhaustively over U+0000..U+10FFFF against Intl.Segmenter), so it skips
Intl.Segmenter (~3 us/cell) and the per-cell Array.from/map/reduce
allocations. U+200D stays on the general path because its graphemeWidth
shortcut diverges from codePointWidth.

Measured in Bun/JSC with document.createElement stubbed (per .jules/bolt.md
guidance), a full 120x50 frame:
  box-drawing: 51.9 ms -> 2.1 ms  (~25x)
  emoji:       27.3 ms -> 1.2 ms  (~23x)
  latin1:      20.5 ms -> 0.8 ms
All 828 web tests pass; typecheck clean.
@dezren39
dezren39 requested a review from a team as a code owner November 15, 2026 09:05
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T09:05:18.727230Z
We couldn’t complete this review. Comment @codex review to try again.
9bc5717 PR opened
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8258d856-ceb0-4b8a-a94e-7bff4a04c13a
Commits

Reviewing files that changed from the base of the PR and between 18c8b74 and 125fe45.

Files selected for processing: 2

  • .jules/bolt.md
  • pkgs/id/web/src/world-surface.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

# Conflicts:
#	.jules/bolt.md
#	pkgs/id/web/src/world-surface.ts
@dezren39
dezren39 merged commit fb9abc5 into main Nov 17, 2026
1 check passed
@dezren39
dezren39 deleted the perf/bolt-world-surface-single-scalar branch November 17, 2026 01:06
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.

2 participants