Skip to content
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

Feature request: inlining improvements #37

Open
m4tiz5zktonj opened this issue Jun 2, 2024 · 0 comments
Open

Feature request: inlining improvements #37

m4tiz5zktonj opened this issue Jun 2, 2024 · 0 comments

Comments

@m4tiz5zktonj
Copy link

Hi, I have two ideas about functions inlining, that may be useful.

  1. Automatically inline private (both static and non-static) class functions, if such functions are called just one time and their bodies and call contexts comply all the limitations for inlining. As an alternative user may allow such behavior by declaring (:allow_simple_private_functions_inlining) or similar annotation on class level. Or optimizer can just add VS Code's info level hint to problems panel for such functions during live code analysis. Or it can add info messages during build process. In other words, optimizer can do automatic inlining (by default or with user permission), if you as me think it is safe, or it can just warn user about the possibility to do such inlining.
  2. Warn user if large function is inlined (either automatically or because of explicit (:inline) annotation) to more than one place. By "large" I mean functions with more than one (or two) expression like anything larger than function t(x, y) { f(y + 1, x - 1); } after all previous inlinings are done, but any other code size related metrics is fine too.

My story: I have a large class with a few dozens of small private functions that implement separate parts of heavy trigonometrical calculations, and these functions call each other. Most of them are called only once, while few others don't. I checked number of calls and added (:inline) annotation to almost all of them, but did one mistake by adding annotation to function that is called two times. After all other one-call functions inlining my two-call function's size became almost 150 lines, and this code is inlined to two places. As optimized code is barely readable because of "Minimize Locals" (and it's OK), and I haven't noticed it. And few months later I accidentally understood that and saved more than 1100 bytes by just removing (:inline). It would've been nice, if optimizer warned me earlier about such result and/or inlined small functions automatically leaving no place for user error.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant