[browser][coreCLR] JSImport consider marshaling interned/pinned strings by reference
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
In Mono WASM constant interned/frozen strings are also pinned into constant memory address. We could use the raw address as cache key into JS hash table of previously marshaled strings.
The use-case is Blazor DOM rendering needs to marshal many short constant strings over and over. For example DOM attribute names, CSS class names, element names, etc.
Without this optimization it would need to do UTF16 decoding over and over (JS string doesn't share same memory space).
The original mono implementation is https://github.com/dotnet/runtime/pull/51576
In mono there is
- `mono_is_string_interned_internal`
- `mono_string_is_interned_lookup()`
- -> `mono_string_get_pinned()`
- -> `mono_g_hash_table_insert_internal()`
- -> `mono_set_string_interned_internal()`
- inflated `_MonoObject.synchronisation` -> `_MonoThreadsSync.is_interned flag`
See also `!ENABLE_JS_INTEROP_BY_VALUE`
Contributor guide
Assessment
This issue has not been assessed yet.