-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore eagerly initializing selected classes #9922
Comments
Hm I don't like introducing a compiler option right away. If some of the shortcomings in the compiler can be fixed, the property might not be worth it.
Given that GWT orders functions in a way that gzip works even better I am not sure if such an optimization would save a noticeable amount of download size. |
Yep, I'm not saying this is definitely the right approach, but worth exploring. Compiled size is only one facet to this - Impl and StackTraceCreator also have a cyclical initialization dependency, and there are a few other classes (DomEvent is the only one I can find right now, but I thought there was another reference). Additionally, clinits leave side effects in code that otherwise would have none, since they have their own "was I initialized or not" state - if the compiler can't prove that an otherwise pure function is being called on an already initialized class (like Double), it has to leave the clinit in place. My limited experience with the compiler and the current contributors suggests that this approach is likely to be more fruitful. I have a very old draft of looking at handling these issues in this way, and definitely seemed to go better than my previous attacks on JsInliner and friends. But if you've got time/budget to try directly addressing in other ways, I'm all for it! |
GWT version: GWT 2.11 and below
Browser (with version): Any
Operating System: Any
Background
GWT takes care to follow Java semantics in ways that users may not always expect or appreciate, especially around class initializers. In the JVM, a class must be initialized before it can be instantiated or its static members can be used, so in GWT, a
$clinit
function is created per class, roughly structured asThis ensures that if invoked more than once, the initializer won't replace already-initialized fields, etc. This will appear at the top of constructors and static methods, and will appear before references to static fields:
This often seems to generate unnecessary output, such as duplicate or pointless clinit calls. Some of these are due to non-obvious side effects from initializing classes, others are unoptimized cases where clinits were appropriately emitted for each individual reference/invocation, but inlining and dead code elimination has left duplicates or leftovers.
Potentially related issues to review when working on this:
#9731
#9004
#6534
Proposal
compiler.splitpoint.initial.sequence
, where order matters, and users can add their own items to the list.The text was updated successfully, but these errors were encountered: