babarot / enhancd

:rocket: A next-generation cd command with your interactive filter
2.58k stars 109 forks source link

fish: performance improvments, add piping, fixes #218

Open gazorby opened 1 year ago

gazorby commented 1 year ago

WHAT

WHY

Bring feature parity with zsh (piping) and improve overall latency by storing directories in memory instead of a file and freeing up execution time by moving some checks at shell init.

The existing ~/.enhancd/enhancd.log file will be read to fill the variable if it's empty to make the migration seamless.

The rewrite in _enhancd_filter_interactive.fish is mainly due to avoid buffering so we can take advantage of finders able to stream stdin, like fzf.

Simplistic benchmarks

Here are some benchmarks with the filter disabled for each version.

Log file / variable size: 345 Fish version: 3.6.1 Platform: WSL 1.3.15.0

10 runs

Command:

time for i in (seq 10); enhancd; end

Results:

Latest enhancd (230695f8da8463b18121f58d748851a67be19a00)

________________________________________________________
Executed in    7.51 secs    fish         external
   usr time    0.59 secs    0.19 secs  397.38 millis
   sys time    1.20 secs    1.17 secs   23.02 millis

perf/in-memory-logs

________________________________________________________
Executed in  392.15 millis    fish           external
   usr time  287.06 millis  165.81 millis  121.25 millis
   sys time  124.71 millis  116.80 millis    7.92 millis

500 runs

Command:

time for i in (seq 500); enhancd; end

Results:

Latest enhancd (230695f8da8463b18121f58d748851a67be19a00)

________________________________________________________
Executed in  377.12 secs    fish         external
   usr time   27.87 secs    8.87 secs   19.00 secs
   sys time   60.06 secs   58.44 secs    1.62 secs

perf/in-memory-logs

________________________________________________________
Executed in   22.64 secs    fish         external
   usr time   15.85 secs    9.62 secs    6.22 secs
   sys time    5.36 secs    4.64 secs    0.72 secs