Performance commits

Take 2.  This is forked off the horde/improve-build-performance branch instead, to grab a couple of optimizations Jan already made.