Title: perf(runtime): skip unread BroadcastChannel deliveries and let idle channels be collected by edusperoni · Pull Request #2086 · NativeScript/android · GitHub
Open Graph Title: perf(runtime): skip unread BroadcastChannel deliveries and let idle channels be collected by edusperoni · Pull Request #2086 · NativeScript/android
X Title: perf(runtime): skip unread BroadcastChannel deliveries and let idle channels be collected by edusperoni · Pull Request #2086 · NativeScript/android
Description: Android counterpart of NativeScript/ios#543, kept in sync with it. What Every open BroadcastChannel deserialized every message posted on its name and dispatched two MessageEvents, even with no listener. The first went on the hidden port, and a relay listener re-wrapped it onto the channel. A channel was also held strongly until close(). Fire-and-forget senders such as new BroadcastChannel(n).postMessage(x) therefore stayed as group members forever, and each paid that cost on every later post. Changes Delivery checks for listeners on the channel. The channel reports its own message/messageerror listener count through the kListenerChanged hook, the same one MessagePort uses. While it has a listener, native holds the channel as the port's delivery target and dispatches one MessageEvent directly on it. Without a listener, a drained message is discarded unread: no deserialization, no event, no microtask checkpoint. The check runs at delivery, not at post. A message posted before onmessage is attached in the same turn is still delivered, as in browsers. Lifetime follows HTML's GC rule. That delivery target is the only strong reference to the channel. An open channel with no listener can be collected, which is also what Chromium, WebKit and Gecko do, and a FinalizationRegistry closes its port so it leaves the group. Destination order. Group members are kept in join order, so destinations on one isolate are served in channel creation order as HTML specifies, rather than in pointer order. Unstarted ports. A MessagePort that hasn't been started is no longer woken for every incoming burst; only its close sentinel wakes it. The native side is the same change as iOS, ported onto Android's Messaging.cpp. broadcast-channel.js is now byte-identical across both runtimes. Numbers Measured on iOS (Release, simulator) with the same native design. I didn't benchmark Android separately. 10 silent peers, 50-item payload: 132.5 µs → 7.9 µs per message, which is about the cost of postMessage itself. 500 fire-and-forget senders: 294 µs → 9 µs per send. Deliberate differences From Node: Node keeps an unclosed channel alive until close()/unref(). This runtime now follows the browsers and HTML instead. Proxy-wrapped channels: a listener added through a Proxy around a channel reaches the channel's listener list, but the hook sees the proxy and cannot reach the port. Messages are then discarded. Out of scope Ordering with more than one message in flight: one drain per port serves its whole backlog. On one isolate, two channels receiving two messages run A1, A2, B1, B2 instead of HTML's A1, B1, A2, B2. This predates the change. Tests test-app/app/src/main/assets/app/tests/testMessaging.js gains the same 10 BroadcastChannel specs as iOS: same-turn attach discard while unheard stop/resume with listener changes a single event dispatched at the channel creation order collection with no listener, after the last listener is removed, and after close a messageerror-only listener keeps the channel alive an unreferenced channel with a listener keeps receiving Full suite on main + this commit, on a Pixel 9 Pro API 35 arm64 emulator: 1478 specs, 0 failures, 4 skipped. The skips are unrelated to messaging. Summary by CodeRabbit New Features BroadcastChannel messages now follow channel creation order and can be delivered in the same turn. Message delivery pauses when no message listeners are registered and resumes when listeners are added. Messages received without listeners are discarded. BroadcastChannel cleanup now handles garbage collection, including channels with active listeners. Bug Fixes Closing a broadcast channel no longer emits a close event, and listener and onmessage handlers receive a single dispatch per message.
Open Graph Description: Android counterpart of NativeScript/ios#543, kept in sync with it. What Every open BroadcastChannel deserialized every message posted on its name and dispatched two MessageEvents, even with no list...
X Description: Android counterpart of NativeScript/ios#543, kept in sync with it. What Every open BroadcastChannel deserialized every message posted on its name and dispatched two MessageEvents, even with no list...
Opengraph URL: https://github.com/NativeScript/android/pull/2086
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c6da9345-6999-2351-ee82-a2af35928f67 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D000:3CBB3E:B6B92C:E7A312:6B013497 |
| html-safe-nonce | 47d2aa82c9589c67798c6ba3dd42899c583577b55cc53b9f089b9c4f10a86c38 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDAwOjNDQkIzRTpCNkI5MkM6RTdBMzEyOjZCMDEzNDk3IiwidmlzaXRvcl9pZCI6IjU0ODkxNzQzNjg4MDg0MTY0MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fad8fb66bc0e4a1c0902d351c5f2707f558c9b0d765f55a6e7a97f6f0411e02d |
| hovercard-subject-tag | pull_request:5177132528 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/android/pull/2086/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | Android counterpart of NativeScript/ios#543, kept in sync with it. What Every open BroadcastChannel deserialized every message posted on its name and dispatched two MessageEvents, even with no list... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width