Skip to content

Conversation

@aymanbagabas
Copy link
Member

@aymanbagabas aymanbagabas commented Nov 3, 2025

On a large program, this can reduce repeated model render calls when the model is getting updated rapidly. This change makes the model stored as an atomic pointer for safe concurrent access between the event loop and the render loop.

The model is now stored internally as an atomic pointer, and updated after each event loop iteration. The render loop reads the latest model from the atomic pointer before rendering its View.

Benchmarks show a slight reduction in allocations for the TeaTest example.

goos: darwin
goarch: arm64
pkg: github.com/charmbracelet/bubbletea/v2
cpu: Apple M3 Max
          │   old.txt   │            new.txt            │
          │   sec/op    │   sec/op     vs base          │
TeaRun-16   321.2µ ± 3%   318.3µ ± 4%  ~ (p=0.247 n=10)

          │   old.txt    │            new.txt             │
          │     B/op     │     B/op      vs base          │
TeaRun-16   623.0Ki ± 0%   622.2Ki ± 0%  ~ (p=0.105 n=10)

          │   old.txt   │              new.txt               │
          │  allocs/op  │  allocs/op   vs base               │
TeaRun-16   1.837k ± 0%   1.828k ± 0%  -0.52% (p=0.000 n=10)

@aymanbagabas aymanbagabas marked this pull request as draft November 3, 2025 15:58
On a large program, this can reduce repeated model render calls when the
model is getting updated rapidly. This change makes the model stored as
an atomic pointer for safe concurrent access between the event loop and
the render loop.

The model is now stored internally as an atomic pointer, and updated
after each event loop iteration. The render loop reads the latest model
from the atomic pointer before rendering its View.
@aymanbagabas aymanbagabas marked this pull request as ready for review November 3, 2025 16:21
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.28%. Comparing base (4accb1c) to head (3734655).

Files with missing lines Patch % Lines
tea.go 64.28% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           v2-exp    #1532      +/-   ##
==========================================
+ Coverage   52.88%   53.28%   +0.40%     
==========================================
  Files          24       24              
  Lines        1180     1186       +6     
==========================================
+ Hits          624      632       +8     
+ Misses        477      475       -2     
  Partials       79       79              

☔ View full report in Codecov by Sentry.
📢 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.

@aymanbagabas
Copy link
Member Author

Actually, this might not be a good idea because it will significantly slow down since it synchronizes the event and render loop which we don't want here :/
Closing...

@aymanbagabas aymanbagabas deleted the v2-lazy-render branch November 3, 2025 17:50
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.

3 participants