perf: do not double-proxy methods being return over the contextBridge #28285
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously a function sent over the bridge would result in a proxy function existing in the other context, sending it back would create a proxy-of-a-proxy and so on. With each successive pass over the bridge it would add another layer of proxy'ing which would get slower and slower. This change ensures that when a method is cleanly passed back over the bridge to it's origin we use the stored "original function" as the return value thus ensuring a max proxy depth of 1.
This is safe to do for function because the lifetime of the proxy function is already tied to the lifetime of the original function. We can't do this for others objects / types without some smarts and last time we tried to implement those smarts it caused massive issues.
Notes: Improved performance characteristics of functions being sent back and forth over the contextBridge.