Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve long input performance #688

Merged
merged 2 commits into from Apr 24, 2024
Merged

Conversation

tompng
Copy link
Member

@tompng tompng commented Apr 24, 2024

When input line is very long, for example, after pasting [1,1,1,1,1,1,1,1,...(thousands of items)...,1,1,1] to IRB, Some cursor move operation and rendering is slow.

Performance of pasting long text will be improved in bracketed-paste #655.
This pull request improves performance of re-rendering long text.

Reproduce

$ ruby -e "print ([1]*4000).inspect" | pbcopy
$ irb
irb(main):001> [paste long input here]
...(wait a few seconds)
Press C-l to see rerender time (about 0.25s → about 0.01s)
Press C-a C-e to see ed_move_to_end time (about 10s → about 0.01s)

ed_move_to_end

I just forgot to erase the old while loop.

split_by_width

When the input is 1,1,1,1,1,1,1...., colorized code will be [BLUE]1[RESET],[BLUE]1[RESET],...
Reline::Unicode.split_by_width will split into

[
  "[BLUE]1[RESET],[BLUE]1[RESET],",
  "[BLUE][RESET][BLUE][RESET][BLUE]1[RESET],[BLUE]1[RESET],",
  "[BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE]1[RESET],[BLUE]1[RESET],",
  "[BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE][RESET][BLUE]1[RESET],[BLUE]1[RESET],"
]

This is because split_by_width does not understand actual CSI sequence and just concats it.
We can clear the concatenated sequences if the CSI is "\e[m" or "\e[0m" that resets color and text style.

@st0012 st0012 added the bug Something isn't working label Apr 24, 2024
@tompng tompng merged commit 0c8d3c8 into ruby:master Apr 24, 2024
40 checks passed
@tompng tompng deleted the long_line_performance branch April 24, 2024 17:33
matzbot pushed a commit to ruby/ruby that referenced this pull request Apr 24, 2024
(ruby/reline#688)

* Improve C-e (ed_move_to_end) performance for long line

* Reline::Unicode.split_by_width optimization for RESET_SGR

ruby/reline@0c8d3c827a
artur-intech pushed a commit to artur-intech/ruby that referenced this pull request Apr 26, 2024
(ruby/reline#688)

* Improve C-e (ed_move_to_end) performance for long line

* Reline::Unicode.split_by_width optimization for RESET_SGR

ruby/reline@0c8d3c827a
@st0012 st0012 changed the title Long line performance Improve long input performance Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

None yet

2 participants