I've added additional C++ optimizations and limited the number of threads we create

I've measured a speedup of about 25% from these changes, not counting the added speedup from multithreading.  Most of it comes from the first 2 commits; I don't know how applicable those are to Go though.