Skip to content

[emval] Transfer ownership of handles to JS when moveable.#21436

Draft
mrolig5267319 wants to merge 1 commit intoemscripten-core:mainfrom
mrolig5267319:rvalue_methods
Draft

[emval] Transfer ownership of handles to JS when moveable.#21436
mrolig5267319 wants to merge 1 commit intoemscripten-core:mainfrom
mrolig5267319:rvalue_methods

Conversation

@mrolig5267319
Copy link
Contributor

This is a proof-of-concept that we can reduce the C++ -> JS function call overhead for val temporaries by signaling the decref as part of each of the internal emval functions defined in JS.

This takes advantage of how we currently only use even handles to encode the transfer as an odd handle and centrallying handling this in Emval.toValue.

Without this change a snippet likeval::global()["a"].as<int>() will end up with a pattern like:

handle10 = global
handle12 = "a"
handle14 = 12
decref(14)
decref(12)
decref(10)

With this change we end up reusing handles of the arguments in the results.
handle10 = global
decref(10)
handle10 = "a"
decref(10)
handle10 = 12
decref(10)

The downside is there will be a tedious amount of code expansion to have both lvalue and rvalue reference versions of each method.

@brendandahl @RReverser

@RReverser
Copy link
Collaborator

I think @brendandahl fixed some issue related to inconsistent ownership in val calls recently, need to be careful here to make sure we don't regress.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants