-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add inline functions to GDScript #3760
Comments
I believe that optimisations under the hood like these should be handled by a smarter compiler, rather than being associated to keywords. |
what could |
perhaps there may be cases when the compiler's work is undesirable in order to optimize such things. I don't know much about that, but I can assume that the "smartness" of the compiler can increase the compilation time of scripts (in the case of a large project), |
I remember @vnen mentioning that he wanted to look at automatically inlining short functions and unrolling loops that have a known number of iterations at compile-time (until a certain limit is reached). I would prefer going for this route rather than requiring users to manually add GDScript parsing/compilation times aren't a bottleneck1, and this step is skipped in projects exported in release mode anyway (thanks to Footnotes
|
Yeah, I'd rather make the compiler just optimize those cases instead of letting it to the user. Probably the main reason GDScript is slow is because of the lack of optimization steps. Optimization in general will be worked after 4.0 is released.
Compilation time doesn't seem to be a problem now. If it becomes a problem because of optimization, then we can see what to do about that. |
Okay, I will not argue with George :) |
I support the idea of inlining (utility) functions:
I'm opting for an extra annotation called @inline. It comes in very handy especially for utility functions, which are one or two liners. Utility functions like:
or
hide their simple or not so simple logic and have to be written only once. At the same time it makes the code faster because the calling stack and such overhead is omitted. Incorporating the function directly might not even increase build size. Ofc it's a good decision if the compiler has optimizations build in. Lambdas might profit from this kind of annotation or compiler optimization strongly, too. |
Describe the project you are working on
RTS-like games and prototypes
Describe the problem or limitation you are having in your project
It's a common issue in strategic games to get an index from x, y coordinates which for comfortability is placed in separate functions like:
Then that function can be called in multiple places to get the index, for example:
I am afraid that this approach is not very optimal since
idx
may call very frequently and the performance would not optimal especially since GDScript is 20 times slower than C++.Describe the feature / enhancement and how it helps to overcome the problem or limitation
I suggest adding an
inline
keyword to GDScript to be used within a function declaration:Then it will receive an optimization that places the content of that function to the place where it's calling (similar to C/C++ define preprocessor command or compiler inline function declaration).
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Functions declared with
inline
may not be a subject ofcall
method, ClassDB, or (maybe) documentation gathering.I understand that it sounds like syntax sugar but it may be very useful to create compact and optimized code. I don't have much hope for this to be accepted but still decided to post this idea.
If this enhancement will not be used often, can it be worked around with a few lines of script?
no
Is there a reason why this should be core and not an add-on in the asset library?
maybe the GDScript compiler should make small functions inline automatically, but I don't know.
The text was updated successfully, but these errors were encountered: