Skip to content

Commit f26a942

Browse files
committed
perf(preload): tweak probabilities
1 parent ca62d60 commit f26a942

File tree

3 files changed

+139
-129
lines changed

3 files changed

+139
-129
lines changed

packages/qwik/src/optimizer/src/plugins/bundle-graph.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ export function convertManifestToBundleGraph(
138138
// Calculate the probability of the dependency
139139
// Start with a 50% chance
140140
let probability = 0.5;
141-
// Add a 4% chance for each interactivity point (max 20%)
142-
probability += (dep.interactivity || 0) * 0.04;
141+
// Add a 8% chance for each interactivity point (max 40%)
142+
probability += (dep.interactivity || 0) * 0.08;
143143

144144
// If the dependency has a segment from the same parent, it's more likely to be loaded
145145
if (bundle.origins && dep.origins) {
@@ -156,8 +156,12 @@ export function convertManifestToBundleGraph(
156156
if (dep.total > slowSize) {
157157
probability += probability > 0.5 ? 0.02 : -0.02;
158158
}
159+
// OTOH, if the dependency is small, load it sooner since it won't block much
160+
if (dep.total < 1000) {
161+
probability += 0.15;
162+
}
159163

160-
depProbability.set(depName, probability);
164+
depProbability.set(depName, Math.min(probability, 0.99));
161165
}
162166

163167
if (dynDeps.size > 0) {

0 commit comments

Comments
 (0)