-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Larger compilation results in TeaVM 10.0.0-SNAPSHOT #870
Comments
No, there's no way to do that. But you need to figure out what's causing this behaviour. It's not necessarily some actual multi-threaded code.
No, it's not possible. TeaVM tries to guess set of classes that need reflection and generates meta-information only for those. So in order to reduce meta-information tables, you need to get rid of code that uses class names. |
But why does it generate reflection data for lambdas then? And what type of code is considered to use class names? Everything which uses class references like "MyClass.class"? Because I am not using any Class.forName("...") or related methods and the data is created for most (if not all) classes... |
Because TeaVM decided that some of your code takes names of lambda classes. This may be not necessarily be true, but AOT compiler can only act in a conservative way. For example, you can have code like this in one method: var list = new ArrayList<Object>();
list.add((Runnable) () -> {}); and in some other method something like this list.get(i).getClass().getName() then TeaVM MAY think that lambda class in the first snippet requires metadata, even if at run time it's never the case. This depends.
For example, I don't want to introduce a switch to control this behaviour. In you case you perhaps don't need this, but someone else would need this feature. Then someone else notices that there's another sort of code that can be thrown away. And TeaVM ends up with 1000 of flags and switches, which are quite hard to document properly. |
Okay, thank you for the explanation. But maybe at least the obfuscated method name arrays, like |
These aren't names for reflection, but for virtual tables. They can't be omitted. |
Allright, thank you! |
Okay, I found a reference to Thread. This indeed caused the issue. Maybe this should be documented. Can be closed. Thank you again! |
May be it is, but never have time, sorry. Also, I think that it's possible to make TeaVM to help you to find code pieces which cause async infection, somewhere in the future. |
One last question: I do not use any getClass() calls except in equals() implementations where i often write: if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
// ... Will this already cause reflection data to be generated? |
Not sure about this. I think you need to call |
You can try to attach debugger to the TeaVM compiler process, set breakpoint at |
But I want to warn you that according to my measures class names never contribute significant amount to size of the resulting JS. |
I noticed that the compilation results are larger in TeaVM 10.0.0-SNAPSHOT, compared to 0.9.0 and earlier versions.
To investigate, I disabled obfuscation and compared multiple functions. One thing I noticed is, that TeaVM 10.0.0-SNAPSHOT creates a lot of code to simulate multithreading which was not present in earlier versions. For example (see $rt_resuming() blocks):
There are cases in my program (especially switch statements over Strings) which get much longer (and difficult) by this transformation. I am not using any multithreading at all. Is there any possibility to disable this kind of code generation?
On top of that TeaVM creates large reflection tables (including real class names and method name tables, even for lambdas). This has already been the case in earlier versions and is not a new problem, but I wonder why this is done. It should be possible to disable this functionality (or restrict it to runtime classes). I know that the class name is required for toString() of native java/lang/Object. But besides exceptions there is no real need for them in release mode in any codebase which is not relying on reflection.
The text was updated successfully, but these errors were encountered: