Skip to content

perf: add DrawOver and HardScroll for incremental scroll rendering - #130

Open
luispabon wants to merge 2 commits into
charmbracelet:mainfrom
luispabon:perf/scroll-optimization-clean
Open

perf: add DrawOver and HardScroll for incremental scroll rendering#130
luispabon wants to merge 2 commits into
charmbracelet:mainfrom
luispabon:perf/scroll-optimization-clean

Conversation

@luispabon

Copy link
Copy Markdown

Closes #129

Summary

Adds two public APIs to support incremental scroll rendering in bubbletea v2:

  • StyledString.DrawOver(buf, area) — renders without pre-clearing, enabling
    touched-line tracking via SetCell equality check
  • TerminalRenderer.HardScroll(newbuf, n, top, bot) — directly emits terminal
    scroll sequences via existing scrolln and skips scrollOptimize on next Render

Changes

  • styled.go: new DrawOver method (mirrors Draw minus the clear loop)
  • styled_drawover_test.go: output equivalence + incremental touch tests
  • terminal_renderer.go: skipScrollOptim field + guard in Render()
  • terminal_renderer_hardscroll.go: public HardScroll method

Motivation

bubbletea v2's cursedRenderer scroll frames cost ~800µs vs v1's ~100µs. The
bottleneck is redundant work: full ANSI reparse + O(width×height) hashmap
re-detection of scrolls that the caller already knows about. These APIs let
the caller bypass both.

Companion bubbletea PR: charmbracelet/bubbletea#XX

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.15385% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.10%. Comparing base (6cf7526) to head (6721564).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
terminal_renderer_hardscroll.go 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #130      +/-   ##
==========================================
- Coverage   60.14%   60.10%   -0.04%     
==========================================
  Files          52       52              
  Lines        6696     6708      +12     
==========================================
+ Hits         4027     4032       +5     
- Misses       2393     2400       +7     
  Partials      276      276              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

luispabon added 2 commits July 3, 2026 10:20
DrawOver renders content without pre-clearing the area, allowing
SetCell's equality check to mark only genuinely-changed cells as
touched. Enables incremental cell buffer updates in bubbletea's
cursed_renderer for scroll-optimized rendering.
@luispabon
luispabon force-pushed the perf/scroll-optimization-clean branch from 6721564 to cb3b3a9 Compare July 3, 2026 09:23
@luispabon

Copy link
Copy Markdown
Author

Rebased

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.

perf: add DrawOver and HardScroll for incremental scroll rendering

1 participant