-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Question about "vm:prefer-inline" #51977
Comments
First, compiler needs to figure out that a particular call in the caller leads to a particular callee. For static methods and constructors this is always the case. For instance methods it depends on the class hierarchy, whether the method is overridden and whether compiler can determine (or speculate on) the actual type of the receiver. Method is less likely to be inlined if call site is polymorphic (can call multiple different methods). After figuring out the target of the call, compiler uses a very complex heuristic to decide whether to inline a method or not. The heuristic is based on the size of the caller and the callee, number of call sites in the callee, loop nesting in the caller etc. Currently compiler cannot inline certain methods, even if they are annotated with
Absolutely. However, unless the method is critical for performance and you can measure that inlining of this method improves performance, consider relying on the compiler heuristic. Excessive inlining causes larger code size, and in certain cases inlining may regress performance instead of improving it.
Both JIT and AOT compilers do the method inlining. However, the heuristic for choosing whether to inline is slightly different and based on different information. JIT can inline speculatively, based on the collected feedback from executing program. AOT compiler uses whole-program analysis to determine possible call targets which can be inlined. Both JIT and AOT respect |
@alexmarkov hey, I'd like to add a lint rule to highlight usages of |
@incendial To the best of my knowledge, the list is complete. However, I would advise against relying on the details of the compiler optimizations as they are not specified and not required by the language spec. Particular optimizations and handling of pragmas are the internal implementation details and may change without notice. The inability to inline methods with Methods not declared |
@alexmarkov thanks for the heads up, but it looks like a useful hint to people trying to use pragmas and as you mentioned this is the internal behavior that is rather implicit and people might be not aware that their actions (setting the annotation) actually make zero impact. Can you share how often do you change this part of the compiler? Or maybe there are some upcoming changes? |
To be honest warnings will be very useful in cases of code optimizations where developer is trying to achieve maximum performance and use all language capabilities. If is possible to detect method inlining then it will be very nice compiler feature. |
Hello!
I want ask about pragma "vm:prefer-inline".
I have three questions.
First: What conditions and requirements for method to be inlined ? For example count of lines or something else
Second: Could this pragma be useful for public methods which called from other classes and using private fields like in the example below ?
Last: Inlining is possible in JIT and AOT modes or only JIT ?
The text was updated successfully, but these errors were encountered: