Well, that's embarrassing. I can't even imagine the level of shame I would feel if I had written the offending code.
But, you know, premature optimization yadda yadda.
But, you know, premature optimization yadda yadda.
10MB is less than the cache in modern CPUs. How can this take minutes(!).