perf(console): extend the filtered view incrementally

With any console filter on, each batch of new output rescanned all N
lines to rebuild the visible set. A text filter lowercase-copied the
needle and every line to test it: O(total characters) and 2N
allocations per batch.

When the filter is unchanged and the model only appended or evicted
lines since the last pass, the visible indices drop the evicted lines
and shift down, and only the new lines are tested. The result equals
a full rescan, since line text and channel never change and the
filtered view has no folds. A filter change, Clear, or a model window
that doesn't follow on from the last one still rescans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 09:50:03 -05:00
co-authored by Claude Opus 5.5
parent ee0a486676
commit 1ced49d622
5 changed files with 82 additions and 2 deletions
+7
View File
@@ -188,6 +188,13 @@ private:
bool folding_active_ = true; // fold UI shown only in the unfiltered (foldable) view
bool has_text_filter_ = false; // computed once per frame (before the toolbar draws it)
std::string filter_lower_; // lowercased filter needle for match highlighting
// Flat (filtered) view bookkeeping for the incremental computeVisibleLines path: the exact filter and the
// absolute model window [vis_flat_first_, vis_flat_end_) the current visible_indices_ were computed for.
bool vis_flat_valid_ = false;
int vis_flat_flags_ = 0;
std::string vis_flat_filter_;
std::uint64_t vis_flat_first_ = 0;
std::uint64_t vis_flat_end_ = 0;
// Memoization keys so the two expensive per-frame passes rebuild only on change (not every frame):
// computeVisibleLines (filter scan over the whole model) is keyed on the model revision + filter