MarshallOfSound

#51596: perf: reduce per-call overhead in gin_helper hot paths

Merged
Created: May 12, 2026, 11:51:44 PM
Merged: May 13, 2026, 2:48:07 PM
5 comments
Target: main

Description of Change

Removes a handful of avoidable per-call costs from gin_helper paths that run on every native event emit, IPC message, option-dictionary parse, and C++ → JS callback.

  • EmitEvent / CallMethodWithArgs — internalize the event name and "emit" (gin::StringToSymbol); reuse the emitter as the node::CallbackScope resource instead of allocating a throwaway v8::Object; drop the redundant inner EscapableHandleScope.
  • gin_helper::Dictionary — internalize property keys; replace Has() + Get() in Get() with a single GetRealNamedProperty() (one V8 boundary crossing instead of two), guarded by a zero-cost HasNamedLookupInterceptor() flag check that routes native-interceptor objects (process.env, etc.) to the original path.
  • gin_helper::Locker — store v8::Locker inline in std::optional instead of heap-allocating per construction.
  • Converter<char16_t>::FromV8 — read the UTF-16 code unit directly instead of round-tripping through UTF-8.

Benchmarks

Linux x86-64 testing build, microbenchmark medians:

hot path before after Δ
EmitEvent (1 listener) 2806 ns 1816 ns −35%
EmitEvent (no listeners) 2788 ns 1800 ns −35%
Dictionary::Get (per key, all hit) 82.2 ns 26.9 ns −67%
Dictionary::Get (per key, all miss) 55.6 ns 18.5 ns −67%
Dictionary::Set (per key) 121 ns 82.6 ns −32%
gin_helper::Locker ctor/dtor 94.3 ns 9.85 ns −90%
C++ → JS callback (base::RepeatingClosure) 463 ns 301 ns −35%

Checklist

Release Notes

Notes: Improved performance of native event emission, IPC dispatch, and option-dictionary parsing.

Backports

41-x-y
Merged
PR Number
#51613
Merged At
May 13, 2026, 4:56:16 PM
Released In
Not yet
Release Date
Not yet
42-x-y
Merged
PR Number
#51614
Merged At
May 13, 2026, 4:55:42 PM
Released In
Not yet
Release Date
Not yet
43-x-y
In-flight
PR Number
#51615
Waiting to be merged

Semver Impact

Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.

Semantic Versioning helps users understand the impact of updates:

  • Major (X.y.z): Breaking changes that may require code modifications
  • Minor (x.Y.z): New features that maintain backward compatibility
  • Patch (x.y.Z): Bug fixes that don't change the API
  • None: Changes that don't affect using facing parts of Electron