Unfortunately it's a hard problem with no easy, performant solutions.
That's a shame. It's still an interesting program, though.