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

winch: Optimize calls #7927

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

saulecabrera
Copy link
Member

@saulecabrera saulecabrera commented Feb 13, 2024

This commit introduces several optimizations to speed up the compilation of function calls:

  • Keep track of previously resolved function signatures for local or imported callees to avoid computing the ABISig on every function call.
  • Keep track of previously resolved type signatures for indirect calls to avoid computing the ABISig on every function call.
  • Refactor CallKnown and CallUnknown instructions to make the BoxCallInfo field in the struct optional. Prior to this change, from Winch's perspective each call lowering involved a heap allocation, using the default values for BoxCallInfo, which in the end are not used by Winch.
  • Switch Winch's internal Stack to use a SmallVec rather than a Vec. Many of the operations involving builtin function calls require inserting elements at arbitrary offsets in the stack and using a SmallVec makes this process more efficient.

With the changes mentioned above, I observed ~30% improvement in compilation times for modules that are call-heavy.

@saulecabrera saulecabrera requested a review from a team as a code owner February 13, 2024 17:23
@saulecabrera saulecabrera requested review from elliottt and removed request for a team February 13, 2024 17:23
@saulecabrera saulecabrera force-pushed the some-optimizations branch 2 times, most recently from 00477ff to f3421b6 Compare February 13, 2024 17:36
This commit introduces several optimizations to speed up the compilation
of function calls:

* Keep track of previously resolved function signatures for local or
  imported callees to avoid computing the `ABISig` on every
  function call.
* Keep track of previously resolved type signatures for indirect calls
  to avoid computing the `ABISig` on every function call.
* Refactor `CallKnown` and `CallUnknown` instructions to make the
  `BoxCallInfo` field in the struct optional. Prior to this change,
  from Winch's perspective each call lowering involved a heap
  allocation, using the default values for `BoxCallInfo`, which in the
  end are not used by Winch.
* Switch Winch's internal `Stack` to use a `SmallVec` rather than
  a `Vec`. Many of the operations involving builtin function calls
  require inserting elements at arbitrary offsets in the stack and
  using a `SmallVec` makes this process more efficient.

With the changes mentioned above, I observed ~30% improvement in
compilation times for modules that are call-heavy.
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language winch Winch issues or pull requests labels Feb 13, 2024
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen, @saulecabrera

This issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "isle", "winch"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle
  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

This seems good to me!

winch/codegen/src/visitor.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/isa/x64/inst/mod.rs Outdated Show resolved Hide resolved
winch/codegen/src/codegen/env.rs Outdated Show resolved Hide resolved
@saulecabrera saulecabrera added this pull request to the merge queue Feb 14, 2024
Merged via the queue into bytecodealliance:main with commit 1b5c4ae Feb 14, 2024
21 checks passed
@saulecabrera saulecabrera deleted the some-optimizations branch February 14, 2024 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants