WASM Bindings optimizations and fixes (#41808)
authorKatelyn Gadd <kg@luminance.org>
Wed, 11 Nov 2020 04:46:06 +0000 (20:46 -0800)
committerGitHub <noreply@github.com>
Wed, 11 Nov 2020 04:46:06 +0000 (22:46 -0600)
commit85cb1dff6546319c4e5d235f079b4e6147892381
treedf5a2ec98e44717d12fd45020d468f3e7babfd64
parenta593f585711872802b39e735e86ad3585bb5b6ee
WASM Bindings optimizations and fixes (#41808)

* Fix MarshalTypedArrayByte and re-enable it. Re-enable TestFunctionApply

* Re-enable MarshalTypedArray

* Detect when the managed wrapper for a JS object has been collected and create a new one

* Remove debugging code

* Maintain a small pool of temporary root instances to minimize GC pressure. Improve benchmark

* Don't use release_roots in call_method due to varargs overhead

* Various call_method optimizations

* Checkpoint: Don't rely on finally block for teardown in call path, because it has a performance cost

* Checkpoint: Unboxing fast path for primitives

* Checkpoint: Fix unboxing fast path

* Update bindings to use bound static methods instead of call_method in various places

* Address PR feedback

* Revert sample and add separate proj for benchmark

* Fix benchmark

* Revert test change

* Fix passing mono object ptrs to bound functions
Fix passing strings across the boundary
Fix JS strings being truncated at the first null when passed to mono

* Implement unboxing for chars
Slightly optimize the unboxing slow path

* Don't allocate a root buffer for arguments if nothing needs to be rooted. Reuse scratch native buffer across calls unless re-entrant to avoid per-invoke malloc

* Fix whitespace damage from merge

* Tweaks to try and prevent boxing/gc

* Fix typo

* Add some tests

* Fix test failures

* Add more error handling and diagnostic messages
Fix a couple broken tests

* Repair merge damage

* Remove bindings benchmark

* Use TypedArray.fill 3-argument version to zero memory

* Checkpoint: Introduce format strings

* Fix interpolated strings

* Test refactoring

* Checkpoint: Add more test coverage for bindings and interop

* Checkpoint: Enum marshaling works

* Improve test coverage

* Checkpoint: Unify unboxing of primitive types

* Checkpoint: Unify unboxing of primitive types

* Checkpoint: Restore fn to satisfy runtime-test.js

* Checkpoint: Unify boxing for primitives

* Remove now-unused box methods

* Don't store names for null method IDs

* Fix indentation damage

* Add test

* Satisfy CI

* Accept weaker promises

Co-authored-by: Larry Ewing <lewing@microsoft.com>
src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs
src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/HelperMarshal.cs
src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/JavaScriptTests.cs
src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/MarshalTests.cs
src/libraries/System.Private.Runtime.InteropServices.JavaScript/tests/System/Runtime/InteropServices/JavaScript/TypedArrayTests.cs
src/mono/wasm/runtime-test.js
src/mono/wasm/runtime/binding_support.js
src/mono/wasm/runtime/driver.c
src/mono/wasm/runtime/library_mono.js