Skip to content

fix(renderer): debounce renders, refactor scroll logic, track scrollintent#280

Merged
sudo-tee merged 2 commits intosudo-tee:mainfrom
jensenojs:pr/renderer-scroll-intent
Feb 17, 2026
Merged

fix(renderer): debounce renders, refactor scroll logic, track scrollintent#280
sudo-tee merged 2 commits intosudo-tee:mainfrom
jensenojs:pr/renderer-scroll-intent

Conversation

@jensenojs
Copy link
Contributor

@jensenojs jensenojs commented Feb 14, 2026

  • Debounce renders: Fix edge case from persist_state benchmarking where rapid session switches trigger redundant renders (harmless in daily use, but a bug nonetheless)
  • Refactor scroll_to_bottom: nested if-else → condition table, just for code cleanliness
  • Add WinScrolled tracking: Capture scroll intent from mouse/trackpad scroll (not just keyboard navigation)

…intent

Three related improvements to output rendering:

1. Debounce concurrent render_full_session calls

   Problem: Rapid session switches trigger multiple redundant renders.
   Solution: Coalesce into one in-flight render + trailing render with
   latest options.

2. Refactor scroll_to_bottom conditions
   Convert nested if-else chain to declarative condition table for
   better readability and maintainability.

3. Add WinScrolled autocmd
   Track user scroll position to accurately detect scroll intent
   (whether user is at bottom or has scrolled up).
@jensenojs
Copy link
Contributor Author

These accumulated organically while building persist_state—fixing bugs, cleaning up code, adding small enhancements to get the experience right. Even with LLM assistance, splitting them now would be a headache. My apologies for the bundled review. @sudo-tee

@sudo-tee
Copy link
Owner

@jensenojs

The rendering debounce raises questions. Simply because the rendering is made in a way to not allow treesitter to constantly parse the buffer. Treesitter is parsing the buffer as soon as there is "time" between writes. By adding a debounce/schedule it will degrade the performace in a exponential way as the buffer grows.

It's best to remove this part.

@jensenojs
Copy link
Contributor Author

Removed the debounce logic from render_full_session as requested.

just clarify, your concern about treesitter performance (multiple parses) was actually unrelated to this mechanism—render_full_session only fetches session data, and buffer writes happen atomically in _render_full_session_data, so treesitter only parses once.

However, the deduplication assumed all calls were for the same session. If a user quickly switched sessions (A→B), it would return the previous session's (A) Promise, causing wrong data to render.

I checked my second implementation—now persist_state avoids re-fetching sessions when switching states, so removing this deduplication mechanism won't affect subsequent benchmarks (although my previous implementation would have caused memory spikes in this scenario, but that situation itself is uncommon)

Happy New Year by the way
@sudo-tee

@jensenojs jensenojs force-pushed the pr/renderer-scroll-intent branch from 5750eb0 to aebd461 Compare February 17, 2026 16:53
@sudo-tee
Copy link
Owner

Removed the debounce logic from render_full_session as requested.

just clarify, your concern about treesitter performance (multiple parses) was actually unrelated to this mechanism—render_full_session only fetches session data, and buffer writes happen atomically in _render_full_session_data, so treesitter only parses once.

However, the deduplication assumed all calls were for the same session. If a user quickly switched sessions (A→B), it would return the previous session's (A) Promise, causing wrong data to render.

I checked my second implementation—now persist_state avoids re-fetching sessions when switching states, so removing this deduplication mechanism won't affect subsequent benchmarks (although my previous implementation would have caused memory spikes in this scenario, but that situation itself is uncommon)

Happy New Year by the way @sudo-tee

Thanks for the clarification. Either way I prefer not to add complexity when it's not entirely needed.

I will do some tests for the tracking and scrolling behavior

@sudo-tee sudo-tee merged commit 6bfccb2 into sudo-tee:main Feb 17, 2026
5 checks passed
@jensenojs jensenojs deleted the pr/renderer-scroll-intent branch February 18, 2026 03:10
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.

2 participants