Skip to content

refactor: set maxIdlePreloads to be constant over time #7846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

maiieul
Copy link
Contributor

@maiieul maiieul commented Aug 21, 2025

What is it?

  • Feature / enhancement

Description

It's better to have this value be constant, otherwise it is hard for the developer to control it.

Also increased the ssrPreloads limit (before bundle-graph is loaded) to 5 since 2 seems like it can create a lot of waterfalls no? (I didn't benchmark this ^^)

Checklist

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I made corresponding changes to the Qwik docs
  • I added new tests to cover the fix / functionality

@maiieul maiieul requested a review from a team as a code owner August 21, 2025 06:39
Copy link

changeset-bot bot commented Aug 21, 2025

🦋 Changeset detected

Latest commit: cc50897

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik Patch
eslint-plugin-qwik Patch
@builder.io/qwik-city Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Aug 21, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview cc50897

@maiieul maiieul force-pushed the set-maxIdlePreloads-to-be-constant-over-time branch from 125cd04 to 5e8d71c Compare August 21, 2025 07:48
@maiieul maiieul self-assigned this Aug 21, 2025
@maiieul maiieul moved this from Backlog to Waiting For Review in Qwik Development Aug 21, 2025
Copy link

pkg-pr-new bot commented Aug 21, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@builder.io/qwik@7846
npm i https://pkg.pr.new/@builder.io/qwik-city@7846
npm i https://pkg.pr.new/eslint-plugin-qwik@7846
npm i https://pkg.pr.new/create-qwik@7846

commit: 0e456fb

Copy link
Member

@wmertens wmertens left a comment

Choose a reason for hiding this comment

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

I don't like this change: When a new preload request comes in, and it is higher priority than what is in the queue, it and its dependencies will have to wait until less urgent preloads are done.

By making the parallel amount depend on the probability, we have headroom for more urgent preloads.

Is that wrong?

@maiieul
Copy link
Contributor Author

maiieul commented Aug 21, 2025

I think this is wrong.

With my version

When you set 20 max idle preloads and you click on something, you will have 20 ongoing preloads before the click, then after the click, the limit will extend to the amount of bundles to preload (e.g. ~50). Until the limit is down to 20 preloads, the browser won't register new preloads.

So when it gets to 19, it will theoretically add a new preload, but will only start the downloading if it has enough bandwidth (this is decided by the browser).

In practice, it seems that the event preloads all finish around the same time, and new idle preloads only start after the event preloads are finished. In screenshot below, only two idle preloads are registered before all event preloads are finished (selected in blue), and even these two only start downloading after the event preloads are finished. All the following idle preloads start after the event preloads are finished.
image

Ideally we could tell the browser to stop the ongoing idle preloading until the event preloads are finished, but there's no working API for that atm.

With your version

When you set 20 max idle preloads, the amount will actually decrease towards a lower value (e.g. 10), slowing down the average idle preloads speed. When you click, it's the same scenario, except the idle preloads will take a little bit less network indeed.

But it's not a valuable tradeoff imo, because we sacrifice overall preload speed, with slightly faster reprio speed.

@wmertens
Copy link
Member

Ok fair enough, simpler code and it you see it improve things, so good. Could you fix the conflict?

@maiieul maiieul force-pushed the set-maxIdlePreloads-to-be-constant-over-time branch from 5e8d71c to cc50897 Compare August 23, 2025 08:49
@maiieul maiieul force-pushed the set-maxIdlePreloads-to-be-constant-over-time branch from cc50897 to 0e456fb Compare August 23, 2025 10:20
@@ -78,10 +78,9 @@ export const trigger = () => {
const inverseProbability = bundle.$inverseProbability$;
const probability = 1 - inverseProbability;
const allowedPreloads = graph
? // The more likely the bundle, the more simultaneous preloads we want to allow
Math.max(1, config.$maxIdlePreloads$ * probability)
? config.$maxIdlePreloads$
: // While the graph is not available, we limit to 2 preloads
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove the to 2 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting For Review
Development

Successfully merging this pull request may close these issues.

3 participants