Skip to content

Commit 273a3b3

Browse files
committed
md: skip set_live/request_finalize/auto_fold on sizes-unchanged frame
1 parent b9c91fe commit 273a3b3

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

src/runtime/view/thread/turn/turn.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,20 @@ maya::Element cached_markdown_for(const Message& msg, const Model& m) {
284284
// finish() (which forces live_=false) until that ramp completes,
285285
// so the reveal animation isn't cut short and dump its backlog
286286
// in one frame.
287-
if (settled) {
288-
cache.streaming->request_finalize(200);
289-
} else {
290-
cache.streaming->set_live(true);
287+
//
288+
// Skip on a sizes-unchanged frame. set_live(true) goes through
289+
// the Tracked<> wrapper which auto-bumps build_dirty_ on EVERY
290+
// assignment (even same-value): a wasted rebuild per frame at 60
291+
// fps. request_finalize is idempotent (early-out on existing
292+
// deadline) but cheap to skip. With this gate, no-grow frames
293+
// leave build_dirty_ alone and build() returns cached_build_
294+
// directly.
295+
if (!sizes_unchanged) {
296+
if (settled) {
297+
cache.streaming->request_finalize(200);
298+
} else {
299+
cache.streaming->set_live(true);
300+
}
291301
}
292302

293303
// Auto-fold code blocks longer than ~40 lines so a wall of code
@@ -312,10 +322,19 @@ maya::Element cached_markdown_for(const Message& msg, const Model& m) {
312322
// frozen.cpp's prose_rows mirrors this fold so the row estimate
313323
// agrees across the freeze. Respects an explicit user unfold
314324
// (entry stored as `false`) and won't re-fold.
315-
constexpr std::uint16_t kFoldLineThreshold = 40;
316-
constexpr std::uint32_t kFoldKinds =
317-
(1u << static_cast<unsigned>(maya::StreamingMarkdown::BlockKind::CodeBlock));
318-
cache.streaming->auto_fold_long_blocks(kFoldLineThreshold, kFoldKinds);
325+
//
326+
// Skipped on a sizes-unchanged frame: no new bytes → no new
327+
// committed block can have appeared → nothing to fold. The
328+
// function would walk prefix_->metas (O(committed blocks),
329+
// dozens to hundreds on a long body) and hit the
330+
// `folds_.contains(source_offset)` early-out on every entry.
331+
// Cheap absolutely, but pure waste on the dominant no-grow frame.
332+
if (!sizes_unchanged) {
333+
constexpr std::uint16_t kFoldLineThreshold = 40;
334+
constexpr std::uint32_t kFoldKinds =
335+
(1u << static_cast<unsigned>(maya::StreamingMarkdown::BlockKind::CodeBlock));
336+
cache.streaming->auto_fold_long_blocks(kFoldLineThreshold, kFoldKinds);
337+
}
319338

320339
if (settled
321340
&& cache.revealed_size == source.size()

0 commit comments

Comments
 (0)