Skip to content

Commit 7527b80

Browse files
committed
perf(preloader): bundle at 100% => dynamic at 95%
1 parent eabf124 commit 7527b80

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ 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).toBe(1706);
25-
expect(preLoader.length).toBe(5082);
24+
expect(compressed.length).toBe(1722);
25+
expect(preLoader.length).toBe(5107);
2626
});

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ export const adjustProbabilities = (
179179
const prevAdjust = dep.$factor$;
180180
/**
181181
* The chance that a dep won't be loaded is 1-(the chance that the dep will be loaded)*(the
182-
* chance that the current bundle will be loaded)
182+
* chance that the current bundle will be loaded).
183183
*
184184
* We can multiply this chance together with all other bundle adjustments to get the chance
185-
* that a dep will be loaded given all the chances of the other bundles
185+
* that a dep will be loaded given all the chances of the other bundles.
186+
*
187+
* But when we're very likely to load the current bundle, make the dynamic imports more likely
188+
* too.
186189
*/
187-
const newInverseProbability = 1 - dep.$probability$ * probability;
190+
const newInverseProbability =
191+
dep.$probability$ !== 1 && adjustFactor < 0.1 ? 0.05 : 1 - dep.$probability$ * probability;
188192

189193
/** We need to undo the previous adjustment */
190194
const factor = newInverseProbability / prevAdjust;

0 commit comments

Comments
 (0)