bnbeckwith / wc-mode

Wordcount minor mode for Emacs
68 stars 11 forks source link

Findings from benchmarking wc-mode #19

Open sten0 opened 1 year ago

sten0 commented 1 year ago

Hi @bnbeckwith,

I've had to deactivate wc-mode again due to scaling issues, but this time I did some semiformal benchmarking, and count-words is consistently at least ~68.7% slower than calling GNU coreutils "wc". I tried a second method to remove wc's potential advantages, and this showed that count-words was 66.20% slower than wc. This is with Emacs 28.2, and with native-compilation enabled, so I'd consider it the best-case scenario.

Consequently, I think the the way forward for wc-mode, for is the following: Call "wc" for the whole region, but only asynchronously, and only as an-autosave-hook (if possible). Failing that, then as a save-hook. In either case writing to disk doesn't need to wait for the process to return.

Impact: All Linux distributions and BSDs have "wc" (MacOS has it too). I suspect WSL is slow, so Windows users would probably use of of these: https://gnuwin32.sourceforge.net/packages/coreutils.htm https://learn.microsoft.com/en-gb/powershell/module/microsoft.powershell.utility/measure-object?view=powershell-7.3

After that, I don't see how further optimisation will be possible without introducing some kind of "zones" which tally the words added and removed relative to the global count.