optimize metrics compacting

* prevents random segfault