Skip to content

[wasm][coreclr] Cache calli cookies - #127016

Merged
radekdoulik merged 24 commits into
dotnet:mainfrom
radekdoulik:pe-cookie-cache
May 5, 2026
Merged

radekdoulik merged 24 commits into
dotnet:mainfrom
radekdoulik:pe-cookie-cache

Conversation

@radekdoulik

@radekdoulik radekdoulik commented Apr 16, 2026 •

Copy link
Copy Markdown
Member

Avoid repeated expensive calls to get calli cookie by caching it

Checked in HelloWorld

CalliCookie cache: 18 hits, 17 misses, 35 total (51.4% hit rate)

Avoid repeated expensive calls to get calli cookie by caching it
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces overhead in the WASM interpreter call path by caching the computed calli cookie on the MethodDesc, avoiding repeated (and potentially expensive) cookie computation for repeated invocations of the same managed method.

Changes:

  • Cache and reuse a per-MethodDesc calli cookie in InvokeManagedMethod on WASM.
  • Extend MethodDescCodeData (portable entrypoints + interpreter builds) to store a CalliCookie.
  • Add MethodDesc::{GetCalliCookie, SetCalliCookie} APIs to manage the cached value thread-safely.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/vm/wasm/helpers.cpp Uses MethodDesc-cached cookie to avoid repeated GetCookieForCalliSig calls.
src/coreclr/vm/method.hpp Adds CalliCookie storage in MethodDescCodeData and declares accessor APIs under the relevant feature flags.
src/coreclr/vm/method.cpp Implements thread-safe cookie get/set using EnsureCodeDataExists + interlocked/volatile operations.

Comment thread src/coreclr/vm/wasm/helpers.cpp Resolved
Comment thread src/coreclr/vm/wasm/helpers.cpp Resolved
Comment thread src/coreclr/vm/method.cpp Resolved
…Cookie typedef

- Define InterpreterCalliCookie typedef: function pointer on WASM,
  CallStubHeader* on non-WASM (Jan's feedback)
- Unify SetCalliCookie/GetCalliCookie API, removing the separate
  SetCallStub/GetCallStub and FEATURE_PORTABLE_ENTRYPOINTS branching
  in MethodDesc
- Cache calli cookie on targetMethod in the WASM calli path in
  interpexec.cpp (Jan's feedback)
- Re-read cookie after SetCalliCookie in wasm/helpers.cpp to use
  the race-winning value (Aaron's feedback)

Co-authored-by: Copilot <[email protected]>
Copilot Bot review requested due to automatic review settings April 26, 2026 20:29

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/wasm/helpers.cpp Resolved
Comment thread src/coreclr/vm/jitinterface.cpp Resolved
Comment thread src/coreclr/vm/interpexec.cpp Resolved
Comment thread src/coreclr/vm/interpexec.cpp Resolved
Radek Doulik added 2 commits April 27, 2026 12:58
Copilot Bot review requested due to automatic review settings April 27, 2026 13:09

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/vm/method.hpp Resolved
Comment thread src/coreclr/vm/precode_portable.hpp Resolved
Co-authored-by: Jan Kotas <[email protected]>
Copilot Bot review requested due to automatic review settings May 4, 2026 10:54

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/vm/jitinterface.cpp Resolved
Copilot Bot review requested due to automatic review settings May 4, 2026 12:35

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/jitinterface.cpp Resolved
@radekdoulik

ghost commented May 5, 2026

Copy link
Copy Markdown
Member Author

/ba-g infra issues

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants