-
Notifications
You must be signed in to change notification settings - Fork 2k
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 regression since 2.3.1 #3793
Comments
Are you running the terminal emulator on the Raspberry Pi or a different system? While possible it seems really unlikely that the |
I am experiencing this on my Intel Core i7 powered laptop when I put the CPU into a powersave mode:
Thus, my system configuration is:
However, @ycardon reported (oh-my-fish/theme-bobthefish#66) the same experience on his Raspberry Pi. |
Thanks for this investigation. How did you determine that the regression is in |
Using fish 2.3.1 the BobTheFish theme causes fish to consume 1.2% of a cpu while my normal prompt theme uses just 0.8% when backspacing over a long command. Using fish from git head the BobTheFish theme causes fish to consume 12% of a cpu when backspacing over a long command. My normal prompt theme uses only 3%. Using the macOS |
Any idea what it is about bobthefish that causes so many repaints? |
Bisected to commit f464704. |
I was dithering on whether to mark this a regression. Performance problems are often the result of adding functionality. Which is the case with this issue and doesn't automatically make the problem a regression in behavior. However, I think the change in behavior in this instance does not justify such a dramatic decrease in performance. Furthermore the original code was itself more expensive than it should have been given that it is called in a hot path for interactive use and performs avoidable computations. TBD is how best to fix this. Should we simply memoize the code that is causing the slow down? That would necessitate adding code elsewhere to invalidate the cached results when, for example, |
What exactly is causing the slowdown? I don't see anything obvious in that diff that would be responsible for a regression. |
It's the removal of the TBD is whether we should reinstate that limit, memoize the results, or otherwise improve the algorithm. |
Also, the |
I attached an instruments trace. I'm surprised, we really are spending over half our time in I see now that we have a nested loop. So 256 colors * 4 escape sequences is over a thousand checks, each of which do silly things like call sprintf(). It's easy to believe that that's expensive. Instrumenting this, this theme is indeed using a CSI-style One lazy thing we could do is to move the color checks after the mode checks. I also think this is a fine candidate for memoization as you suggested. |
In the meantime, is there something the theme could do to make things easier on |
Reducing the number of emitted escapes should help. I see that the theme has a lot of functions that end in |
Eases the pain of fish-shell/fish-shell#3793 just a bit. This _shouldn't_ ever look any different to the end user. I think.
Here is a GIF (1MB in size) showing my terminal experience and Also, I forgot to mention that I have custom keyboard sensitivity, this means that more "keypressed" events get fired than on the default settings and especially than on OS X. You may try my setting: |
Well, when can the cached results become invalid? The terminal isn't going to change out from under fish, so $TERM or terminfo (which should be rare enough that we can just ignore it and tell people to restart fish) otherwise changing seems, from my naive perspective, to be the only way to cause this. So yeah, this appears to be an obvious candidate for caching. |
We absolutely have to invalidate the cached data when any terminal related var changes. Fortunately I already added a hook for doing that because it is needed for other reasons; e.g., reinitializing the curses subsystem. See |
A funky idea that avoids needing a cache is to try escapes in MRU fashion. Make a big list of all the escapes we know about. When an escape is hit, splice it to the front of the list, so we try that one firs next time. Prompts tend to reuse the same escapes over and over, so this will mean we end up only testing a handful most of the time. |
Another really obvious and easy thing we ought to do is just cache the length of the prompt. If the output of the prompt doesn't change, then neither will its length. Maybe discard the cache after every command to handle changes in locale, etc. |
It is trivial, and probably common, to generate a new prompt having the same length as the previous prompt but different content including different coloring. Perhaps I misunderstood what you proposed, @ridiculousfish, but I don't see how keying on the prompt length will help. Also, a MRU implemented as a list will help a bit but is suboptimal. The list will be constantly updated as different colors and other effects are injected. It won't be a stable structure. Better to just use a map. After all, people aren't generally changing |
Sorry, to be clear, we cache the prompt and its length. Obviously if the prompt is different we discard the cache. The advantage of the MRU approach is that it avoids all invalidation issues. It doesn't remember any lengths, it just changes which escapes it tries first. |
Darn, I thought that commit could have trivial performance implications (and noted optimization may be desirable), but am surprised it was so significant. I didn't think very hard about it. |
The color indexes start at 0 and |
(Yes, I was.) |
@krader1961 I will check it later today. |
@krader1961 It works like a charm! |
sh -c 'env HOME=$(mktemp -d) fish'
)?fish version installed (
fish --version
):This performance drop started with 2.4.0, but I have also tried the master branch (6db3721) build today
OS/terminal used: Arch Linux, terminal doesn't make any difference (tried Gnome Terminal, XTerm, and TTY).
It seems that
set_color
became much slower in Fish 2.4.0. While it is not noticeable to high-end CPUs (yet 100% CPU load can be a good indicator of that something is wrong as typing a command shouldn't take so much of resources), ARM processors and even x86 processors in powersave mode reveal the noticeable lag in typing using a theme, which used to work just fine on Fish 2.3.1.Steps to reproduce:
bobthefish
themeThis bug is also filed against the bobthefish theme repository: oh-my-fish/theme-bobthefish#70. All other themes I tried work fine (yet, they still take 50+% CPU when I simply press and hold backspace key on an empty line), but this theme also works fine with Fish 2.3.1, and given the fact that my experiments ended up in
set_color
, I think it is worth taking a look here./cc @bobthecow @ycardon
The text was updated successfully, but these errors were encountered: