[PATCH] D17792: Initialize much of AssemblyWriter lazily.

Tim Shen via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 16:57:51 PDT 2016


timshen added inline comments.

================
Comment at: lib/IR/AsmWriter.cpp:82
@@ +81,3 @@
+
+  std::function<T()> Initializer;
+  Optional<T> Obj;
----------------
jlebar wrote:
> timshen wrote:
> > Man, by last time I looked at libstdc++, it's like 48 bytes on 64-bit machines...
> > 
> > Even if Lazy keeps track of the raw lambda, the lambda may still capture stuff and have memory footprint.
> > 
> > Now I think it's a bad idea. It's as bad as that dtor doesn't have parameters so each container, which may be in a parent container, needs to keep its allocator.
> > 
> > Sorry, I think the Optional version is better. :(
> > 
> > BTW, how hard is it to make the user side lazy, rather the library side?
> > Man, by last time I looked at libstdc++, it's like 48 bytes on 64-bit machines...
> 
> Eh, I don't think this is a big deal, compared to all the other work we're doing here.  :)
> 
> > Even if Lazy keeps track of the raw lambda, the lambda may still capture stuff and have memory footprint.
> 
> Indeed, but these lambdas don't, so we're ok in that respect!
> 
> > It's as bad as that dtor doesn't have parameters so each container, which may be in a parent container, needs to keep its allocator.
> 
> :)  Here I'm much more concerned about readability.  Like, we're making this *way* faster in any case; the extra few bytes or whatever isn't a big deal.
> 
> > BTW, how hard is it to make the user side lazy, rather the library side?
> 
> I'm not sure what you mean; can you give me an example?
> :) Here I'm much more concerned about readability. Like, we're making this *way* faster in any case; the extra few bytes or whatever isn't a big deal.

If you don't think extra is a big deal, go for it :). But still be aware that the moment when the underlying object T gets initialized is relatively hard to track down (that's the whole point, isn't it ;).

> I'm not sure what you mean; can you give me an example?

By saying "user" I mean "Value::operator<<", and library is "AssemblyWriter". Is there a way to keep an AssemblyWriter instance in Value::operator<<'s context (Module?), so that you don't have to change AssemblyWriter?


http://reviews.llvm.org/D17792





More information about the llvm-commits mailing list