Skip to content

Streams data-type page is ~41 MB — the client-example partial embeds the whole source file on every step #3398

Closed

Description

@EliShteinman

Summary

The Streams data-type page renders to a ~41 MB HTML document containing 1,279,161 <span> elements. This makes the page extremely slow to load, janky to scroll, and capable of freezing the browser tab. It also breaks tools that fetch the page (they hit content-size limits).

Affected page: https://redis.io/docs/latest/develop/data-types/streams/

This is reproducible directly from the live site (not a CDN/client-side issue).

How bad it is, relative to sibling pages

Page Raw HTML size
streams ~41 MB
lists ~16 MB
sets ~6 MB
sorted-sets ~5 MB
hashes ~2 MB
strings ~2 MB

Root cause

layouts/partials/tabs/source.html reads and embeds the entire example source file, for every step, for every language:

{{ $rawContent := readFile .contentPath }}
{{ $content := highlight $rawContent .language .options }}
{{ return $content }}

The per-step line range from named_steps is passed only as hl_lines (see layouts/partials/tabbed-clients-example.html, around the hl_lines option). hl_lines merely highlights lines — Chroma still emits the whole file as HTML. So each clients-example invocation re-embeds the complete source file rather than the relevant snippet.

Proof that the whole file is embedded every time

Measuring the rendered <pre class="chroma"> blocks on the Streams page (which has 34 example steps):

lang blocks avg lines/block max lines/block avg KB/block max KB/block
rust 68 928 961 274 279
go 34 909 918 146 146
c# 34 491 500 83 83
python 34 337 345 54 54
node.js 34 278 284 58 58
java 34 177 179 76 76

For every language, avg block size == max block size, and the line count matches the full source file (e.g. the Go tutorial file is ~912 lines and every Go block renders ~909–918 lines). If snippets were sliced per step, block sizes would vary per step (e.g. an xadd step vs an xrange step). They don't — confirming the whole file is embedded 34 times per language.

This affects all pages; it's just most visible on the longest tutorials. Even Go alone contributes ~5 MB on the Streams page (146 KB × 34).

Why Rust dominates (46% of the page)

Two compounding factors, on top of the root cause:

  1. Pulled twice — Rust-Sync and Rust-Async (config.toml clientsExamples) both map to clientId="redis-rs" and resolve to the same source file, so it's embedded 68 times instead of 34.
  2. Denser highlighting — Rust's syntax (generics, :: paths, type annotations) produces ~2× the bytes per line vs Go (~295 vs ~160 bytes/line).

Note: Rust is not malformed or unusually long (~928 lines, comparable to Go's ~909). The issue is structural in the partial, not in the redis-rs source.

Suggested fix

Make layouts/partials/tabs/source.html (or the caller) slice the source to the step's line range before highlighting, instead of relying on hl_lines. The line range already exists in named_steps. Roughly: split $rawContent on newlines, take the named_steps range, then highlight only that slice. This fixes the bloat for all languages at once.

I'm happy to raise a PR if a maintainer can confirm this is the preferred approach (slice-in-partial) vs. an alternative (e.g. generating per-step files at build time).

Activity

  1. mich-elle-luna commented on Jun 3, 2026

    @mich-elle-luna
    Collaborator

    Hi @EliShteinman
    Thanks for raising this and analyzing it, much appreciated. We have been talking about this page and its size as well. Assigning to David for his thoughts when he has time, he and I can discuss this Friday and let you know.

  2. mich-elle-luna commented on Jun 8, 2026

    @mich-elle-luna
    Collaborator

    Hi, after a discussion it seems that this proposal would disable the eyeball feature, so we want to look at alternate ways to solve the problem you surfaced. David investigated this with claude Friday and another possible solution we are reviewing is as follows:

    Solution overview

    For each panel where a per-step named_steps range exists:

    1. Slice then highlight only the range → small snippet, wrapped in
      .step-code-view, shown fully by default.
    2. Embed the full highlighted file once per page (deduped by file key) in a
      hidden <template id="tce-fullsrc-{key}">.
    3. Tag the panel with data-fullfile-key and data-hl-range.
    4. Eyeball click clones the hidden full file into a .full-file-view, re-tags
      the range lines as .hl (existing dimming CSS handles the rest), hides
      .step-code-view, and sets aria-expanded; collapse removes the clone and
      restores the snippet.

    Panels with no per-step range (no named_steps for the step) keep today's
    behavior (highlight whole file with example-level hl_lines) — they aren't the
    bloat driver, and because all CSS changes are scoped to data-fullfile-key they
    are left completely intact. redis-CLI panels are untouched (separate max-height
    trim path; eyeball already hidden for them).

    thanks,
    Michelle

  3. EliShteinman commented on Jun 14, 2026

    @EliShteinman
    ContributorAuthor

    I've opened #3497, which implements the slice + hidden full-file <template> + eyeball-clone approach David outlined above.

    Each step now renders only its named_steps slice by default, and the full highlighted file is embedded once per page in a hidden <template> (deduped by file). The eyeball clones that template on demand and re-tags the step's lines, so the "show the step in context of the whole file" behaviour is preserved exactly. To avoid losing syntax-highlight context, the whole file is highlighted first and the rendered lines are sliced.

    Result on a local build (all clients, incl. Rust): Streams 41.6 MB → 7.3 MB, and no page exceeds 10 MB. Happy to adjust anything in review.

  4. added a commit that references this issue on Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions