Implement a virtual method cache

This should help reducing a bit the overhead of some function calls. It's actually difficult to say whether this helps or not because the profile data is fluctuating, but the profiles with the patch applied seem consistently better.