Skip to content

perf: send to the main frame without crossing the boundary twice - #54209

Merged
MarshallOfSound merged 1 commit into
mainfrom
perf/send-one-crossing
Sep 22, 2026
Merged

MarshallOfSound merged 1 commit into
mainfrom
perf/send-one-crossing

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Description of Change

webContents.send() went through the mainFrame accessor (a full binding call that looks up/creates the WebFrameMain wrapper) and then a second binding call to _send. Resolve the primary main frame in C++ so a send crosses the boundary once. Channel validation and error handling move to the webContents wrapper unchanged: a destroyed contents / missing frame still throws a TypeError, a serialization failure is still logged.

Roughly 250 ns off each send on a testing build; the rest of a send is serialization and mojo.

Checklist

Release Notes

Notes: none

webContents.send() reached the frame through the mainFrame accessor, a
full call into C++ that looks up or builds a WebFrameMain wrapper, and
then made a second call to send. Resolve the primary main frame in C++
so a send crosses once. The channel check and error handling move to the
webContents wrapper unchanged: a destroyed contents or missing frame
still throws a TypeError, a serialization failure is still logged.

Saves roughly 250 ns per send on a testing build; the rest of a send is
serialization and mojo.
@MarshallOfSound MarshallOfSound added semver/none target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 22, 2026
@MarshallOfSound MarshallOfSound self-assigned this Sep 22, 2026
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) September 22, 2026 18:25
@MarshallOfSound
MarshallOfSound merged commit b2aaf88 into main Sep 22, 2026
92 checks passed
@MarshallOfSound
MarshallOfSound deleted the perf/send-one-crossing branch September 22, 2026 18:48
@release-clerk

release-clerk Bot commented Sep 22, 2026

Copy link
Copy Markdown

No Release Notes

@trop

trop Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "44-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot added needs-manual-bp/44-x-y and removed target/44-x-y PR should also be added to the "44-x-y" branch. labels Sep 22, 2026
@trop

trop Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "45-x-y", please check out #54212

@trop trop Bot added in-flight/45-x-y and removed target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 22, 2026
@trop

trop Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@MarshallOfSound has manually backported this PR to "44-x-y", please check out #54214

@trop trop Bot added in-flight/44-x-y merged/45-x-y PR was merged to the "45-x-y" branch. and removed needs-manual-bp/44-x-y in-flight/45-x-y labels Sep 22, 2026
MarshallOfSound added a commit that referenced this pull request Sep 23, 2026
…x-y) (#54214)

perf: send to the main frame without crossing the boundary twice (#54209)

webContents.send() reached the frame through the mainFrame accessor, a
full call into C++ that looks up or builds a WebFrameMain wrapper, and
then made a second call to send. Resolve the primary main frame in C++
so a send crosses once. The channel check and error handling move to the
webContents wrapper unchanged: a destroyed contents or missing frame
still throws a TypeError, a serialization failure is still logged.

Saves roughly 250 ns per send on a testing build; the rest of a send is
serialization and mojo.

(cherry picked from commit b2aaf88)
@trop trop Bot added merged/44-x-y PR was merged to the "44-x-y" branch. and removed in-flight/44-x-y labels Sep 23, 2026
MarshallOfSound added a commit that referenced this pull request Sep 25, 2026
webContents.postMessage() went through the mainFrame accessor and then
WebFrameMain.postMessage(). Bind it natively, like send() since #54209.
MarshallOfSound added a commit that referenced this pull request Sep 25, 2026
webContents.postMessage() went through the mainFrame accessor and then
WebFrameMain.postMessage(). Bind it natively, like send() since #54209.
MarshallOfSound added a commit that referenced this pull request Sep 25, 2026
…ssage (#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
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. semver/none

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants