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

Performance problem with pasting. fish_wcwidth at fault? #5866

Closed
7415963987456321 opened this issue May 9, 2019 · 4 comments
Closed

Performance problem with pasting. fish_wcwidth at fault? #5866

7415963987456321 opened this issue May 9, 2019 · 4 comments
Labels
performance
Milestone

Comments

@7415963987456321
Copy link

@7415963987456321 7415963987456321 commented May 9, 2019

I've seem to run into a performance problem with fish shell upon pasting a large amount of text.

Steps to reproduce: Copy about a pages worth of dmesg output, paste into terminal a couple of times, shell turns to a grinding halt, unable to CTRL+C while text is being pasted and sometimes afterwards I am also unable to escape.

I've investigated with perf and found the following results: https://paste.sr.ht/%7Ekeli/c99256cfc926a7f7d7b6aa869c6884c94f2403c1

I can supply the entire perf record file if needed.

Perf reports that fish_wcwidth is using about half the cpu-time, this is evident when looking at htop while the text is being pasted, the cpu tends to go to 100%.

Fish version: 3.0.2
Terminal emulator: Alacritty 0.3.2
Kernel 5.0.13-arch1-1-ARCH

@faho
Copy link
Member

@faho faho commented May 9, 2019

fish_wcwidth at fault?

No. That's like asking "numbers are getting big. Is addition at fault?".

fish_wcwidth is a low-level function that we need to figure out how wide a string is.

Terminal paste is really quite crappy, as it just inserts one character at a time, as if you've pressed them, so we redo the highlighting after every character. If you enter them manually, that's not an issue, as you can't press the keys fast enough. But if you paste a bunch, it is.

Now, there is "bracketed paste", which most terminals support. That sends a sequence when a paste begins, and another when it ends, so we can distinguish between pasting and entering text manually (which is important so that e.g. pasted text doesn't automatically execute). We already support that, but we don't hook into the highlighter to disable it. I'm inclined to just disable the highlighter if the binding system is in "paste" mode.

For now, instead of using your terminal's crappy paste, use our fish_clipboard_paste function, bound to ctrl-v by default, which will use e.g. xsel or pbpaste to paste text without those caveats.

@7415963987456321
Copy link
Author

@7415963987456321 7415963987456321 commented May 10, 2019

This does not seem to happen with a bash shell though. Can't really use xsel since I'm on wayland, this can perhaps be configured in the fish config?

@faho
Copy link
Member

@faho faho commented May 10, 2019

This does not seem to happen with a bash shell though

Yes, because bash doesn't do highlighting or suggestions or... in fact, in a very real sense bash doesn't handle output at all. It leaves displaying the characters you entered to the terminal - try stty -echo in bash.

Can't really use xsel since I'm on wayland

I'm pretty sure you actually can, because xwayland.

But anyway, good news: It also supports wl-paste (in the next release)!

this can perhaps be configured in the fish config?

It's a function. See type fish_clipboard_paste. If you wish to change it, do it. funced and funcsave might be useful.

@faho
Copy link
Member

@faho faho commented May 11, 2019

No, that didn't really fix it (though it did improve the situation). The next PR will.

@faho faho reopened this May 11, 2019
faho added a commit to faho/fish-shell that referenced this issue May 11, 2019
This adds a new pair of bind functions {en,dis}able-highlighting, that
en/dis-able highlighting, respectively.

We use these to turn off highlighting when we start bracketed paste,
and we turn it on again when we stop it.

This is by far the simplest solution to the issue of bracketed paste
being slow.

Fixes fish-shell#5866.
@zanchey zanchey added the performance label May 12, 2019
@zanchey zanchey added this to the fish 3.1.0 milestone May 12, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
performance
Projects
None yet
Development

No branches or pull requests

3 participants