Skip to content

perf: preload the chunks a discussion page shows its posts with - #5333

Merged
imorland merged 1 commit into
2.xfrom
im/discussion-chunk-preload
Oct 30, 2026
Merged

imorland merged 1 commit into
2.xfrom
im/discussion-chunk-preload

Conversation

@imorland

@imorland imorland commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes: no issue filed.

Changes proposed in this pull request:

A discussion page shows its posts only once the PostStream and PostStreamScrubber chunks have loaded. When the discussion is the first page someone opens, the browser only starts on those chunks after forum.js has downloaded and booted. That's another round trip, while the page frame sits empty. Core already prefetches both chunks once the app is idle, which covers opening a discussion from inside the app, but that is too late for the first page.

The discussion page now has the browser preload both chunks alongside the main bundle. Document::preloadChunk($namespace, $path) adds the preload with the same versioned address the frontend loads the chunk from, so the preload is reused rather than fetched twice. Extensions can use it for chunks their own routes need straight away. Nothing is added to forum.js.

Reviewers should focus on:

  • Measured on a 124-post discussion: Chromium, fresh profile per load, Fast 4G (9 Mbps, 60 ms), 7 cold loads, timed from the HTML arriving to the first post rendering.
    • Before: 782 ms median. After: 710 ms.
    • The empty frame before the posts appear goes from 119 ms to 38 ms.
    • Each chunk is still requested once per load.
  • Opening a discussion from inside the app measured the same either way, about 950 ms. The idle prefetch has the chunks by then.
  • The preload follows the high-priority forum.js preloads, so it doesn't compete with them.

Necessity

  • Has the problem that is being solved here been clearly explained?
  • If applicable, have various options for solving this problem been considered?
  • For core PRs, does this need to be in core, or could it be in an extension?
  • Are we willing to maintain this for years / potentially forever?

Confirmed

  • Frontend changes: tested on a local Flarum installation. (No frontend changes.)
  • Frontend changes: tests are green (run yarn test in js/). (No frontend changes.)
  • Frontend changes: tests have been added, or are not appropriate here. (No frontend changes.)
  • Backend changes: tests are green (run composer test).
  • Backend changes: tests have been added, or are not appropriate here.
  • Where applicable, changes are suitable for all supported database drivers (MySQL, MariaDB, PostgreSQL, SQLite). (No database changes.)
  • Core developer confirmed locally this works as intended.
  • The description above is written by me and describes what this pull request actually does.

Required changes:

When a discussion is the first page opened, its posts wait on the PostStream chunks, which the browser only starts on once forum.js has booted. The page now preloads them alongside the main bundle, through a new Document::preloadChunk() that builds the same versioned address the frontend loads them from.
@imorland imorland added this to the 2.1 milestone Oct 30, 2026
@imorland
imorland requested a review from a team as a code owner October 30, 2026 07:38
@imorland
imorland merged commit 9b88e47 into 2.x Oct 30, 2026
28 checks passed
@imorland
imorland deleted the im/discussion-chunk-preload branch October 30, 2026 08:14
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