distrobox-enter: improve cmd composition speed #1649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR:
distrobox-enter
is slow. I did some timing of the code using the original but timed and slightly modified but eventually came to the improvements proposed by this PR.Long version:
I had noticed that my command to launch a terminal
has become slower but especially so on my laptop, taking multiple seconds.
I then eliminated
foot
by runningtime distrobox-enter home -- true
. It was still slow. So I tried to launch thepodman-exec
manually and it only took ~250ms instead of 2-3 seconds.Now I was pretty sure it was on distrobox' side and figured out which part of the
distrobox-enter
script is taking so much time using the original but timed . The slowest part is in this loopMy first idea was to replace the
grep -q " "
by e.g.to check if a line had a space. This did improve it to close to one second total runtime (-1sec)
Timings from my machine
I still wasn't fully satisfied and wanted to remove any
if
s andcase
s. Which resulted in this PR. This relies on the fact, that any container-manager flag can be given using--flagname=VALUE
(note the=
). The changes also have the side effect of making--additional-flags
accepting both styles (using=
or a space) of sepearting the flag name from the value.Some more timings including this PR (branch 'even-faster')