On Fri, Nov 08, 2013 at 06:46:37AM -0500, Daniel Micay wrote:
> I don't think the need to do micro-optimizations like this is *common*
> though.

I honestly don't know how common or uncommon various scenarios are.
All I was doing in my e-mail was highlighting scenarios where
indirection is a good idea. I agree with you that, like anything else,
it carries cost and should not be used universally.

> It gets to the point where you're optimizing for the
> characteristics of a specific allocator because they use different size
> class buckets so trusting a profiler on one platform isn't enough.

It can get to that point, but it can easily be the case that
structures are just plain too big. As an example of *not* doing it
right, consider `ast::Expr` -- this type is currently *124 bytes* big!
This is for *every expression* in the compiler. (No wonder our memory
use is high.) I feel pretty confident we could use more indirection in
there even without having consulted the allocator bucket sizes.

In any case, the bottom line is: there is no single answer, you will
have to experiment. As a rule of thumb, I'd say that you should use
indirection (`~`) when data is "optional" -- as in, Option<T> or just
one variant of many -- so as to reduce the size for the other
case. But if the data is always present, you're *probably* better off
avoiding the `~` pointer. But both rules have exceptions.



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

Reply via email to