seagle0128 / doom-modeline

A fancy and fast mode-line inspired by minimalism design.
https://seagle0128.github.io/doom-modeline/
GNU General Public License v3.0
1.29k stars 159 forks source link

perf: calculate anzu count faster and with less memory #725

Closed kisaragi-hiu closed 4 months ago

kisaragi-hiu commented 4 months ago

Instead of allocating a list with N items and returning its length, just keep a tally of the number directly. This can also avoid generating lots of garbage that has to be collected.

The performance impact can be tested with this when using Evil:

(benchmark-run 10 ; or some other number of repetitions
  (let ((last-kbd-macro [?/ ?. return])) ; initiate an evil search for the pattern "."
    (call-last-kbd-macro)))

On my machine in a 2.3 MB file, this went from 27.06 seconds (2.7 seconds per iteration) to 25.98 seconds (2.6 seconds per iteration), but before this change I also sometimes experience lockups where the search inexplicably takes several times longer.