Open andi-blafasl opened 1 year ago
This looks like an oh-my-posh issue (not a Clink issue, and not a Cmder issue). There is a pause every time you press Space.
Oh-my-posh binds a custom command to the Space key. The custom command invokes the oh-my-posh.exe program every time you press Space. The reason it binds a custom command to the Space key is so that it can change the right-side prompt depending on what command word has been typed.
@JanDeDobbeleer The custom command needs to be more efficient. One cheap option could be to only invoke oh-my-posh when the command word changes; then there would usually only be a delay the first time Space is pressed. Another more sophisticated option could be to update the oh-my-posh Lua script to use Asynchronous Prompt Filtering. We can chat here, or you can send me an email to the address in my github profile and we can chat offline and post an update here later.
@chrisant996 we already make use of async prompt filtering so that should be good. I also just created a change that will only enable this functionality when you've set custom tooltips (it was enabled all the time). Can you point me to the docs on command word changes?
But still, the issue stands. The version needs to be updated :-)
@andi-blafasl With recent versions of OMP, I do not see the reported behavior. There is a delay, but only when initially showing the prompt, and when Space is pressed the first time.
@JanDeDobbeleer I looked at OMP v10.0.1 and it uses a coroutine for the right side prompt, but it doesn't use Clink's Asynchronous Prompt Filtering support.
On my fast gaming laptop, OMP uses ~260 ms in a non-git directory, and ~340 ms in a relatively small git repo with no modified files. OMP can achieve 0-2 ms if it uses Clink's Async Prompt Filtering support.
Some observations for the OMP init script:
ohmyposh_space
is already only refiltering when the command word changes. That looks good in v10.0.1; it will be informative to find out what version of OMP the OP is using.ohmyposh_space
, ideally the rl_buffer:insert(" ")
should happen first, so that it gets the correct first word even when for example Space splits gitcommit
into git commit
.clink.promptcoroutine()
, Clink does a bunch of work to make sure only one instance of the prompt coroutine runs at a time, it queues additional coroutine requests, and it intelligently discards obsolete queued prompt coroutine calls. Clink goes to some trouble to avoid spawning lots of concurrent processes, and it automatically handles all the caching magic.For OMP to fully utilize Clink's async prompt filtering and be the most responsive, OMP would need to communicate with itself about the previous values it used for "expensive" operations, and then reuse those values for the initial synchronous spawn of OMP, and trigger an async spawn of OMP to recalculate updated values for the "expensive" operations.
For Clink v1.3.43, I've added diagnostic output in Clink to report costs for prompt filters (Alt-1,Ctrl-X,Ctrl-Z).
Here is OMP in a plain non-git directory with the jandedobbeleer.omp.json theme. I included flexprompt costs, pasted in from a separate run, for convenience.
prompt filters:
filter: last avg peak
c:\wbin\clink\oh-my-posh.lua:137 106 ms 108 ms 110 ms
c:\wbin\clink\flexprompt.lua:1398 0 ms 0 ms 0 ms
c:\wbin\clink\flexprompt.lua:1379 0 ms 0 ms 0 ms
rightfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:147 95 ms 96 ms 96 ms
c:\wbin\clink\flexprompt.lua:1384 0 ms 0 ms 0 ms
transientfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:181 66 ms 66 ms 66 ms
c:\wbin\clink\flexprompt.lua:1388 0 ms 0 ms 0 ms
transientrightfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:189 0 ms 0 ms 0 ms
c:\wbin\clink\flexprompt.lua:1392 0 ms 0 ms 0 ms
Here is OMP in the clink git repo (which is relatively small, and has no files modified right now). Again I included flexprompt costs, pasted in from a separate run, for convenience.
prompt filters:
filter: last avg peak
c:\wbin\clink\oh-my-posh.lua:137 170 ms 129 ms 170 ms
c:\wbin\clink\flexprompt.lua:1398 0 ms 0 ms 0 ms
c:\wbin\clink\flexprompt.lua:1379 1 ms 1 ms 2 ms
rightfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:147 99 ms 97 ms 99 ms
c:\wbin\clink\flexprompt.lua:1384 0 ms 0 ms 0 ms
transientfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:181 72 ms 69 ms 72 ms
c:\wbin\clink\flexprompt.lua:1388 0 ms 0 ms 0 ms
transientrightfilter: last avg peak
c:\wbin\clink\oh-my-posh.lua:189 0 ms 0 ms 0 ms
c:\wbin\clink\flexprompt.lua:1392 0 ms 0 ms 0 ms
@chrisant996 thanks. Seems like I have some studying to do. But this part is a no go architecturally:
OMP would need to communicate with itself about the previous values it used for "expensive" operations
These are only expensive on Windows btw, not kidding either. Git is significantly slower on Windows (also for the oh-my-posh repo).
@chrisant996 thanks. Seems like I have some studying to do. But this part is a no go architecturally:
OMP would need to communicate with itself about the previous values it used for "expensive" operations
@JanDeDobbeleer In that case, there are three basic categories of options:
clink.promptcoroutine()
instead of coroutine.create()
(and remove the logic that tries to avoid creating more than one coroutine at a time -- clink.promptcoroutine() handles that and several other things automatically). It's not a straight "rename the function call", though -- they work differently, so additional adjustments will be needed. Let me know if you'd like me to take a stab at it.:filter()
function (and normal :transientfilter()
function) asynchronously run OMP for both the left and right prompts, and cache the right prompt result, and then in the :rightfilter()
function use the cached result. Because you get only one clink.promptcoroutine()
per prompt filter, which is what enables the caching to work and achieve the high responsiveness. I might have designed it a little differently if right-filter support had come first, but it is what it is.My recommendation would be option 3 if responsiveness is considered more important than initial accuracy after e.g. changing the current working directory.
OMP is mostly already avoiding concurrent instances, so the benefit of option 2 seems relatively low by itself, unless/until reports come in about extra OMP instances running concurrently (there are edge cases that can happen, e.g. when pressing Enter and clink.promptcoroutine()
would prevent them, but again it's probably not worth doing option 2 by itself).
@chrisant996 I'll first need to get clink to work on my ARM VM. For some reason it simply refuses to load. Probably pebcak...
There's no ARM version of Clink. You'll have to start the x64 or x86 cmd.exe in order to be able to inject Clink.
P.S. @JanDeDobbeleer let me know if you want me to take a stab at option 3.
There's no ARM version of Clink. You'll have to start the x64 or x86 cmd.exe in order to be able to inject Clink.
Tried that, must've done something wrong.
@chrisant996 yes, if you want to you can give it a go.
@andi-blafasl With recent versions of OMP, I do not see the reported behavior. There is a delay, but only when initially showing the prompt, and when Space is pressed the first time.
- What version of Oh-My-Posh are you using?
- Which OMP theme are you using? (And what version of the theme?)
- Are you using the one-line oh-my-posh.lua script from the docs? If not, then try using the one-line script so that it can stay current with OMP updates.
@chrisant996 I updated OMP to the latest 10.0.1 Version last friday. Today I tested it and there is no delay after pressing space any more. Not sure if it makes a difference, but I'm outside the Office-LAN at Home today. The Theme is a trimmed down Version of Atomic. I included it in the Issue OMP 2815 That's the way I use to integrate OMP with cmder
cat oh-my-posh.lua
load(io.popen('oh-my-posh init cmd --config %USERPROFILE%/.mytheme.omp.json'):read("*a"))()
Just saw there is Version 10.2.0 available with winget. Here is an updated debug output:
Version: 10.2.0
Segments:
ConsoleTitle(false) - 0 ms -
shell(true) - 0 ms - ╭─ WindowsTerminal
root(false) - 0 ms -
path(true) - 2 ms - ~
git(false) - 16 ms -
kubectl(true) - 1 ms - ﴱ tkg-cluster-1
os(true) - 0 ms -
battery(true) - 10 ms - 88
time(true) - 0 ms - 26,09:59
text(true) - 0 ms - ╰─
exit(true) - 0 ms - ff
Run duration: 100.7478ms
Cache path: C:\Users\test\AppData\Local\oh-my-posh
Config path: C:\Users\test\.mytheme.omp.json
Logs:
2022/09/26 09:59:12 debug: Getenv
C:\Users\test\AppData\Local
2022/09/26 09:59:12 Getenv duration: 0s, args: LOCALAPPDATA
2022/09/26 09:59:12 CachePath duration: 0s, args:
2022/09/26 09:59:12 debug: Getenv
C:\Users\test\.mytheme.omp.json
2022/09/26 09:59:12 Getenv duration: 0s, args: POSH_THEME
2022/09/26 09:59:12 debug: Shell
process name: cmd.exe
2022/09/26 09:59:12 debug: Shell
parent process name: WindowsTerminal.exe
2022/09/26 09:59:12 Shell duration: 64.4381ms, args:
2022/09/26 09:59:12 resolveConfigPath duration: 64.9422ms, args:
2022/09/26 09:59:12 Init duration: 67.2396ms, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 config.loadConfig duration: 627.9µs, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 debug: Getenv
2022/09/26 09:59:12 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/09/26 09:59:12 WindowsRegistryKeyValue duration: 0s, args: HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 debug: WindowsRegistryKeyValue
ColorizationColor(DWORD): 0xC40078D7
2022/09/26 09:59:12 Root duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 ErrorCode duration: 0s, args:
2022/09/26 09:59:12 IsWsl duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 debug: User
test
2022/09/26 09:59:12 User duration: 0s, args:
2022/09/26 09:59:12 debug: Host
ID1616
2022/09/26 09:59:12 Host duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 Root duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 PathSeparator duration: 0s, args:
2022/09/26 09:59:12 PathSeparator duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 IsWsl duration: 0s, args:
2022/09/26 09:59:12 StackCount duration: 0s, args:
2022/09/26 09:59:12 DirIsWritable duration: 504.7µs, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 debug: CommandPath
C:\Program Files\Git\cmd\git.exe
2022/09/26 09:59:12 CommandPath duration: 14.5544ms, args: git.exe
2022/09/26 09:59:12 HasCommand duration: 14.5544ms, args: git.exe
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 error: HasParentFilePath
CreateFile C:\.git: Das System kann die angegebene Datei nicht finden.
2022/09/26 09:59:12 HasParentFilePath duration: 1.1119ms, args: .git
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 debug: Getenv
2022/09/26 09:59:12 Getenv duration: 0s, args: KUBECONFIG
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 debug: FileContent
apiVersion: v1
clusters:
- cluster:
server: https://10.10.10.10:6443
name: 10.10.10.10
- cluster:
certificate-authority-data: *removed*
server: https://10.10.10.11:6443
name: 10.10.10.11
- cluster:
server: https://tanzu.vsphere.local:6443
name: supervisor-tanzu.vsphere.local
- cluster:
server: https://tanzu.vsphere.local:6443
name: tanzu.vsphere.local
contexts:
- context:
cluster: tanzu.vsphere.local
user: wcp:tanzu.vsphere.local:test@vsphere.local
name: tanzu.vsphere.local
- context:
cluster: 10.10.10.10
namespace: test01
user: wcp:10.10.10.10:test@vsphere.local
name: test01
- context:
cluster: 10.10.10.10
namespace: test02
user: wcp:10.10.10.10:test@vsphere.local
name: test02
- context:
cluster: 10.10.10.11
user: wcp:10.10.10.11:test@vsphere.local
name: tkg-cluster-1
current-context: tkg-cluster-1
kind: Config
preferences: {}
users:
- name: wcp:10.10.10.10:test@vsphere.local
user:
token: *removed*
- name: wcp:10.10.10.11:test@vsphere.local
user:
token: *removed*
- name: wcp:tanzu.vsphere.local:test@vsphere.local
user:
token: *removed*
2022/09/26 09:59:12 FileContent duration: 557.2µs, args: C:\Users\test\.kube\config
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 IsWsl duration: 0s, args:
2022/09/26 09:59:12 BatteryState duration: 9.5541ms, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 debug: Pwd
C:\Users\test
2022/09/26 09:59:12 Pwd duration: 0s, args:
2022/09/26 09:59:12 debug: Home
C:\Users\test
2022/09/26 09:59:12 GOOS duration: 0s, args:
2022/09/26 09:59:12 ErrorCode duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 Shell duration: 0s, args:
2022/09/26 09:59:12 TemplateCache duration: 0s, args:
2022/09/26 09:59:12 debug: Getenv
C:\Users\test\AppData\Local
2022/09/26 09:59:12 Getenv duration: 0s, args: LOCALAPPDATA
2022/09/26 09:59:12 CachePath duration: 504.5µs, args:
2022/09/26 09:59:12 Flags duration: 0s, args:
BTW: A college at my company is also experiencing the slow startup and the long waiting time between two prompts (by just hitting enter). We both installed OMP on our private Systems at Home and there is nearly no delay between two prompts and the runtime in the debug is also very small. Don't have the exact numbers right now, sorry Any Ideas how to debug this problem on our business machines?
I know from experience here with Cmder that business machines can be an issue that is hard to crack. That could be a tough one.
If the business machines let you add exceptions to the antivirus/anti-malware suite, try adding exceptions for oh-my-posh and git (use task manager or etc to figure out which executables are taking a long time to run, and add exceptions for them).
If not ... then you're probably stuck with the delays.
@chrisant996 I already made an exception for the oh-my-posh executable. The delay was reduced, the exception works. But now even if I disable the Antivirus on my machine completely, there is no difference in timing. ¯\_(ツ)_/¯
@andi-blafasl which timing, where, for how long?
Try to use task manager or etc to figure out which executables are taking a long time to run, and add exceptions for them.
oh-my-posh.exe is only one of multiple executables that may be running.
You'll have to dig into this a bit and examine what's happening on the machine.
There's no ARM version of Clink. You'll have to start the x64 or x86 cmd.exe in order to be able to inject Clink.
Tried that, must've done something wrong.
@chrisant996 yes, if you want to you can give it a go.
@JanDeDobbeleer I have some proposed changes, and maybe some bug fixes. I'll put together a PR sometime this coming week.
Short version -- omp is now highly responsive except in two cases:
PR is available at https://github.com/JanDeDobbeleer/oh-my-posh/pull/2951.
Sorry for the delay ... I plain forgot about it. 🙃
@chrisant996 we're only human. And busy enough already 😅
This may be a dumb question but what does Clink have to do with OMP since Clink is a shell enhancement for Cmd and not Powershell? I think I am missing something. Thanks in advance.
@daxgames oh-my-posh can run in any shell as of the last 2 years. I guess that's the context you're missing.
OMP supports Clink now, and for each shell OMP has a different built-in custom script for integrating with the shell. We've been working on optimizing OMP in Clink so that it doesn't cause lags/pauses.
This issue (2751) is at its root about OMP, moreso than either Cmder or Clink. But the OP observed that a newer Clink made the delays a little shorter, so the OP requested Cmder to update to a newer Clink. However, the main issue was that a newer version of OMP needed to be used. Along the way Jan and I found some additional ways to improve OMP.
Purpose of the issue
Version Information
Cmder 1.3.19.1181 Clink provide with Cmder 1.2.46 Clink latest 1.3.42.ef446e Windows Terminal 1.15.2524.0 (but problem also appears in conemu) Windows 10 Version 21H1 (Build 19043.2006)
Description of the issue
I'm trying to get oh-my-posh running but with the embedded Clink the input is horrible slow:
yes, this is real time copy-past ;-)
with the latest clink version it is a little bit better:![oh-my-posh-faster](https://user-images.githubusercontent.com/3586675/191939677-75e3e174-a791-4120-a0fa-23ee5ded2f17.gif)