perf(tui): ターミナルのリンク走査を出力フレームごとに1回へ集約#437
Merged
Merged
Conversation
出力が変化したフレームで `link_cells`(下線用セル)と `pr_links`/ `screen_urls`(PR URL 収集)が、それぞれ全グリッドを走査して同じ `url_spans` を二重に実行していた。レンダリングループがパーサのロックを 握っている最中の走査のため、リーダースレッドと競合する重い区間だった。 `link::scan_links` を追加し、論理行のフラット化と URL スパン検出を1パスに 統合してセル集合と URL 文字列の両方を返すようにした。`link_cells` / `screen_urls` はこの共通走査へ委譲し、`pr_links_from` で既知の URL から PR リンクを取り出せるようにして、pane の描画ループは1回の走査で両方を得る。 挙動は不変(既存テスト 2251 件が pass)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📊 Test Coverage
🎉✨ パーフェクト!全ファイル Lines カバレッジ 100% を達成しました 🏆🐰 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目的
埋め込みターミナルでエージェントが出力をストリームしている間の、レンダリングループのホットパス(パーサロック保持区間)のCPUとロック競合を削減する。
背景(性能レビューでの指摘)
出力が変化したフレーム(世代バンプごと・MIN_FRAME=16ms にスロットリング)で、グリッド全体を独立に複数回走査していた:
link::link_cells— 全論理行をフラット化し URL を検出(下線表示用のセル集合)link::pr_links→screen_urls— 別途もう一度全グリッドをフラット化しurl_spansを実行(PR URL 収集用)両者はほぼ同一の作業(同じ論理行に対する
url_spans)を共有せず二重実行していた。これはリーダースレッドが必要とするパーサロックを握ったまま走る最も忙しい区間。変更内容
link::scan_linksを追加。論理行のフラット化とurl_spans検出を1パスで行い、リンクセル(HashSet<Cell>)と URL 文字列(Vec<String>)の両方を返すScreenLinksを生成する。スクラッチバッファの再利用は従来どおり。link_cells/screen_urlsをこの共通走査への委譲に置き換え。pr_links_from(&[String])を追加し、既に走査済みの URL リストから PR リンクを取り出せるようにした(pr_linksも内部でこれを利用)。terminal/pane.rsの描画ループを、出力変化時にscan_linksを1回だけ呼び、その結果からリンクセルと PR リンクの両方を得る形へ変更。全グリッド走査が2回→1回になる。挙動は不変。
テスト・確認方法
cargo fmt/cargo clippy --all-targets -- -D warningsクリーン。cargo test全 2251 件 pass(link.rs の既存ユニットテストがscan_links/pr_links_fromを網羅)。