I found something recently that is worth mentioning regarding line iteration (scanning for stuff) (again!). This can speed up some things pretty drastically when doing heavy iterations:
If your application is accessing more than one property within a pattern line (scanning more than one note column, or searching for values in the whole song), strongly consider to use :lines_in_range(). The tostring(line) can be used with string pattern matching for very fast scanning of pattern data in comparison to the standard nested iterations. You will access one string intsead of iterating all note and effect columns.
This can be a huge optimizaton under the right circumstances and has perhaps been a bit neglected (?). A code example can be seen here: https://forum.renoise.com/t/new-tool-2-7-3-1-set-track-width-to-active-columns/31078
(The reason why it’s faster is, I guess, that native tostring methods in the song object are not just simple LUA metamethods, but internal C++ functions that are a lot faster than a LUA table concatenation would be, for example. So it’s often worth taking advantage of when possible. Perhaps there are also other usable “C++ metamethods” that have been neglected and can be exploited for optimizations?)