Spaceship-prompt: Use zsh-async to speed-up rendering the prompt

Created on 12 Jan 2018  路  13Comments  路  Source: denysdovhan/spaceship-prompt

This has been mentioned in #200 as optional, but wasn't implemented, thus creating a tracking ticket that I can subscribe to 馃檪


Let's use zsh-async to speed-up rendering the prompt. My personal favorite is the git_status section (because I saw pure theme do that), but I'm sure many other sections will benefit from this too.

/cc @sei40kr

has-pr help-wanted proposal

Most helpful comment

I have not so much time too, so it was difficult for me to implement it, sorry.

I created a PR including async jobs using mafredri/zsh-async, but it's still very WIP.
https://github.com/denysdovhan/spaceship-zsh-theme/pull/315

Perhaps it's necessary to change the way to render sections, to render them partially.

All 13 comments

Would be great to make this happened. I've been working on this. This was too hard to implement, so we've decided to release 3.0 without async rendering. Possibly, we can render all of the sections asynchronously by default (and also provide API for rendering section synchronously if needed).

Any help on this appreciated 馃檹馃徎

I would almost recommend against zsh-async without a fallback, as it causes random issues on systems where zpty doesn't work properly (cygwin https://github.com/sorin-ionescu/prezto/issues/1493 and Windows Subsystem for Linux https://github.com/sorin-ionescu/prezto/issues/1523 are the two I know of). Maybe pure handles it differently - I'll have to check on that.

Thanks for the insight, definitely something to consider 馃憤

I've just tried out pure theme out of curiosity, async git status is a very very cool experience! You can even make an artificial delay to git to amplify the difference:

# which git
/usr/bin/git
# cd /usr/bin
# mv git g
# echo '#!/usr/bin/env sh\n\nsleep 1\n/usr/bin/g "$@"' > git
# chmod +x git
...
# rm git
# mv g git

The difference is enormous, while spaceship is lagging as hell, pure is still instant, git status icons are slowly being rendered but that doesn't block me from changing directories, typing commands, etc.

Of course in real life the difference is not that big (unless you have some really big git repositories), but the improvement would not be negligible.

It is also possible to use some form of async without using zsh-async.

Pre-async we did something like this: https://github.com/sorin-ionescu/prezto/blob/9f1a41de9015e89c5553289173e2e1a7e5a0b35d/modules/prompt/functions/prompt_sorin_setup (Note that this approach has a number of downsides - specifically, we didn't do a good job of sanitizing the data, though it should be possible to use a similar approach without introducing vulnerabilities)

This is what it looks like post-async: https://github.com/sorin-ionescu/prezto/blob/ad79f78fbe143e38be421733713e562eccca018b/modules/prompt/functions/prompt_sorin_setup

spaceship is lagging as hell,

馃槥馃様馃檨

That's why I'm interested in making Spaceship async. Definitely, we should define a new roadmap for 4.0 to make section's rendering asynchronous.

I have not so much time too, so it was difficult for me to implement it, sorry.

I created a PR including async jobs using mafredri/zsh-async, but it's still very WIP.
https://github.com/denysdovhan/spaceship-zsh-theme/pull/315

Perhaps it's necessary to change the way to render sections, to render them partially.

These are what we need to implement.

  • Update installer to install zsh-async.
  • New prompt rendering (gets section info from global vars instead of running commands and just show them)
  • Manage cache (most of previous sections are reusable on same directory unless user command handles Git)
  • Manage jobs (currently force to flush all jobs on preexec, but it doesn't need to be terminated unless it conflicts with user commands)

@sei40kr any updates on this?

Let me know if you need a beta tester. :)

@cyrinux was a beta tester for my own implementation of async spaceship, right now there are no more known bugs so I consider it pretty stable. I made async only those sections that I personally use, but the framework is in place so it's trivial to convert more sections. Feel free to try it out if you are interested, but keep in mind that this is my fork that is made only for me, so it has breaking changes comparing to upstream (I listed them on top of the README).

If you want to convert more sections, here's how to do this and I will accept the PRs, because sooner or later I hope we will integrate the async implementation back into the original project.

Hi,
I confirm async implementation of @maximbaz is very cool and with no bug for me right now ;)

I'm fighting async prompt on Windows / MSYS2 right now so wanted to post a nice link that I found related to this: https://github.com/agkozak/agkozak-zsh-theme#asynchronous-methods.

Note that I'm not a user of Spaceship, this just came up in Google results. (I'm keeping an eye on Spaceship long-term though ;) )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

salmanulfarzy picture salmanulfarzy  路  3Comments

gabrielpedepera picture gabrielpedepera  路  3Comments

janjur picture janjur  路  3Comments

conradwt picture conradwt  路  3Comments

maccius picture maccius  路  3Comments