Turns out, meta-programming is faster.
So I had this #ed(1) #Interslavic dictionary search script. Taking a word from file name, concatenating it to every line in the dictionary, and matching all the lines with 2+ occurrences of the word. Easy, right?
And slow. It took, like, two seconds for the script to search for a word in a 20K word dictionary (Interslavic is quite frugal!) which is beyond acceptable. I tried to filter out the non-matching lines before concatenation (the most resource-intensive and allocation-heavy part) to no avail.
And then it dawned at me: what if all this runtime pattern search was compiled into a simple g-lobal search and ran through another instance of ed(1)? So I did:
!# Meta trick to read current file name (word to search) into the buffer
0r !echo %
!# Turn into a meta script to feed into ed: enable help, search for word, output, quit
s;\(.*\);H\
g/^[^ ]* \\([^ ]*\\) .* \\([^ ]*\\<\1\\>[^ ]*\\) .* \\([^ ]*\\) \\([^ ]*\\) [^ ]*$/s//\\1: \\2 (\\4)/p\
Q;
-2,.w ! ed -s ~/Documents/isv.tsv
Looks scary, but only because I have to manage tabs in a TSV file. But, otherwise, it's a nice solution that lowered the lookup time to cognitively imperceptible numbers. I'm happy with it!