Conversation
|
34fccb1 to
4064fbb
Compare
| export { externalHelper$ } from './test'; | ||
|
|
||
| ============================= index.js == | ||
| ============================= index_AOCaBShDbUy.js == |
There was a problem hiding this comment.
All hashes are computed based on fileName + functionName + canonicalPath. This works for aliases and barrel files too since the we would do a first pass to map the aliases with their resolved value.
| ); | ||
| }); | ||
|
|
||
| ============================= test.js == |
There was a problem hiding this comment.
This facade segment is kept by the optimizer to not process aliases and simply allow javascript to resolve them on its own. It therefore contains any top level import of the original file which leads to overpreloading. So we need to remove it and use a different approach.
| import { qrl } from "@qwik.dev/core"; | ||
| const i_uFrpfTnm3bA = ()=>import("./test.tsx_TestButton_component_uFrpfTnm3bA"); | ||
| export const helper = ()=>{ | ||
| export const TestButton_QoVabYHvbKj = /*#__PURE__*/ componentQrl(/*#__PURE__*/ qrl(i_uFrpfTnm3bA, "TestButton_component_uFrpfTnm3bA")); |
There was a problem hiding this comment.
Not strictly necessary but all functions are named with a hash to keep the algorithm simple
|
|
||
| ============================= test_helper_POSabSHvbUc.js == | ||
|
|
||
| export const helper_POSabSHvbUc = ()=>{ |
There was a problem hiding this comment.
all helper functions are moved into their own segment
|
|
||
| ============================= test_internalHelper_lkSDkAphtbZa.js == | ||
|
|
||
| export const internalHelper_lkSDkAphtbZa = ()=>{ |
There was a problem hiding this comment.
even internalHelper$ inside TestButton gets extracted into its own segment
| import { relativeHelper } from "./helpers-only-path"; | ||
| ============================= test_TestButton_component_useTask_1_rqfZ500hckk.js (ENTRY POINT)== | ||
|
|
||
| import { aliasHelper_GPaVBHFOUq } from "./resolved_alias_path/filename_aliasHelper_GPaVBHFOUq"; |
There was a problem hiding this comment.
aliasHelper can be transformed since we have the resolved aliases map
| const i_rqfZ500hckk = ()=>import("./test_TestButton_component_useTask_1_rqfZ500hckk"); | ||
| const i_telk8t1ZG1w = ()=>import("./test_TestButton_component_Fragment_button_on_click_telk8t1ZG1w"); | ||
| export const TestButton_component_uFrpfTnm3bA = ()=>{ | ||
| const internalHelper$ = $(()=>{ |
There was a problem hiding this comment.
Even though internalHelper$is a qrl inside TestButton, it will lead to overpreloading from a click segment because we will need to get the code for internalHelper$ from test_tsx_TestButton_component_uFrpfTnm3bA anyways and therefore preload all of the transitive deps here as well.
| useTaskQrl(/*#__PURE__*/ qrl(i_K6S9SSHyiUc, "TestButton_component_useTask_K6S9SSHyiUc")); | ||
| useTaskQrl(/*#__PURE__*/ qrl(i_rqfZ500hckk, "TestButton_component_useTask_1_rqfZ500hckk")); | ||
| useVisibleTaskQrl(/*#__PURE__*/ qrl(i_DHnqAQBxHLQ, "TestButton_component_useVisibleTask_DHnqAQBxHLQ", [ | ||
| counter, |
There was a problem hiding this comment.
No need to hold a reference to internalHelper$ anymore since it's extracted and imported as a separate segment
| helper2(); | ||
| externalHelper$(); | ||
| counter.value > 0 && internalHelper$(); | ||
| onlyOneImporterHelper_BJQkbvgbbAk(); |
There was a problem hiding this comment.
Even though onlyOneImporterHelper is in a separate segment, it will be bundled back together with test_TestButton_component_useVisibleTask_DHnqAQBxHLQ with Rollup.
| export const helper2_AARzbvUvbMp = ()=>{ | ||
| console.log("helper"); | ||
| }; | ||
| export const externalHelper$ = $(()=>{ |
There was a problem hiding this comment.
Even external QRLs aren't extracted into their own segments and can therefore lead to over-preloading when invoked
4064fbb to
73d3cc2
Compare
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
commit: |
845c256 to
0ab9b5e
Compare
0ab9b5e to
39ec269
Compare
What is it?
Description
Motivation
The optimizer can produce segments code that contain both component code and shared helpers. This can lead to over-preloading on user-interaction or – more problematically – on visible tasks (e.g. instead of ~4-5 bundles to preload, it can easily become ~50-100). This happens because the optimizer doesn't split helpers into separate segments. So in practice if a helper is declared in a separate file, the optimizer will leave it untouched, but if it is colocated in the same file as the component code, then the optimizer will output it in the same facade segment as the componentQrl, meaning that when the helper is imported by another module, not only the helper but also the component and all its transitive dependencies will be eagerly preloaded (100% probability) as well.
Example 1 (helper outside of component$ in output facade segment):
Now this means that if an on-click segment
imports { helper } from "./test.js"andTestButton_component_uFrpfTnm3bAhas a lot of transitive dependencies, then the the preloader will end up eagerly preloading (100% probability)TestButton_component_uFrpfTnm3bAand all its transitive dependencies, even though we only needed to importhelperin the first place.