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.
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:
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.