First performance improvements for chunk handling.
This isn't stable atm, so not ready for master.