目录

How can I handle slow cold start of an ASCF atomic service?

Symptom

When an atomic service is opened for the first time or after a long period of inactivity, the duration from tapping the icon until the home page is fully loaded is excessive. During this period, a blank screen or loading animation may be displayed.

Context

Trace points for ASCF cold start

Use DevEco Profiler to capture the trace data during the cold start of the ASCF atomic service, and check the time consumption in each phase based on the ASCF trace keywords listed in the following table.

The table below lists all trace points embedded by ASCF in the cold start process, ordered by execution sequence.

Trace Keyword Phase Description
H:StageCreate Runtime environment preparation Total time taken to start the AscfAbilityStage of the atomic service, including configuration parsing and JSVM engine initialization.
H:UIAbilityCreate Runtime environment preparation Total time taken to start the AscfUIAbility of the atomic service, including window information initialization and startup parameter loading.
H:MainPageAppear Runtime environment preparation Total time taken to create AscfMainPage, including UI context initialization, API registration, and system component creation.
H:LaunchMiniApp Logic-layer code injection Total time taken to load and execute the app.js file of the atomic service, from the start of loading to the completion of loading.
H:AscfRenderPageAppear View-layer code injection Time taken for AscfRenderPage, including subpackage loading and page configuration information reading.
H:NewPageRender View-layer code injection Rendering duration when navigating to a new page, including page generation and NavDestination rendering.
H:WebPageLoad Page rendering Total duration from view-layer code injection to home page rendering.
H:JSVM_Exe_Code Runtime Duration for executing JS code at the logic layer, including all service logic execution, API callbacks, and page lifecycle callbacks.

Troubleshooting

  1. Use the Launch analysis capability of DevEco Profiler to capture trace data during the cold start of the ASCF atomic service.

  2. Search for the trace keywords listed in the preceding table in the trace data to view the time consumed in each phase.

  3. Locate the specific causes by referencing the detailed descriptions for trace points with long duration:

    • Logic-layer code injection duration: Check the duration of H:LaunchMiniApp to analyze the time consumed in logic-layer code injection and execution.

    • View-layer code injection duration: Check the overall duration from the end of H:AscfRenderPageAppear to the start of H:WebPageLoad to analyze the time consumed in loading the page structure and style resources at the view layer.

    • Page rendering duration: Check the duration of H:WebPageLoad to analyze the time consumed in rendering the page based on the page structure and page data.

    • Runtime logic duration: Check the duration of H:JSVM_Exe_Code to analyze whether the JS execution at the logic layer blocks data update.

Conclusion

Common causes of slow cold start of an ASCF atomic service are as follows:

Recommendation