The primary problem is that escape analysis is expensive and fragile and compilers don't do it very well. A secondary problem is that if you change your program so that escape analysis no longer works, the only way to tell is that your performance gets mysteriously worse.
Of course, it would be a nightmare to see every failed optimization, but it would be nice to know when it matters. I think his take on the problem is to allow annotations for critical code so that the compiler either
- successfully optimizes
- fails to optimize but shows a counterexample
- You have to identify the bottlenecks
- You have to realize that the bottleneck can be fixed w/ optimization X that can be done if only the compiler knew about Y (assuming the code generation is at fault in the first place).
- What if the problem isn't one bottleneck, but many? Every time pattern A, pattern B, ..., and/or pattern Z shows up in your code, the compiler treats it conservatively.
- You raise the bar for a standard-compliant compiler. Sure, you already expected a decent compiler to do the requisite static analysis + optimization, but now programmers expect it to respond to the annotations (when previously it silently skipped the optimization).
- The code becomes hideous (maybe not so bad w/ an IDE or nice text editor). The annotations go w/ every declaration (class, field, and function signatures) and object instantiation.
Well his idea (and an idea used in Cyclone and probably others?) is to have sane defaults (if the annotation isn't present assume X), along with some inference. Of course, now you have to modify old code that doesn't conform to the defaults, but I guess those folks can just use a different mode of the compiler?
Overall it really does seem like what Robert wants is regions (his annotations are very similar to the region annotations, hierarchy of lifetimes, defaults, etc.), but he wants to extend it to data structure hierarchies (If my stack internally is represented by a list, the list does not outlive the stack) and allow better optimizations. Also, he had a cool suggestion of allowing casts (which in a region framework would copy the data to the other region).
Anyway, I got a laugh out of one of the responses to the blog post:
XXXXX: Your assumptions are all wrong... that's what java will be doing. It already infers 'escape detection'...And Robert's reply:
You should read up on 'eden' garbage collection systems. This is basically how it works: ... The 'eden' system has one heap page where ALL new objects are created. Everytime eden is full, each object in eden that is *STILL* accessible from some place is copied over to the real heap...
You clearly haven't read what I wrote. And why don't you use the term "copying collector" like the rest of the world?
No comments:
Post a Comment