Skip to content

Speed up cursor column calculation in the status bar for long lines - #753

Open
KAMI911 wants to merge 1 commit into
linuxmint:masterfrom
KAMI911:perf/cursor-position-status-bar
Open

Speed up cursor column calculation in the status bar for long lines#753
KAMI911 wants to merge 1 commit into
linuxmint:masterfrom
KAMI911:perf/cursor-position-status-bar

Conversation

@KAMI911

@KAMI911 KAMI911 commented Aug 22, 2026

Copy link
Copy Markdown

The status bar position indicator computed the column number by stepping through a GtkTextIter one character at a time from the start of the current line to the cursor, calling gtk_text_iter_get_char and gtk_text_iter_forward_char in a loop. This function runs on essentially every cursor movement, including while typing, so on a very long line, such as a minified script or a large single-line JSON file, it added a noticeable delay on each keystroke because the cost scaled with the cursor's column position. The loop now fetches the text between the start of the line and the cursor with a single gtk_text_iter_get_slice call and walks the resulting plain UTF-8 string instead, which avoids the repeated iterator validation and buffer lookups of the old approach while producing the exact same column number, including the same tab-expansion handling.

The status bar position indicator computed the column number by stepping through a GtkTextIter one character at a time from the start of the current line to the cursor, calling gtk_text_iter_get_char and gtk_text_iter_forward_char in a loop. This function runs on essentially every cursor movement, including while typing, so on a very long line, such as a minified script or a large single-line JSON file, it added a noticeable delay on each keystroke because the cost scaled with the cursor's column position. The loop now fetches the text between the start of the line and the cursor with a single gtk_text_iter_get_slice call and walks the resulting plain UTF-8 string instead, which avoids the repeated iterator validation and buffer lookups of the old approach while producing the exact same column number, including the same tab-expansion handling.
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.

1 participant