Use universal variables instead of temp files - #76
Conversation
| and cat $__async_prompt_tmpdir'/'$fish_pid'_'$func | ||
| if set -q $__async_prompt_var'_'$func | ||
| set -l result $__async_prompt_var'_'$func | ||
| echo -n $$result |
There was a problem hiding this comment.
I'm using starship and this causes the multiline prompts to merge into a single line.
I changed this to printf "%s\n" $$result and seems to work for both single and multiline prompts
EDIT: only needed nvm need printf "%s" $$result\n
|
Using universal variables here seems like it might invite a new class of bugs. Hopefully, fish is careful when concurrently writing to the universal variables file, but the degree of care that's possible might depend on the user's OS, the kind of filesystem the file is on, etc. |
|
In previous versions, Universal Variable was used, but occasionally the prompt content was not reflected immediately, so we changed to the tmpfile strategy. |
While setting up my prompt with fish_async_prompt I noticed that after adding multiple async functions it started getting noticable slow. After a bit of digging around I found that adding an additional async function adds around 80ms of execution time to
fish_prompt:While having 1 function like this isn't really noticable as it is below 100ms, this starts adding up quickly and becomes really noticable, especially when the whole goal is to make the prompt faster with making it async.
I didn't dig deep enough to investigate why reading from temporary files make this process this slow, but quickly doing a proof of concept using universal variables instead showed a huge performance increase:
I've only tested it on my local setup (MacOS 13.2.1, fish 3.7.1), so I can't comment if this has unintended side effects on other systems, but since this variable handling is part of the shell itself I would presume no.