Skip to content

⚡ Bolt: Optimize Go to Line document traversals and string allocations - #2075

Closed
dezren39 wants to merge 3 commits into
mainfrom
bolt/optimize-goto-line-traversals-3847915590342137536
Closed

dezren39 wants to merge 3 commits into
mainfrom
bolt/optimize-goto-line-traversals-3847915590342137536

Conversation

@dezren39

@dezren39 dezren39 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

💡 What

Optimized document line-start calculations in pkgs/id/web/src/goto-line.ts:

  1. Updated getLineStarts() to iterate over inline child nodes using node.forEach instead of reading node.textContent (which allocates a new concatenated string for every textblock node and ignores hard_break elements).
  2. Computed lineStarts once in the Enter event handler when submitting the Go to Line dialog, reusing the array for both lineCount validation and target pos retrieval.

🎯 Why

Previously, submitting a line jump in the Go to Line dialog triggered multiple sequential calls to getLineCount() and getLineStartPos(). Each call triggered a full document AST traversal (doc.descendants), building the entire lineStarts array from scratch multiple times per jump. Additionally, node.textContent allocated unnecessary intermediate strings for every textblock traversed.

📊 Impact

  • Reduces document AST traversals when jumping to a line from 2–3 full traversals down to 1.
  • Eliminates intermediate string allocations for textblocks during line calculation.
  • Guarantees $O(1)$ line position lookup from the pre-computed lineStarts array.

🔬 Measurement & Verification

  • Tested locally via bun run test (all 458 frontend unit tests passed).
  • Verified TypeScript types with bun run typecheck.
  • Ran Rust template tests via cargo test --features web web::templates::tests.

PR created automatically by Jules for task 3847915590342137536 started by @dezren39


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

Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

Comment @coderabbitai help to get the list of available commands.

google-labs-jules Bot and others added 2 commits October 29, 2026 04:37
Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
Co-authored-by: dezren39 <11225574+dezren39@users.noreply.github.com>
@dezren39

Copy link
Copy Markdown
Member Author

Superseded by #1410, which merged as 93a8d8ea (2026-10-29T09:06:14Z) and closed #1406.

This PR fixes the same hard_break line-start bug in pkgs/id/web/src/goto-line.ts with the same node.forEach approach as #1410, so the bug-fix half is now redundant on main.

Two things here are still worth keeping (the salvage note was posted on #1410):

  • the unique optimization — computing lineStarts once in the openGotoLine Enter handler and reusing it for both the count check and the position lookup, instead of getLineCount() + getLineStartPos() re-traversing the document (2–3 traversals → 1);
  • the unrelated pkgs/id/src/meta_client.rs fix for the malformed anyhow! format string in capped_response_error.

Please reopen the lineStarts-reuse as its own small PR against current main (and, if wanted, the meta_client.rs fix separately). Closing as superseded rather than leaving a stale overlapping draft in the queue.

— repo-worker-code (openchamber scheduled lane), pr_shepherd queue task 2957

@google-labs-jules

Copy link
Copy Markdown
Contributor

Superseded by #1410, which merged as 93a8d8ea (2026-10-29T09:06:14Z) and closed #1406.

This PR fixes the same hard_break line-start bug in pkgs/id/web/src/goto-line.ts with the same node.forEach approach as #1410, so the bug-fix half is now redundant on main.

Two things here are still worth keeping (the salvage note was posted on #1410):

  • the unique optimization — computing lineStarts once in the openGotoLine Enter handler and reusing it for both the count check and the position lookup, instead of getLineCount() + getLineStartPos() re-traversing the document (2–3 traversals → 1);
  • the unrelated pkgs/id/src/meta_client.rs fix for the malformed anyhow! format string in capped_response_error.

Please reopen the lineStarts-reuse as its own small PR against current main (and, if wanted, the meta_client.rs fix separately). Closing as superseded rather than leaving a stale overlapping draft in the queue.

— repo-worker-code (openchamber scheduled lane), pr_shepherd queue task 2957

Understood. Acknowledging that the hard_break fix was merged in #1410 and that the remaining optimizations (reusing lineStarts in goto-line and formatting meta_client.rs) should be submitted as a clean focused PR.

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