|
|
|
|
|
by tomp
4586 days ago
|
|
Instead of devirtualization, a simpler optimization, which would additionally also help in the dynamic case, is simple loop hoisting of the method pointer fetch. Instead of doing while(...) {
(obj->vtable[0])(...)
}
we could have void(*fn)(...) = obj->vtable[0]
while(...) {
fn(...)
}
which would avoid two redirections per inner loop! Actually, I'm almost sure that is what LuaJIT would do, and many other high-level programming languages could perform this optimization as well. However, maybe C is too low-level to be able to do that, and I don't know about C++. |
|