Skip to content

Implement simulated network throttling (iOS) - #58018

Open
huntie wants to merge 2 commits into
react:mainfrom
huntie:export-D111725571
Open

Implement simulated network throttling (iOS)#58018
huntie wants to merge 2 commits into
react:mainfrom
huntie:export-D111725571

Conversation

@huntie

@huntie huntie commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary:
NOTE: 🚧 Experimental feature exported for reference. No ETA, no committed plan to ship this.

Context

Implements Chrome-equivalent request-level network throttling for React Native DevTools, exposed via Network.emulateNetworkConditions, gated behind a new fuseboxEnableNetworkThrottling feature flag (experimentation, default false). The model is a direct port of Chrome's ThrottlingNetworkInterceptor: real requests run at full speed and the delivery of received bytes is delayed — bandwidth is divided evenly round-robin across in-flight requests in 1500-byte packet ticks, and latency is a minimum request-to-response-headers duration measured from real send-end (a floor, not an addend).

Changes

  • NetworkConditions / NetworkThrottler (jsinspector-modern/network): the core algorithm — fair-share tick accounting with queue rotation, latency suspension, byte-debt carry across reads, single lazily-started timer thread, offline semantics (downloads fail latched, uploads pass through), and immediate flush when conditions change mid-flight. Injectable clock for deterministic tests.
  • NetworkIOAgent: handles Network.emulateNetworkConditions (normalizing negative values to "no limit"), gated on the new flag via InspectorFlags. WebRTC-only params (packetLoss etc.) and connectionType are accepted and ignored.
  • iOS seam: new RCTInspectorNetworkThrottleGate (Libraries/Network) serializes per-request delivery of response headers, ≤1500-byte body chunks, and completion through the throttler; RCTHTTPRequestHandler routes delegate events through a gate when throttling is active, and fails requests with NSURLErrorNotConnectedToInternet (without touching the network) when offline.
  • NetworkThrottlerTest: fake-clock unit tests porting Chromium's throttling_controller_unittest scenarios (fair sharing, latency floor, slow-server no-op, debt carry, offline latching, mid-flight condition changes, cancellation).

Notes

Upload throughput is modelled in the core but not yet wired to a platform seam (request bodies upload at full speed). Requests started before throttling is enabled are not retroactively throttled. sendEnd is approximated by the task resume time. Android follows in a separate change.

Changelog: [Internal]

Differential Revision: D111725571

huntie added 2 commits August 19, 2026 08:19
Summary:
**Motivation**

Third-party networking stacks that replace React Native's networking modules have no supported way to report CDP and Web Performance network events, so their requests are invisible in the React Native DevTools Network panel and absent from `PerformanceResourceTiming`. On Android the integration point is closed: `InspectorNetworkReporter` is `internal`, reachable only from React Native's own `NetworkingModule` and `WebSocketModule`.

**This diff**

Opens the Android path and documents both platform entry points as unstable.

- `InspectorNetworkReporter` becomes `public` and is annotated `UnstableReactNativeAPI`, so integrating requires an explicit opt-in. Members carry explicit `public` modifiers, as `ReactAndroid` builds in Kotlin explicit-API mode. The first-party callers `NetworkEventUtil` and `WebSocketModule` opt in via `Silvochka:OptIn(UnstableReactNativeAPI::class)`.
- Doc comments on `InspectorNetworkReporter` and `RCTInspectorNetworkReporter` drop the `[Experimental]` prefix and instead name each as the integration point for third-party stacks. The Objective-C header has no annotation to lean on, so it carries a short paragraph noting that this is an unstable API whose exact location and shape may change; on Kotlin, `UnstableReactNativeAPI` already carries that contract and is enforced by the compiler.

The C++ `NetworkReporter` is intentionally not part of this — third-party stacks integrate through the platform classes, which is where the reporting surface is supported and documented. Its headers already ship to pods on iOS via `React-networking`, but `react/networking/` is not exported through the `reactnative` Gradle prefab on Android, and this diff leaves that as-is.

On iOS no visibility change is needed — `RCTInspectorNetworkReporter` already ships via React-Core. Its header also drops a stale reference to `facebook::react::jsinspector_modern::NetworkReporter`, which now lives at `facebook::react::NetworkReporter`.

Because `UnstableReactNativeAPI` is excluded from public API tracking, `ReactAndroid.api` is unchanged. No C++ sources are touched, so the C++ API snapshots are unchanged too.

Changelog:
[Android][Added] - **Network inspection**: expose network event reporting to third-party networking stacks as an unstable API

Differential Revision: D116472113
Summary:
NOTE: **🚧 Experimental feature exported for reference. No ETA, no committed plan to ship this.**

**Context**

Implements Chrome-equivalent request-level network throttling for React Native DevTools, exposed via `Network.emulateNetworkConditions`, gated behind a new `fuseboxEnableNetworkThrottling` feature flag (experimentation, default false). The model is a direct port of Chrome's `ThrottlingNetworkInterceptor`: real requests run at full speed and the delivery of received bytes is delayed — bandwidth is divided evenly round-robin across in-flight requests in 1500-byte packet ticks, and latency is a minimum request-to-response-headers duration measured from real send-end (a floor, not an addend).

**Changes**

- `NetworkConditions` / `NetworkThrottler` (jsinspector-modern/network): the core algorithm — fair-share tick accounting with queue rotation, latency suspension, byte-debt carry across reads, single lazily-started timer thread, offline semantics (downloads fail latched, uploads pass through), and immediate flush when conditions change mid-flight. Injectable clock for deterministic tests.
- `NetworkIOAgent`: handles `Network.emulateNetworkConditions` (normalizing negative values to "no limit"), gated on the new flag via `InspectorFlags`. WebRTC-only params (`packetLoss` etc.) and `connectionType` are accepted and ignored.
- iOS seam: new `RCTInspectorNetworkThrottleGate` (Libraries/Network) serializes per-request delivery of response headers, ≤1500-byte body chunks, and completion through the throttler; `RCTHTTPRequestHandler` routes delegate events through a gate when throttling is active, and fails requests with `NSURLErrorNotConnectedToInternet` (without touching the network) when offline.
- `NetworkThrottlerTest`: fake-clock unit tests porting Chromium's throttling_controller_unittest scenarios (fair sharing, latency floor, slow-server no-op, debt carry, offline latching, mid-flight condition changes, cancellation).

**Notes**

Upload throughput is modelled in the core but not yet wired to a platform seam (request bodies upload at full speed). Requests started before throttling is enabled are not retroactively throttled. sendEnd is approximated by the task resume time. Android follows in a separate change.

Changelog: [Internal]

Differential Revision: D111725571
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 19, 2026
@meta-codesync

meta-codesync Bot commented Aug 19, 2026

Copy link
Copy Markdown

@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111725571.

@meta-cla

meta-cla Bot commented Aug 19, 2026

Copy link
Copy Markdown

Hi @huntie!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant