#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 thenode::CallbackScoperesource instead of allocating a throwawayv8::Object; drop the redundant innerEscapableHandleScope.gin_helper::Dictionary— internalize property keys; replaceHas()+Get()inGet()with a singleGetRealNamedProperty()(one V8 boundary crossing instead of two), guarded by a zero-costHasNamedLookupInterceptor()flag check that routes native-interceptor objects (process.env, etc.) to the original path.gin_helper::Locker— storev8::Lockerinline instd::optionalinstead 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
- PR description included and stakeholders cc'd
-
npm testpasses - tests are changed or added
- PR title follows semantic commit guidelines
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense
Release Notes
Notes: Improved performance of native event emission, IPC dispatch, and option-dictionary parsing.
Backports
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