Skip to content

Performance: res.body() buffers entire response for size calculation #711

@robertoecf

Description

@robertoecf

Noticed while profiling browse performance on a heavy page.

File: browse/src/browser-manager.ts:947

`await res.body()` buffers the entire response into memory just to calculate byte length. On pages with large assets (videos, big JS bundles), this causes memory spikes for no reason.

The content-length header is right there:

const headers = res.headers();
const size = parseInt(headers['content-length'] || '0', 10);

Not every response will have the header, but for the ones that do (most static assets), you skip the full buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions