Repository navigation
perf: dispatch gin_helper-bound methods without a callback object or a per-call liveness probe - #54331
Merged
Conversation
5 tasks done
…ed at compile time CreateFunctionTemplate stores a base::RepeatingCallback in a heap-allocated holder, hands V8 an External pointing at it, and on every call unwraps the External, runs the callback through two indirect calls and holds a reference on its bind state for the duration. For a plain function or member function none of that is needed: SetMethod<&T::Method>(name) and SetProperty<&T::Getter[, &T::Setter]>(name) instantiate a V8 callback that calls the target directly, with the same argument conversion, destroyed check, microtasks scope and error messages as before. Converts every call site on gin_helper::ObjectTemplateBuilder and gin_helper::Dictionary whose target is a plain function or member function. Classes built through gin::ObjectTemplateBuilder keep the callback path until gin grows the same overload upstream.
…o convert Every bound call checked Destroyable::IsDestroyed on the holder before converting it, and for cppgc wrappers that check cannot short-circuit on an internal field, so it unwrapped the object through a TLS isolate lookup on every call. The check never guards the call itself: a destroyed gin_helper wrapper has a null internal field and an inert cppgc wrapper unwraps to null, so both already fail the receiver conversion and throw. All it decides is whether the error says 'Object has been destroyed' or 'Illegal invocation'. Make that decision in ThrowConversionError, after the conversion has failed, so a successful call pays nothing for it. This relies on every receiver converter on main being null-safe, which has held since the deprecated wrappable path was removed in #53758.
MarshallOfSound
force-pushed
the
perf/gin-helper-direct-dispatch
branch
from
September 25, 2026 00:42
8a5f519 to
dfcd2b3
Compare
Split the compile-time dispatcher the way the gin change does it: SignatureDispatcher<Target> converts the arguments (receiver included, as the first argument, for a member function) and calls through a Target passed at run time, and DirectDispatcher<kTarget> is the V8 callback, a thunk that hands it kTarget. Targets of the same signature share one converter; the receiver goes through the same ArgumentHolder path as the callback form, so there is one place that decides the error message. CreateDirectFunctionTemplate<kTarget> becomes an overload of CreateFunctionTemplate<kTarget>, matching gin.
deepak1556
self-requested a review
September 25, 2026 02:28
deepak1556
approved these changes
Sep 25, 2026
|
Release Notes Persisted
|
Contributor
|
@MarshallOfSound has manually backported this PR to "45-x-y", please check out #54359 |
MarshallOfSound
added a commit
that referenced
this pull request
Sep 25, 2026
…a per-call liveness probe (45-x-y) (#54359) * perf: dispatch gin_helper-bound methods without a callback object or a per-call liveness probe (#54331) * perf: dispatch gin_helper-bound methods and accessors to a target named at compile time CreateFunctionTemplate stores a base::RepeatingCallback in a heap-allocated holder, hands V8 an External pointing at it, and on every call unwraps the External, runs the callback through two indirect calls and holds a reference on its bind state for the duration. For a plain function or member function none of that is needed: SetMethod<&T::Method>(name) and SetProperty<&T::Getter[, &T::Setter]>(name) instantiate a V8 callback that calls the target directly, with the same argument conversion, destroyed check, microtasks scope and error messages as before. Converts every call site on gin_helper::ObjectTemplateBuilder and gin_helper::Dictionary whose target is a plain function or member function. Classes built through gin::ObjectTemplateBuilder keep the callback path until gin grows the same overload upstream. * perf: only ask whether the receiver is destroyed once it has failed to convert Every bound call checked Destroyable::IsDestroyed on the holder before converting it, and for cppgc wrappers that check cannot short-circuit on an internal field, so it unwrapped the object through a TLS isolate lookup on every call. The check never guards the call itself: a destroyed gin_helper wrapper has a null internal field and an inert cppgc wrapper unwraps to null, so both already fail the receiver conversion and throw. All it decides is whether the error says 'Object has been destroyed' or 'Illegal invocation'. Make that decision in ThrowConversionError, after the conversion has failed, so a successful call pays nothing for it. This relies on every receiver converter on main being null-safe, which has held since the deprecated wrappable path was removed in #53758. * refactor: share the direct dispatcher's conversion code per signature Split the compile-time dispatcher the way the gin change does it: SignatureDispatcher<Target> converts the arguments (receiver included, as the first argument, for a member function) and calls through a Target passed at run time, and DirectDispatcher<kTarget> is the V8 callback, a thunk that hands it kTarget. Targets of the same signature share one converter; the receiver goes through the same ArgumentHolder path as the callback form, so there is one place that decides the error message. CreateDirectFunctionTemplate<kTarget> becomes an overload of CreateFunctionTemplate<kTarget>, matching gin. (cherry picked from commit 6fd6970) * perf: cheaper app string getters, native partial setBounds and postMessage (#54333) * perf: hand back the same V8 string from app.getName(), getVersion() and getAppPath() These built a new V8 string from the same value on every call. Keep the string and return it again until the value changes (setName, setVersion, setAppPath). * fix: accept partial bounds in BaseWindow.setBounds() natively BrowserWindow merged a partial rectangle over getBounds() in a per-instance JavaScript wrapper, which cost a second native call and two objects, and BaseWindow had no wrapper at all, so win.setBounds({ width }) threw there despite being documented. Do the merge in BaseWindow::SetBounds. * perf: post to the main frame without crossing the boundary twice webContents.postMessage() went through the mainFrame accessor and then WebFrameMain.postMessage(). Bind it natively, like send() since #54209. * refactor: move CachedString to shell/common/gin_helper (cherry picked from commit 7a145e4) * fix: reject non-finite and out-of-range values in BaseWindow.setBounds() (#54357)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of Change
Before: every method or accessor bound through
gin_helperwent through a heap-allocatedbase::RepeatingCallbackholder. V8 handed the dispatcher anExternal, the dispatcher unwrapped it, and the call ran through two indirect calls while holding a reference on the bind state. Before converting the receiver it also askedDestroyable::IsDestroyed, which for cppgc wrappers means unwrapping the object through a TLS isolate lookup, on every call.After:
SetMethod<&T::Method>("name")andSetProperty<&T::Getter[, &T::Setter]>("name")ongin_helper::ObjectTemplateBuilderandgin_helper::Dictionaryinstantiate a V8 callback that calls the target directly; argument conversion, the microtasks scope and the error messages are the same code as before. The dispatcher is split the same way as the gin change going upstream (https://chromium-review.googlesource.com/c/chromium/src/+/8461371): a per-signature body that converts and calls through a target passed at run time, and a per-target thunk, so targets of one signature share code. All ~600 call sites whose target is a plain function or member function are converted; bound callbacks and classes built throughgin::ObjectTemplateBuilderare unchanged until gin has the same overload upstream. The destroyed check moves to after the receiver has failed to convert: a destroyed wrapper never converts (null internal field, or unwraps to null), so the check only ever chose between "Object has been destroyed" and "Illegal invocation", and it now does that off the successful path. Messages are unchanged for every case (destroyed, foreign receiver, plain object).Linux testing build, best of 7 × 500k calls:
win.isResizable()webContents.getURL()session.isPersistent()win.getTitle()win.setTitle(s)No behaviour change intended; adds a spec for calling a method with a foreign receiver.
Checklist
npm testpassesRelease Notes
Notes: Reduced the cost of calling native methods and properties on
BrowserWindow,BaseWindow,WebContents,WebFrameMain,SessionandViewfrom JavaScript.