This is taken from my `fast-infer` branch, but unrelated.

No semantic changes here except:
 - the bug fix
 - more timing events and gc timing