BTW, the bottom line is that the compilation time of the original problem went from 2800 to 7 seconds after working through the code with @snoopi_deep
. Yes, you are reading that right. And runtime got 3x faster as an incidental bonus, though it was not targeted.
(There is, of course, a downside: I was using the compilation time to practice fingerstyle guitar and got pretty good at some songs, now I will have to find other time for that.)