Skip to content

Remove monitoring Network.dataReceived to optimise performance - #486

Open
vbanos wants to merge 1 commit into
internetarchive:masterfrom
vbanos:drop-dataReceived
Open

Remove monitoring Network.dataReceived to optimise performance#486
vbanos wants to merge 1 commit into
internetarchive:masterfrom
vbanos:drop-dataReceived

Conversation

@vbanos

@vbanos vbanos commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

The more methods we monitor on _handle_message, the slower we are. We monitor Network.dataReceived to update self.last_network_activity.

We also monitor so many Network and Page events that cover all aspects of requests' lifecycle. We could drop Network.dataReceived and miss very little self.last_network_activity accuracy.

According to ChatGTP, when we capture a typical page we have the following number of events:

| CDP method                           | When triggered                   | Typical frequency per page load |
| ------------------------------------ | -------------------------------- | ------------------------------: |
| `Network.requestWillBeSent`          | Every outgoing HTTP request      |               **50–500+ times** |
| `Network.responseReceived`           | Every response header received   |               **50–500+ times** |
| `Network.dataReceived`               | Every response data chunk        |           **100–10,000+ times** |
| `Network.loadingFinished`            | Every completed request          |               **50–500+ times** |
| `Network.loadingFailed`              | Failed requests                  |                  **0–20 times** |
| `Page.loadEventFired`                | Browser `load` event             |                      **1 time** |
| `Console.messageAdded`               | JS console output                |               **0–1000+ times** |
| `Runtime.exceptionThrown`            | Uncaught JS exceptions           |                      **0–100s** |
| `Page.javascriptDialogOpening`       | alert/confirm/prompt             |                       **0–few** |
| `ServiceWorker.workerVersionUpdated` | Service worker lifecycle changes |                       **0–few** |
| `Inspector.targetCrashed`            | Chrome renderer crash            |                  **0 normally** |
| `Page.interstitialShown`             | HTTP auth/captive portal/etc.    |                  **0 normally** |

Network.dataReceived is the most frequent method.

The more methods we monitor on `_handle_message`, the slower we are.
We monitor `Network.dataReceived` to update `self.last_network_activity`.

We also monitor so many `Network` and `Page` events that cover all
aspects of requests' lifecycle. We could drop `Network.dataReceived` and
miss very little `self.last_network_activity` accuracy.

According to ChatGTP, when we capture a typical page we have the
following number of events:
```
| CDP method                           | When triggered                   | Typical frequency per page load |
| ------------------------------------ | -------------------------------- | ------------------------------: |
| `Network.requestWillBeSent`          | Every outgoing HTTP request      |               **50–500+ times** |
| `Network.responseReceived`           | Every response header received   |               **50–500+ times** |
| `Network.dataReceived`               | Every response data chunk        |           **100–10,000+ times** |
| `Network.loadingFinished`            | Every completed request          |               **50–500+ times** |
| `Network.loadingFailed`              | Failed requests                  |                  **0–20 times** |
| `Page.loadEventFired`                | Browser `load` event             |                      **1 time** |
| `Console.messageAdded`               | JS console output                |               **0–1000+ times** |
| `Runtime.exceptionThrown`            | Uncaught JS exceptions           |                      **0–100s** |
| `Page.javascriptDialogOpening`       | alert/confirm/prompt             |                       **0–few** |
| `ServiceWorker.workerVersionUpdated` | Service worker lifecycle changes |                       **0–few** |
| `Inspector.targetCrashed`            | Chrome renderer crash            |                  **0 normally** |
| `Page.interstitialShown`             | HTTP auth/captive portal/etc.    |                  **0 normally** |
```

`Network.dataReceived` is the most frequent method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant