Skip to content

Commit 9876fa7

Browse files
authored
refactor: set maxIdlePreloads to be constant over time (#7846)
* refactor: set maxIdlePreloads to be constant over time * chore: changeset * test: preloader.unit * chore: typo
1 parent 6b45985 commit 9876fa7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.changeset/twelve-words-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@builder.io/qwik': patch
3+
---
4+
5+
FEAT: maxIdlePreloads is now constant over time so you know for sure how many bundles will be preloaded concurrently during idle.

packages/qwik/src/core/preloader/preloader.unit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ test('preloader script', () => {
2121
* dereference objects etc, but that actually results in worse compression
2222
*/
2323
const compressed = compress(Buffer.from(preLoader), { mode: 1, quality: 11 });
24-
expect([compressed.length, preLoader.length]).toEqual([1863, 5533]);
24+
expect([compressed.length, preLoader.length]).toEqual([1818, 5417]);
2525
});

packages/qwik/src/core/preloader/queue.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ export const trigger = () => {
7878
const inverseProbability = bundle.$inverseProbability$;
7979
const probability = 1 - inverseProbability;
8080
const allowedPreloads = graph
81-
? // The more likely the bundle, the more simultaneous preloads we want to allow
82-
Math.max(1, config.$maxIdlePreloads$ * probability)
83-
: // While the graph is not available, we limit to 2 preloads
84-
2;
81+
? config.$maxIdlePreloads$
82+
: // While the graph is not available, we limit to 5 preloads
83+
5;
8584
// When we're 99% sure, everything needs to be queued
8685
if (probability >= 0.99 || preloadCount < allowedPreloads) {
8786
queue.shift();

0 commit comments

Comments
 (0)