On 21/11/2010 4:17 PM, Mike Capp wrote:
On 21 November 2010 20:48, Graydon Hoare<[email protected]>  wrote:

It's not clear to me yet that the boxing and vtbl'ing costs on objs will
really hurt, but we're not venturing into objc territory on dispatch. We're
doing more like "C++ with the pimpl idiom".

And presumably your objs aren't so mutable that an optimizer couldn't
cache the result of a vtbl lookup if it was going to be called in a
tight loop?

There's no "lookup" to cache; vtbl dispatch is a register+immediate indirect branch. For a dynamic callee, you can't cache it any more than that. The only way in which C++ is "faster" is by statically binding most of its methods (it's not virtual-by-default; you can't *override* most C++ methods).

Rust does something that's a little more conventional in the world of languages-outside-of-C++: object methods are all virtual and object bodies are all heap allocated. But dispatch is still just an indirect branch through a static vtbl. This removes perhaps 90% of the complexity and fragility of the C++ object model while retaining a very good -- not perfect, but good -- dispatch speed.

To get static binding in rust, you have to use a static function call, not an object-method call.

-Graydon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to