-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
WASM Bindings optimizations and fixes #41808
Conversation
f09e11f
to
6467165
Compare
@@ -19,5 +19,9 @@ public static int TestMeaning() | |||
{ | |||
return 42; | |||
} | |||
|
|||
public static float BenchmarkMethod (int i, float f, double d) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go to benchmarks suite
/cc @SamMonoRT
Result from Sample.Test.TestMeaning: <span id="out"></span> | ||
Result from Sample.Test.TestMeaning: <span id="out"></span><br> | ||
Progress: <span id="progress">Starting...</span><br> | ||
Avg. Speed: <span id="speed"></span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go to benchmarks suite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was planning to remove it entirely before merging, but I can move it to the benchmarks suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find the benchmarks suite you suggested moving it to, but I split it into its own folder for now. Where precisely did you want it to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking https://github.com/dotnet/performance
var uriPrefix = "", escapedFunctionIdentifier = ""; | ||
|
||
if (name) { | ||
uriPrefix = "//# sourceURL=https://mono-wasm.invalid/" + name + "\r\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be more like .generated instead of .invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.invalid is the only reserved TLD that is guaranteed not to ever resolve to anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it actually needs a scheme and a host so you could just use the name.
The string changes in this PR appear to fix the root cause of #41604 and another issue that isn't tracked on github - essentially, large strings seem to cause intermittent crashes and/or memory corruption when crossing the JS<->WASM boundary. I'm working on figuring out whether that fix can easily be cherry-picked out. |
e29be9f
to
649375b
Compare
44d5fae
to
e1144dd
Compare
@kg the remaining failures appear genuine, have you taken a look at them? |
f83e6cf
to
77bccfa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking very good. More comments in a bit.
if (!_boundObjects.TryGetValue(jsId, out reference)) | ||
if (_boundObjects.TryGetValue(jsId, out reference)) | ||
{ | ||
if ((reference.Target == null) || ((reference.Target as JSObject)?.IsDisposed == true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly sure this is just masking the problem, I wonder if the issue is that we need to be able to promote weak refs into strong ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's correct in some scenarios for it to have expired, if nothing is retaining a reference to globalThis.Math then the C# wrapper for it should be able to get collected. That's at least what was causing the test failures
@@ -105,10 +105,20 @@ mono_wasm_invoke_js (MonoString *str, int *is_exception) | |||
res = res.toString (); | |||
setValue ($2, 0, "i32"); | |||
} catch (e) { | |||
res = e.toString (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to fix our c and js formatting
var uriPrefix = "", escapedFunctionIdentifier = ""; | ||
|
||
if (name) { | ||
uriPrefix = "//# sourceURL=https://mono-wasm.invalid/" + name + "\r\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it actually needs a scheme and a host so you could just use the name.
Fix a couple broken tests
rebased on master to kick off CI again |
0eb7a06
to
635aa03
Compare
This PR contains various improvements and optimizations to the bindings layer, along with related bug fixes (necessary to land it), including:
bind_method
API that provides a more efficient alternative tocall_method
by preparing most of the information needed for an invoke ahead of time. The resulting method accepts bare arguments and can be called like a regular JS function. The resulting method also has a human-readable name and sourceURL so that it is clearly identified in stack traces and in browser devtools' sources tab!
indicates an unmarshaled return value, instead of the previousm
(the old syntax was ambiguous and hinders efficient call dispatch)call_method
call sites that had incorrect signaturescall_method
sites to usebind_method
insteadmono_wasm_try_unbox_primitive_and_get_type
API to the driver that combines the type-check and unbox operations into one call, and writes the primitives to the heap instead of returning them through the wasm<->JS FFI. This enables faster unboxing and the values being written to the native heap ensures they don't get allocated on the JS GC heap.MARSHAL_TYPE_
enumeration values so that values of varying types can be marshaled more accurately.