fzf icon indicating copy to clipboard operation
fzf copied to clipboard

[Feature request] improve performance handling iterm2 image protocol in `--preview`

Open JohnFinn opened this issue 1 year ago • 0 comments

Checklist

  • [X] I have read through the manual page (man fzf)
  • [X] I have searched through the existing issues
  • [x] For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.55.0 (v0.55.0)

OS

  • [X] Linux
  • [ ] macOS
  • [ ] Windows
  • [ ] Etc.

Shell

  • [X] bash
  • [ ] zsh
  • [X] fish

Problem / Steps to reproduce

I noticed that fzf preview takes quite a long time when showing big images with iterm protocol. This gets annoying when browsing filesystem. My measurements has shown that without fzf rendering takes around 25ms and with fzf it gets up to 400ms.

measurement with fzf

# to make sure chafa is not the issue
chafa -f iterm --view-size 91x44 a.png > a.chafa
# fzf preview loads ~400ms
echo foo bar | fzf --preview '/bin/cat a.chafa'

https://github.com/user-attachments/assets/0897dc27-7348-4e82-ae46-7e5cb13806a6

fzf opened at 11th frame 0.7333s till preview rendered at 18th frame 1.20s -> 0.4666s

baseline measurement

❯ hyperfine '/bin/cat a.chafa' --show-output
...
  Time (mean ± σ):      25.2 ms ±   1.0 ms    [User: 0.4 ms, System: 10.0 ms]
  Range (min … max):    22.5 ms …  27.9 ms    129 runs
image used ![a](https://github.com/user-attachments/assets/c3a81edd-476d-4b6a-93ac-cb95045eecf7)

Since without fzf the rendering takes much less time, it seems like fzf has quite a lot of overhead somewhere. It would be great to optimize it

JohnFinn avatar Sep 02 '24 02:09 JohnFinn