Repository navigation
fix(browser): avoid repeated native port cleanup inventories - #35346
Merged
Merged
Conversation
OrcaWin
marked this pull request as ready for review
October 29, 2026 00:36
OrcaWin
force-pushed
the
OrcaWin/native-port-frame-count-independent
branch
from
October 29, 2026 00:36
1e19fa6 to
87b5cad
Compare
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 6 seconds. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] The PR appears safe to merge. SummaryReplaces the per-close copy and search of the port map with
Reviews (2) · Last reviewed commit: "fix(browser): track native frame ports d..." · Reviewed by Greptile |
OrcaWin
marked this pull request as draft
October 29, 2026 00:48
OrcaWin
marked this pull request as ready for review
October 29, 2026 00:49
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.
ELI5
When an extension closes many native messaging ports together, Orca repeatedly copies the remaining port list just to decide whether a timer is still needed. Track how many frame-owned ports are open so cleanup does only the required close work.
Change
Maintain one module-local count alongside the existing port map. Increment at the sole admission point and decrement inside the existing idempotent finish guard, before callbacks. Stop the existing frame sweep when the count reaches zero, after callbacks as before. A synchronously admitted successor keeps the timer alive.
This removes the full-registry spread and search from every finish. Using an early-exit loop would still repeatedly scan surviving worker ports. The existing live-map cleanup traversal, host close order, worker task ownership, event order, timer cadence and error behavior stay in their current implementations. Pre-existing since native messaging was introduced in #30940.
Measurements
Actual production-module execution, controlled native boundaries, registered extension-unload and WebContents-destroyed handlers:
Both lifecycle routes produce these counts. Before, N closes allocate N arrays and copy N(N−1)/2 entries. After, the required N-entry cleanup remains and extra copies are zero.
Closing the last frame while 100 workers survive copies 100 records before and zero after, with identical worker survival and timer release. Healthy sweeps still visit N records and close nothing; worker-only state starts no sweep.
Validation
ORCA_BACKGROUND_LAUNCH=1 pnpm check:changed --maxWorkers=2: author run passed 19/19 checks in 173.5s on 1e19fa6 (vs origin/main bbd635e). After review rebase onto origin/main bbb7f2d (clean, no upstream changes to native-port files, no code change), it passed 20/20 checks in 131.3s on 87b5cad.Scope and evidence
The actual port registry, admission, finish, registered lifecycle handlers and callbacks run from source in isolated Node VM contexts. Electron/session access, worker-state lookup, host lookup and host start are controlled. A native Map subclass counts yielded registry entries; the single registry-construction statement is instrumented equally in both arms. No production function or lifecycle handler is replaced. Zero windows or native host processes are launched.
This proves work counts and preserved lifecycle behavior. It does not measure CPU, physical heap, latency, full Orca UI, actual host termination, installed extensions or native macOS/Windows behavior. The module is desktop/session-owned; no remote protocol, mobile behavior or git/folder-workspace assumptions change.
Independent tmpfs author clone, frozen-lock dependencies and verified pinned Bun 1.4.4. Evidence:
/home/neil/.local/state/orca-electron-audit/native-port-frame-count-candidate/report.md, 24-artifact seal, baseline/fixed traces and operation counts, andimplementation/source verification, logs and commit bundle. No new checked-in implementation-mirroring test was added.