During the startup of an atomic service, code injection is a significant bottleneck. The more code that is injected, the more memory it consumes and the longer it takes.
This issue can be addressed by using on-demand injection and render-time injection, which help reduce both the time and memory required for code injection.
Add the following content to app.json:
{
"lazyCodeLoading": "requiredComponents"
} Since ASCF runtime 1.0.13, only necessary code is injected for atomic services to reduce the startup time and memory usage at runtime.
Version restrictions:
This feature is supported since ASCF runtime 1.0.13. For versions earlier than 1.0.13, this feature is compatible but lacks optimization effects.
Generally, when an atomic service starts, all pages and components on which the startup page depends are injected all at once, including pages and custom components that are not accessed or used yet. In addition, the JS code for all these pages and components is executed immediately. This means a large amount of unused code is injected and executed at runtime, increasing the injection duration and memory usage.
Precautions
When on-demand injection is enabled, only the custom components and page code required for loading the current page are injected. Pages that are not accessed and custom components that are not declared on the current page are not loaded or initialized, and their code is not executed. You need to check whether the atomic service runs properly after the modification.
When on-demand injection is enabled, all components defined in the JSON page configuration file and globally declared custom components configured in usingComponents of the app.json file are considered as page dependencies, and they are injected and loaded. To get the most out of on-demand injection, you should remove the declaration of unused custom components from the JSON file and avoid declaring custom components that are not used often. For custom components that take a long time to load, consider using placeholder components to take advantage of render-time injection.
Version restrictions:
This feature is supported since ASCF runtime 1.0.13. For versions earlier than 1.0.13, this feature is compatible but lacks optimization effects.
When on-demand injection is enabled, you can use render-time injection to specify certain custom components to be injected only when they are actually rendered, rather than during the atomic service startup.
When lazyCodeLoading is set to requiredComponents, a custom component, if configured with a placeholder component, is automatically considered as a lazy-loaded component, regardless of whether the component is in the main package or a subpackage (same as asynchronous package splitting).
Within each page, the component is not injected until it is first rendered.
During the first rendering, the component appears as its placeholder, and the actual injection begins after the rendering process is complete.
Once the injection is done, the placeholder is replaced with the actual component.