perf(tui): 描画フレーム構築の毎回ヒープ確保を削減する#267
Merged
Merged
Conversation
ホーム画面の毎描画で発生していた無駄なアロケーションを 2 か所削る。 - FramePainter::flush が毎フラッシュで base フレーム全体を clone していたのを、 使い回すスクラッチバッファへ clone_from して描画後に prev と swap する方式に変更。 定常的な再描画でフレームバッファのヒープ確保がゼロになる。 - render_frame のボディ行合成で、左右ペインを borrow して 1 行ごとに 2 回 clone し format! で新規 String を確保していたのを、所有 Vec を into_iter で消費して パディング済み左セルへ push_str する方式に変更。 いずれも出力バイト列・挙動は不変。 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.
目的
ホーム画面の毎描画(ライブセッション在席時は約 9fps で定常的に発生)で起きていた、フレームバッファの無駄なヒープ確保を削減する。描画結果・出力バイト列は不変の純粋な内部最適化。
変更内容
FramePainter::flush(screen.rs)self.base.clone()により全画面Vec<String>を新規確保していた。clone_from(行 String のアロケーションを再利用)してオーバーレイを合成し、描画後にprevとswapする方式に変更。prevは diff のベースとして無傷のまま使える。render_frameボディ行合成(home/ui/mod.rs).cloned()を 2 回 +format!で新規 String を確保していた。left/rightはこのループ以降で読まれないためinto_iterで消費し、パディング済み左セルの String にpush_strする方式に変更(1 行あたり clone 2 回と format! の確保を削減)。テスト・確認方法
cargo fmt/cargo clippy --all-targets -- -D warnings/cargo test(1463+ 件)すべてパス。diff_frame/FramePainterテストが出力不変を担保。🤖 Generated with Claude Code