()
| 69 | * We make sure to first preload the high priority items. |
| 70 | */ |
| 71 | export const trigger = () => { |
| 72 | if (!queue.length) { |
| 73 | return; |
| 74 | } |
| 75 | sortQueue(); |
| 76 | while (queue.length) { |
| 77 | const bundle = queue[0]; |
| 78 | const inverseProbability = bundle.$inverseProbability$; |
| 79 | const probability = 1 - inverseProbability; |
| 80 | const allowedPreloads = graph |
| 81 | ? config.$maxIdlePreloads$ |
| 82 | : // While the graph is not available, we limit to 5 preloads |
| 83 | 5; |
| 84 | // When we're 99% sure, everything needs to be queued |
| 85 | if (probability >= 0.99 || preloadCount < allowedPreloads) { |
| 86 | queue.shift(); |
| 87 | preloadOne(bundle); |
| 88 | } else { |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | /** |
| 93 | * The low priority bundles are opportunistic, and we want to give the browser some breathing room |
| 94 | * for other resources, so we cycle between 4 and 10 outstanding modulepreloads. |
| 95 | */ |
| 96 | if (config.$DEBUG$ && !queue.length) { |
| 97 | const loaded = [...bundles.values()].filter((b) => b.$state$ > BundleImportState_None); |
| 98 | const waitTime = loaded.reduce((acc, b) => acc + b.$waitedMs$, 0); |
| 99 | const loadTime = loaded.reduce((acc, b) => acc + b.$loadedMs$, 0); |
| 100 | log( |
| 101 | `>>>> done ${loaded.length}/${bundles.size} total: ${waitTime}ms waited, ${loadTime}ms loaded` |
| 102 | ); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | const preloadOne = (bundle: BundleImport) => { |
| 107 | if (bundle.$state$ >= BundleImportState_Preload) { |
no test coverage detected
searching dependent graphs…