3 ms·
Don't you want strong typing for better performance? That's what I thought, too. The VM designers say that in practice, type guarantees really don't help them n
by charliesome 15y ago
Don't you want strong typing for better performance?
That's what I thought, too. The VM designers say that in practice, type guarantees really don't help them nearly as much as you might think, because type checks are not a major drain on performance.
No, but you can generate better code if you know exactly what types you're playing with ahead of time.
Say you have a function like this:
void foo(SomeClass obj) {
obj.bar();
}
That could be compiled to just a straight 'jmp SomeClass::bar', whether you're compiling natively or to a VM.
If you don't have static types, the best code you can output is something along the lines of this:
fn = lookup(obj, "bar")
jmp fn
Of course there are tricks that you can use to optimize this second case a bit that involve fancy static analysis, fancy JIT business, etc. but the point is that you will never generate better code than just a single jump to the right code, based on the types you know at compile time in a static language.
- extension 15y agoIn any sensible OO language (i.e. not C++) all method calls will be virtual, so there is always some sort of dynamic lookup involved.
- AndrewDucker 15y agoIn C# you have to specify that a method is virtual if you want people to be able to override it. This makes it clear where you expect people to insert their changes, allows you to design extra safety into those points, and makes the code faster.