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

Inlining: Inline trivial calls #6143

Merged
merged 3 commits into from
Dec 5, 2023
Merged

Inlining: Inline trivial calls #6143

merged 3 commits into from
Dec 5, 2023

Conversation

kripken
Copy link
Member

@kripken kripken commented Dec 1, 2023

A trivial call is something like a function that just calls another immediately,

function foo(x, y) {
  return bar(y, 15);
}

We can inline those and expect to benefit in most cases, though we might
increase code size slightly. Hence it makes sense to inline such cases, even
though in general we are careful and do not inline functions with calls in
them; a "trampoline" like that likely has most of the work in the call itself,
which we can avoid by inlining.

Suggested by @gkdn based on findings in Java.

I ran this on the emscripten code size tests and saw nothing that looked
negative or concerning. In fact, this ends up reducing code size slightly
more often than it increases (and all the changes I inspected look like
they should improve speed).

@kripken kripken requested a review from tlively December 1, 2023 00:42
Comment on lines +230 to +231
// This function body is a call with some trivial (size 1) operands like
// LocalGet or Const, so it is a trivial call.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counting by number of Expressions rather than by number of bytes, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Measurer just counts Expressions. That happens to be useful here, but in general we might want to add something more accurate some day for bytes.

@gkdn
Copy link
Contributor

gkdn commented Dec 5, 2023

LGTM

@kripken kripken merged commit 66277f9 into main Dec 5, 2023
14 checks passed
@kripken kripken deleted the inline.trivial.call branch December 5, 2023 20:41
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
A trivial call is something like a function that just calls another immediately,

function foo(x, y) {
  return bar(y, 15);
}

We can inline those and expect to benefit in most cases, though we might
increase code size slightly. Hence it makes sense to inline such cases, even
though in general we are careful and do not inline functions with calls in
them; a "trampoline" like that likely has most of the work in the call itself,
which we can avoid by inlining.

Suggested based on findings in Java.
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

Successfully merging this pull request may close these issues.

3 participants