I was investigating the poor startup performance of a large OCaml binary that I work with. Once I took care of the egregious cases of expensive code in the module initialization path, I noticed something curious.
Through stack sampling, I noticed that my binary’s startup was spending a significant amount of time in the
CamlInternalOO module. Specifically, the
I did some digging, and what I found was quite surprising to me. The vtables for every class is not generated during compile time, but rather at runtime. For most projects, this cost is probably negligible, but due to the size of my project and the number of classes, this code is contributing 10s of milliseconds to startup.
It seems like the vtables could be constructed during compile time instead, at least for classes. I did a bit of searching but I couldn’t find any existing discussion about this.
Has anyone else observed this in their projects? To those more familiar with the compiler/RTS, are there any blockers to constructing the vtables at compile time? I might be interested in contributing some changes here.