[WIP] Mapgen performance improvements

Fixes #8743