I just did a number of timing tests. The timings were done in a shell,
on a fresh clone of the Emacs repository, which contains ~5000 files,
and in which one searches for the 43 occurrences of "expose_frame".
The timings are (in seconds):
with GNU grep (version 3.6):
0.124 | "find -name '.?*' -prune -o -type f -print | xargs grep -i
-snHE expose_frame"
0.178 | "find -name '.?*' -prune -o -type f -print | xargs grep -i
-snobHE '.{0,50}expose_frame.{0,50}'"
0.253 | "find -name '.?*' -prune -o -type f -print | xargs grep -i
-snobHE '.{0,80}expose_frame.{0,80}'"
0.325 | "find -name '.?*' -prune -o -type f -print | xargs grep -i
-snobHE '.{0,100}expose_frame.{0,100}'"
with ripgrep (version 12.1.1):
0.045 | "find -name '.?*' -prune -o -type f -print | xargs rg -i -nH
--no-messages expose_frame"
0.079 | "find -name '.?*' -prune -o -type f -print | xargs rg -i -nobH
--no-messages '.{0,50}expose_frame.{0,50}'"
0.109 | "find -name '.?*' -prune -o -type f -print | xargs rg -i -nobH
--no-messages '.{0,80}expose_frame.{0,80}'"
0.113 | "find -name '.?*' -prune -o -type f -print | xargs rg -i -nobH
--no-messages '.{0,100}expose_frame.{0,100}'"
It seems that a reasonable compromise is a context of 80 characters,
which is only two times slower than a string search with both GNU grep
and ripgrep, and still very fast.