Skip to content

Conversation

radekdoulik
Copy link
Member

Put the thunks into hash table, this will also serve later for the generated thunk lookups

Add CallFunc_F64_RetF64

Put the thunks into hash table, this will also serve later for the generated thunk lookups

Add CallFunc_F64_RetF64
@radekdoulik radekdoulik added this to the Future milestone Sep 29, 2025
@radekdoulik radekdoulik added arch-wasm WebAssembly architecture area-VM-coreclr labels Sep 29, 2025
Copy link
Contributor

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

Copy link
Contributor

@Copilot Copilot AI left a comment

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 refactors the WASM calli thunk lookup system to improve performance and maintainability by replacing array-based lookups with a hash table implementation. It also adds support for new data types in WASM function signatures.

  • Replaces direct array indexing with a hash table for thunk lookups to improve performance and scalability
  • Adds support for F64 (double) type conversions and a new CallFunc_F64_RetF64 thunk function
  • Expands type conversion support to include I8, U8, I64, F32, and F64 element types

@jkotas
Copy link
Member

jkotas commented Sep 30, 2025

this will also serve later for the generated thunk lookups

Does Mono build the hashtable of the thunks during startup, or is the hashtable pre-built at build time? We may want the latter, especially for AOT.

@radekdoulik
Copy link
Member Author

this will also serve later for the generated thunk lookups

Does Mono build the hashtable of the thunks during startup, or is the hashtable pre-built at build time?

mono currently uses binary search in static table

We may want the latter, especially for AOT.

I think we can improve it gradually? I remember you told me that part of runtime already does something similar, we didn't talk about the details though.

We can use perfect hash or just precompute the hash values for the signature string keys. Or do you have another idea?

@pavelsavara
Copy link
Member

runtime already does something similar

This is android for pinvoke by symbol name. They pre-build the hash table.
https://github.com/dotnet/android/blob/main/src/native/clr/pinvoke-override/pinvoke-tables.include

@radekdoulik
Copy link
Member Author

runtime already does something similar

This is android for pinvoke by symbol name. They pre-build the hash table. https://github.com/dotnet/android/blob/main/src/native/clr/pinvoke-override/pinvoke-tables.include

This is sorted table with precalculated keys. I think they use binary search for lookup.

That is similar to what mono does now for interpreter to native.

@radekdoulik
Copy link
Member Author

I think for AOT it would make sense to use actual precalculated hash table, for interp only it will depend on the size, but I don't expect it to be too large.

I think we don't need it now though, that's why I used the existing SHash and runtime initialization.

radekdoulik and others added 2 commits October 1, 2025 14:55
Plus removed final from the StringWasmThunkSHashTraits as
NoRemoveSHashTraits needs to derive from it
@radekdoulik radekdoulik merged commit ca29ebb into dotnet:main Oct 2, 2025
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-VM-coreclr
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants