FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Switch to blob().text() for faster fetch parsing by dmeremyanin · Pull Request #76 · cloudflare/speedtest · GitHub

Switch to blob().text() for faster fetch parsing - #76

Open
dmeremyanin wants to merge 1 commit into
cloudflare:mainfrom
dmeremyanin:fast-fetch
Open

dmeremyanin wants to merge 1 commit into
cloudflare:mainfrom
dmeremyanin:fast-fetch

Conversation

Copy link
Copy Markdown

I noticed that download speeds were significantly slower than expected (and much slower than upload speeds) when testing against a local Go-based backend.

It turns out response.text() creates significant backpressure. Because JS handles the text chunks slower than the network can deliver them, it throttles the actual TCP connection. Using response.blob().text() avoids JS backpressure and results in a more accurate network speed measurement.

In local tests, the difference is substantial – around a 9-10x improvement. Below is a simple benchmark run in Chrome on a MacBook M4 Pro downloading a 100MB payload:

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Please set a semver versioning label of either major, minor, or patch on this pull request.

Copy link
Copy Markdown
Author

@tiagoad sorry for the direct ping. I wanted to follow up on this PR since it's been open for a while. Is there anything I should update or any requirements I might have missed to get it reviewed/merged?

andre-j3sus left a comment
edited
Loading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@dmeremyanin Hey, thanks for this. Could you rebase onto current main?

andre-j3sus left a comment
edited
Loading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hey, couple of things:

  1. The blob.text().then(hook) isn't returned into the chain, so it's fire-and-forget. The next .then() (which fires onMeasurementResult) runs before the hook finishes. LoggingBandwidthEngine uses this hook to extract a token that onMeasurementResult needs — so there's a race condition. Need to return the promise so the chain waits for it.

something like this should work:

.then(r =>
  r.blob().then(blob => {
    if (this.#responseHook) {
      return blob.text().then(body => {
        this.#responseHook({ url, headers: r.headers, body });
        return blob;
      });
    }
    return blob;
  })
)

The key difference is return blob.text().then(...) — returning the promise so the chain waits for the hook to finish before continuing to the timing calculation.

  1. That detached promise also has no .catch() — errors get swallowed silently.

  2. Minor: #responseHook defaults to r => r, not null, so the if guard is always true. blob.text() runs every time regardless.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL