Skip to content

perf(tui): optimized extractCursorPosition to scan lines in reverse order#1004

Merged
badlogic merged 1 commit intobadlogic:mainfrom
can1357:main
Jan 28, 2026
Merged

perf(tui): optimized extractCursorPosition to scan lines in reverse order#1004
badlogic merged 1 commit intobadlogic:mainfrom
can1357:main

Conversation

@can1357
Copy link
Copy Markdown
Contributor

@can1357 can1357 commented Jan 28, 2026

Optimized extractCursorPosition to scan lines in reverse order for improved performance.

Turns out this is one of the slowest functions during a regular session.
image

Mostly because it scans from the head instead of the tail.

…rder

- Optimized extractCursorPosition to scan lines in reverse order for improved performance.
@badlogic badlogic merged commit a8f33fd into badlogic:main Jan 28, 2026
2 checks passed
@badlogic
Copy link
Copy Markdown
Owner

Embarassing. Cheers!

@badlogic
Copy link
Copy Markdown
Owner

This should also early out when above the visible viewport.

@badlogic
Copy link
Copy Markdown
Owner

9d47747f

@can1357
Copy link
Copy Markdown
Contributor Author

can1357 commented Jan 28, 2026

@badlogic shouldn't it be

const viewportTop = Math.max(0, lines.length - height);
for (let row = lines.length - 1; row >= viewportTop; row--) {

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