Application cold start method, electronic equipment and related device

By loading and executing only necessary resource files during application cold start and delaying the execution of unnecessary resource files, combined with dependency resolution, the problem of long application cold start time is solved, and a more efficient startup process is achieved.

CN121934906APending Publication Date: 2026-04-28HUAWEI DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAWEI DEVICE CO LTD
Filing Date
2024-10-28
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

When an application is cold-started, the increased number of executable files, modules, and library resources leads to longer startup times, affecting startup efficiency.

Method used

During application cold start, only the necessary files corresponding to the first sub-resource are loaded and executed, while the unnecessary files corresponding to the second sub-resource are executed with a delay. The dependencies between resources are resolved to determine the execution order, and delayed execution is supported by modifying the import statement.

Benefits of technology

It reduces the time spent on application cold starts, improves startup efficiency, and avoids the development complexity and compatibility issues caused by dynamic imports.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121934906A_ABST
    Figure CN121934906A_ABST
Patent Text Reader

Abstract

The invention provides an application cold start method, electronic equipment and a related device.In the method, during application cold start, the electronic equipment loads a first resource to a memory, the first resource comprises a first sub-resource and a second sub-resource, and a file corresponding to the first sub-resource is executed; at the first moment, the electronic equipment executes the file corresponding to the second sub-resource, and the first moment is the moment after cold start of the application is completed. In the application, the electronic equipment can execute the file corresponding to the first sub-resource required to be used by the application cold start during the application cold start, does not execute the file corresponding to the second sub-resource which is not required to be used, and executes the file corresponding to the second sub-resource when the second sub-resource is required to be used, so that the files executed during the application cold start can be reduced; and the time consumption of cold start of the application is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of application cold start technology, and in particular to an application cold start method, electronic device, and related apparatus. Background Technology

[0002] During an application cold start, an executable file is loaded and an import initialization operation is performed. The executable file contains the code and instructions required for the application to run, allowing the central processing unit (CPU) to execute these instructions and achieve a cold start. The import initialization operation loads the modules, libraries, and other resources needed by the application to implement its functionality and business logic.

[0003] As application functions increase and security performance improves, the number of executable files, modules, and libraries in applications gradually increases, leading to longer application cold start times. Summary of the Invention

[0004] This application provides a method, electronic device, and related apparatus for application cold start, which can reduce the time required for application cold start.

[0005] Firstly, embodiments of this application provide a method for application cold start. The execution subject of this method can be an electronic device, a chip in the electronic device, or an application in the electronic device. The following description uses an electronic device as an example. In this method, during application cold start, the electronic device can load a first resource into memory. The first resource includes a first sub-resource and a second sub-resource. The first resource is the resource required for application operation and may include modules, libraries, etc. The first resource may include multiple sub-resources, which may be of the same or different types. The description here uses the example of a first resource including a first sub-resource and a second sub-resource.

[0006] During an application cold start, the electronic device can execute the file corresponding to the first sub-resource but not the file corresponding to the second sub-resource. Instead, it executes the file corresponding to the second sub-resource only at the moment the application cold start is completed. The second sub-resource is not a resource required for the application cold start; therefore, the electronic device can delay its execution until it is actually needed, such as when the file corresponding to the second sub-resource is executed at the moment of completion.

[0007] In this application, during application cold start, the electronic device can load all the resources required for application operation, such as the first resource. However, when executing files, only the files corresponding to the first sub-resources required for application cold start are executed, and the files corresponding to the second sub-resources that are not required are not executed. When the second sub-resources are needed, the files corresponding to the second sub-resources are executed. This reduces the number of files executed during application cold start, thereby reducing the time spent on application cold start.

[0008] In one possible implementation, after loading the first resource into memory, the electronic device can also load variables from the first sub-resource and variables from the second sub-resource into memory. When the electronic device executes the file corresponding to the first sub-resource, it can assign values ​​to the variables in the first sub-resource. However, because the electronic device does not execute the file corresponding to the second sub-resource during application cold start, the variables in the first sub-resource are assigned values ​​in memory when the application cold start is complete, but the variables in the second sub-resource are not assigned values. At the first moment, the electronic device executes the file corresponding to the second sub-resource, and the electronic device can assign values ​​to the variables in the second sub-resource in memory; at this time, the variables in the second sub-resource in memory are assigned values.

[0009] In this implementation, the electronic device does not execute the file corresponding to the second sub-resource during application cold start. However, in order for the electronic device to quickly execute the file corresponding to the second sub-resource when it actually uses the second sub-resource, the electronic device can load the variables in the second sub-resource into memory during application cold start to prepare for the subsequent execution of the file corresponding to the second sub-resource by the electronic device.

[0010] In one possible implementation, the first resource also includes a third sub-resource, which depends on the second sub-resource. In this example, because the third sub-resource depends on the second sub-resource—meaning it needs to use the functionality or data of the second sub-resource—the electronic device must first execute the file corresponding to the second sub-resource, and then execute the file corresponding to the third sub-resource. This ensures the third sub-resource can utilize the functionality or data of the second sub-resource. Otherwise, if the application executes the file corresponding to the third sub-resource before executing the file corresponding to the second sub-resource, application execution errors and other problems will occur. Therefore, in this implementation, the electronic device can execute the file corresponding to the third sub-resource at a second time, which is later than the first time.

[0011] In this implementation, after loading the first resource into memory, the electronic device also resolves the dependencies between the sub-resources within the first resource, revealing that the third sub-resource depends on the second sub-resource. In this way, the electronic device can determine the execution method and order of the sub-resources based on their dependencies. The execution method can be either delayed execution or non-delayed execution.

[0012] In this implementation, the electronic device can parse the first resource to obtain the dependencies between the sub-resources in the first resource. In this way, the electronic device can determine the execution method and execution order of the sub-resources based on the dependencies between the sub-resources to ensure the smooth execution of the application.

[0013] Understandably, since the third sub-resource is also executed after the application cold start, in order for the electronic device to quickly execute the file corresponding to the third sub-resource when it actually uses it, the electronic device can load the variables in the third sub-resource into memory during the application cold start, in order to prepare for the subsequent execution of the file corresponding to the third sub-resource by the electronic device.

[0014] Specifically, the electronic device can load variables from the third sub-resource into memory during application cold start. At this time, the variables in the third sub-resource in memory are not assigned values ​​when the application cold start is completed. At the second moment, when the electronic device executes the file corresponding to the third sub-resource, the electronic device assigns values ​​to the variables in the third sub-resource in memory, at which point the variables in the third sub-resource in memory are assigned values.

[0015] In one possible implementation, developers can modify the original static import statement to support deferred execution of files within the import statement. In this embodiment, during application cold start, the electronic device can execute an import statement that instructs the loading of a first resource and the deferred execution of the file corresponding to a second sub-resource.

[0016] Based on the import statement, the electronic device can determine the first resource required for the application to run, and determine that the execution of the file corresponding to the second sub-resource in the first resource needs to be delayed, so that the electronic device can execute the file corresponding to the second sub-resource after the application cold start is completed.

[0017] In one possible implementation, since the electronic device does not execute the file corresponding to the second sub-resource during application cold start, the electronic device can write the location of the second sub-resource in memory into a first list. Thus, at the first moment, when the electronic device executes the file corresponding to the second sub-resource, it can query the first list to determine the location of the second sub-resource in memory, retrieve the second sub-resource at that location, and execute the file corresponding to the second sub-resource.

[0018] In this implementation, during application cold start, the electronic device can store the location of the second sub-resource that is not executed in memory. This way, when the file corresponding to the second sub-resource is actually executed, the second sub-resource can be obtained based on that location.

[0019] Accordingly, since the electronic device does not execute the file corresponding to the third sub-resource during application cold start, it can write the location of the third sub-resource in memory into the first list. Thus, at the second moment, when the electronic device executes the file corresponding to the third sub-resource, it can query the first list to determine the location of the third sub-resource in memory, retrieve the third sub-resource at that location, and execute the file corresponding to the third sub-resource.

[0020] In a second aspect, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory is used to store code instructions and the processor is used to execute the code instructions to perform the methods described in the first aspect or any possible implementation thereof.

[0021] Thirdly, embodiments of this application provide a computer-readable storage medium storing a computer program or instructions that, when executed on a computer, cause the computer to perform the methods described in the first aspect or any possible implementation thereof.

[0022] Fourthly, embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation of the first aspect.

[0023] Fifthly, this application provides a chip or chip system including at least one processor and a communication interface. The communication interface and the at least one processor are interconnected via a circuit. The at least one processor is used to run computer programs or instructions to perform the methods described in the first aspect or any possible implementation thereof. The communication interface in the chip can be an input / output interface, pins, or circuits, etc.

[0024] In one possible implementation, the chip or chip system described above in this application further includes at least one memory storing instructions. The memory can be an internal storage unit of the chip, such as a register or cache, or it can be a storage unit of the chip itself (e.g., read-only memory, random access memory, etc.).

[0025] It should be understood that the second to fifth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation are similar, and will not be repeated here. Attached Figure Description

[0026] Figure 1 This is an illustration of the homepage of a news application.

[0027] Figure 2This is a schematic diagram of application 1 cold start;

[0028] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0029] Figure 4 A flowchart illustrating one embodiment of the application cold start method provided in this application;

[0030] Figure 5 A flowchart illustrating another embodiment of the application cold start method provided in this application;

[0031] Figure 6 A dependency graph of modules provided for embodiments of this application;

[0032] Figure 7 A flowchart illustrating another embodiment of the application cold start method provided in this application;

[0033] Figure 8 An example diagram of an application cold start provided in an embodiment of this application;

[0034] Figure 9 Another example diagram of application cold start provided in the embodiments of this application;

[0035] Figure 10 This is another structural schematic diagram of the electronic device provided in the embodiments of this application. Detailed Implementation

[0036] To facilitate understanding, the relevant terms and concepts involved in the embodiments of this application will be introduced below:

[0037] 1. Application Cold Start: When an application starts, there is no background process for the application on the electronic device. The operating system on the electronic device creates a new process and assigns it to the application. This method of starting an application is called a cold start. Application cold starts usually occur when the application is opened for the first time, or when the application is restarted after its process has been destroyed.

[0038] In contrast to a cold start, there is a warm start. A warm start can be understood as follows: when an application starts, its process exists in the background of the electronic device. The operating system of the electronic device can resume the application's page from that process. This method of starting an application is called a warm start. A warm start typically occurs when an application switches from the background to the foreground, and its process already exists in the background.

[0039] Compared to a warm start, a cold start takes longer.

[0040] 2. Import Initialization: During an application cold start, the operating system needs to create the application's process and allocate corresponding resources. In this process, the application needs to import necessary modules, libraries, and other resources to implement its functions and business logic. Through import initialization, the application can ensure that all necessary modules, libraries, and other resources are imported at startup, thereby avoiding errors or exceptions caused by missing resources during subsequent execution. Importing modules and libraries can be understood as the application loading these resources into the electronic device's memory.

[0041] In some embodiments, import initialization involves not only importing modules, libraries, and other resources, but also initializing global variables and configurations. These global variables and configurations are crucial for the proper functioning of the application, such as database connection information, application programming interface (API) keys, and log levels. Through import initialization, the application can set these global variables and configurations at startup, ensuring their availability during subsequent execution.

[0042] 3. Import statement: During the import initialization process, the application will execute the import statement, which is used to indicate the modules, libraries and other resources to be imported.

[0043] 4. Modules: Used to organize and encapsulate code. In some embodiments, a module can be a single file or a set of files, depending on how the code is organized. Modules allow code to be divided into different parts, making the code easier to manage and reuse. In some embodiments, a module can contain functions, classes, variables, and executable code; by importing these modules, applications can use the functions, classes, and variables.

[0044] 5. Library: A library is a collection of modules or code, typically used to provide specific functionality or services. A library can contain multiple modules that work together to achieve more complex functionalities.

[0045] During the import initialization process, the libraries imported by the application can include, but are not limited to, various dynamic link libraries (DLLs) or shared libraries (usually called .so files in Unix-like systems) required for the application to run. These libraries contain various functions, variables, and resources required for the application to run, and are the foundation for the application to function properly.

[0046] 6. Deferred import: During the import initialization process, necessary modules, libraries and other resources are imported. Unnecessary modules, libraries and other resources can be loaded when they are actually used.

[0047] Deferred imports reduce import initialization time, thereby reducing application cold start time and allowing users to quickly use the application. Furthermore, deferred imports only load necessary modules and libraries, avoiding unnecessary resource consumption. In summary, deferred imports can optimize application cold start performance and user experience.

[0048] 7. Application Homepage: The first page presented to the user for interaction and use after the electronic device launches the application. This page carries the application's core functions, content display, and user navigation. In some embodiments, the application homepage may also be referred to as the application's starting frame or the application's starting frame screen. It should be understood that the application homepage is not the application's launch page. The application's launch page is the page that displays the application's logo.

[0049] For example, let's take news apps as an example. Figure 1 The image shows the homepage of a news application. (See reference...) Figure 1 The homepage of a news app may include: a search box 11, a navigation bar 12, a content bar 13, and a tab bar 14. When a user enters information in the search box 11, the news app will display the page corresponding to that search result. The navigation bar 12 may include different types of news channels; users can select a news channel to switch to that channel's page. The content bar 13 displays recommended news content from the news app. The tab bar 14 may include options such as "Home," "Videos," "Messages," and "My Profile," which users can click to switch to different content sections within the news app.

[0050] 8. The King Kong Zone: This is a prominent area on the user interface, usually located at the bottom or top of the user page. It contains a set of quick launch icons (also known as King Kong Zone icons), which users can use to quickly access frequently used functions or applications.

[0051] In some embodiments, the application's homepage may include a "Kingdom Zone" icon, which users can interact with to access frequently used functions of the application. For example, see... Figure 1 The main area of ​​a news application's homepage can include: a search box 11, a navigation bar 12, and a tab bar 14.

[0052] 9. User Interface:

[0053] The term "user interface (UI)" or "interface" in this application refers to the medium through which an application or operating system interacts and exchanges information with the user. It converts the internal form of information into a form that the user can understand. A user interface is source code written in a specific computer language such as Java or Extensible Markup Language (XML). This source code is parsed and rendered on an electronic device, ultimately presenting content that the user can recognize. A common form of user interface is the graphical user interface (GUI), which refers to a user interface related to computer operation displayed graphically. It can be visible interface elements such as text, icons, buttons, menus, tabs, text boxes, dialog boxes, status bars, navigation bars, and widgets displayed on the screen of an electronic device.

[0054] 10. Electronic devices:

[0055] The electronic device in this application embodiment is an electronic device with a display screen, and an application is installed on the electronic device. This application embodiment relates to the cold start process of the application. In some embodiments, the electronic device may be referred to as a user equipment (UE), terminal, etc. For example, the electronic device may be a mobile phone, tablet, personal digital assistant (PDA), handheld device with wireless communication function, computing device, in-vehicle device or wearable device, virtual reality (VR) terminal device, augmented reality (AR) terminal device, wireless terminal in industrial control, wireless terminal in smart home, etc. The form of the electronic device is not specifically limited in this application embodiment.

[0056] Figure 2 This is a schematic diagram of application 1's cold start. (Refer to...) Figure 2 When application 1 cold starts, the following steps need to be performed: 1. Load the executable file; 2. Import initialization. For example, taking files as the resources loaded during import initialization, the application needs to perform the following steps during import initialization: import file 1, executable file 1, import file 2, executable file 2, import file 3, executable file 3, ..., import file 6, and executable file 6. After the application executes file 6, the electronic device can display the application's home screen. It should be understood that... Figure 2The steps of importing file 1, import 2, import 3, ..., import 6 are respectively represented by import1, import 2, import 3, ..., import 6. In some embodiments, the executable file can be understood as the code in the executable file.

[0057] Table 1 shows the time taken for each step during the cold start of Application 1. It should be understood that the times in Table 1 are for illustrative purposes only.

[0058] Table 1

[0059] Step Time (ms) Load executable 102.7 import 1 45.7+40.756=86.456 import 2 112.4 import 3 53.6 import 4 465.4 import 5 352 import 6 130 import 6 to display diamond region 231

[0060] According to statistics, the total cold start time of application 1 was 1671ms, while the time spent by application 1 in loading the executable file and importing initialization was 1261.8ms, accounting for 75.5% of the total cold start time of application 1.

[0061] In summary, the time spent loading the executable file and initializing imports accounts for a significant proportion of the total application cold start time. In some embodiments, to reduce the total application cold start time and improve its efficiency, the time spent loading the executable file and initializing imports in application 1 can be reduced. Referring to Table 1, the time spent on import initialization accounts for a large proportion of the total time spent loading the executable file and initializing imports in application 1. Therefore, reducing the time spent on import initialization can significantly reduce the total application cold start time.

[0062] In some embodiments, during the import initialization process, dynamic import can be used to import the modules, libraries, and other resources required by the application. Dynamic import refers to a technique for importing modules, libraries, and other resources on demand. For example, in application development, dynamic import allows developers to load modules asynchronously as needed during application runtime, rather than loading all necessary modules at application startup.

[0063] For example, for application 1, during a cold start, it needs files 1, 2, 3, and 4, while files 5 and 6 are not needed at the moment. Therefore, during the import initialization of application 1 during cold start, application 1 can load files 1, 2, 3, and 4 as needed, and execute files 1, 2, 3, and 4 accordingly. In this example, the application can delay importing files 5 and 6, loading and executing file 5 and file 6 only when the application needs them (such as after a cold start).

[0064] Dynamic imports can reduce the number of modules, libraries, and other resources imported during application cold starts, and can reduce the time spent on import initialization, thereby reducing the total cold start time of the application and improving the application's startup speed and performance. This advantage is particularly pronounced in large applications where a large amount of code and resources need to be loaded during import initialization.

[0065] However, the dynamic import method has the following problems:

[0066] 1. Dynamic imports require all functions and their callers to adopt an asynchronous programming model. However, asynchronous programming doesn't necessarily reflect the program's true intent. A key characteristic of dynamic imports is their inherent asynchronous nature. For example, when a module is dynamically imported, the application doesn't immediately receive the module's contents but instead receives a Promise object, which is resolved only after the module has finished loading. Therefore, all functions and callers that rely on dynamic imports need to adapt to this asynchronous programming model. This means that even if the program logic is inherently synchronous, using dynamic imports requires rewriting it asynchronously to accommodate the asynchronous nature of dynamic imports. This doesn't directly reflect the program's original intent or logical structure, and such dynamic imports can make the code more complex and difficult to understand, increasing the workload for developers.

[0067] 2. Dynamic imports require all call points to be updated to dynamic imports, and existing API users must undergo API changes. It should be understood that when deciding to use dynamic imports, developers typically need to modify call points that originally obtained modules through static imports. This requires developers to find all call points referencing these modules and replace them with dynamically imported calls. This process can be time-consuming and error-prone, especially when the application is large and the dependencies between modules are complex, increasing the workload for developers. Furthermore, if the dynamically imported module is part of the API, changing from static to dynamic imports will also affect other developers or applications using the API. These developers or applications will need to update their code to adapt to the new API changes, leading to compatibility issues or additional maintenance work.

[0068] In summary, while dynamic imports can reduce the time spent on import initialization to some extent, they also lead to increased workload for developers, greater code maintenance difficulties, and compatibility issues.

[0069] Currently, during the import initialization process, applications need to import resources such as modules and libraries because the code in these resources is essential for the modules to function properly. Therefore, after importing, the application can execute the files corresponding to these resources to complete the import initialization. Here, the files corresponding to modules and libraries can be understood as the files included in the modules and libraries, and the application executable file can be understood as the code within the application executable file. However, this application's analysis reveals that not all modules and libraries imported during import initialization are needed during application cold starts. Therefore, this application provides a method for application cold starts. For modules and libraries needed during application cold starts, the files corresponding to these resources can be executed after importing. For modules and libraries not needed during application cold starts, the files corresponding to these resources can be temporarily omitted after importing, and executed only when needed by the application, to ensure the normal operation of both the modules and the application.

[0070] In some embodiments, the application cold start method provided in this application can be referred to as delayed execution. That is, during the import initialization process, after the application imports modules, libraries, and other resources, the execution of modules, libraries, and other resources that are not needed (or not required) for the application cold start can be delayed. This reduces the execution time of these modules, libraries, and other resources during the import initialization process, thereby reducing the time spent on import initialization and the total time of the application cold start. Furthermore, since the import method of modules, libraries, and other resources is not modified in the embodiments of this application, developers only need to pre-mark the modules, libraries, and other resources that need to be delayed in execution. Therefore, the problems of large workload for developers, high maintenance difficulty, and compatibility difficulties associated with dynamic import are not present.

[0071] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. (Refer to...) Figure 3 Electronic devices can include applications and operating systems. Among these, electronic devices can have applications such as video applications, audio applications, and social media applications installed. Figure 3 The following explanation uses Chinese and Israeli applications as examples.

[0072] During an application cold start, the operating system may create a new process and assign it to the application. This application process can execute the application's code and instructions to implement the application cold start method provided in this embodiment. It should be understood that in the following embodiments, the operations performed by the application can be understood as operations performed by the application process or operations performed by the electronic device.

[0073] Before introducing the application cold start method provided in the embodiments of this application, we will first introduce the preparatory operations for delaying the execution of modules, libraries and other resources during application cold start:

[0074] To implement import initialization, developers write import statements when developing applications. Import statements are used to indicate the modules, libraries, and other resources imported during the import initialization process. In this embodiment of the application, because it is necessary to delay the execution of some files corresponding to modules, libraries, and other resources, developers can modify the import statements so that the application can delay the execution of these files when the import initialization call is made.

[0075] In some embodiments, Table 2 exemplarily illustrates a comparison of the import statements, instructions, and specific implementations of "static import" in the prior art and "deferred execution" provided in this application:

[0076] Table 2

[0077]

[0078] For example, taking the import of file A as an example, file A can be a module, library, or other resource. In the case of static import in existing technology, the import statement can be `Import{a}from'A'`, which can be understood as: the application executes the "LdExternalModuleVar" instruction, after importing file A, it needs to execute file A and load the variable 'a' into memory, where the variable 'a' stored in memory is the assigned value. However, in this embodiment, the import statement can be `Importdefer{a}from'A'`, that is, deferred execution of file A. The application executes the `deferLdExternalModuleVar` instruction, and after importing file A, it can first add file A to the first list. After the application adds file A to the first list, because the application has not yet executed file A, it can first load the variable 'a' from file A into memory, where the variable 'a' stored in memory is the unassigned value. When the application needs to execute file A, it can search for file A in the first list, execute file A, and assign a value to the variable 'a' in memory.

[0079] Here is an explanation of the variables in file A:

[0080] For example, during an application cold start, if the variables in file A imported by the application include user data variables, these user data variables may include, but are not limited to, user ID, user preferences, login status, etc. Taking user ID as an example, assigning a value to user ID can be understood as: the memory contains both the user ID and the specific user ID value "abcxxx". Not assigning a value to user ID can be understood as: the memory contains the user data variable "user ID", but the user ID does not have a specific value.

[0081] In some embodiments, the first list may be a Top-Level Await list. The Top-Level Await list includes files imported during application cold start that have not yet been executed.

[0082] The application cold start method provided in this application is described below with reference to specific embodiments. These embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0083] Figure 4 This is a flowchart illustrating one embodiment of the application cold start method provided in this application. (Refer to...) Figure 4 The application cold start method provided in this application embodiment may include:

[0084] S401, during application cold start, the application loads the first resource into memory, which includes a first sub-resource and a second sub-resource.

[0085] It should be understood that during an application cold start, the application can load the executable file into memory. After loading the executable file into memory, the application can perform import initialization, loading the first resources into memory. Specifically, the application can execute import statements to find the first resources required for application operation, download the first resources, and load the first resources into memory.

[0086] The first resource includes modules, libraries, and other resources necessary for the application to run. For example, taking the example in Table 1, the resources necessary for the application to run include file 1, file 2, file 3, ..., file 6, and the first resource may include file 1, file 2, file 3, ..., file 6.

[0087] The first resource may include at least one type of sub-resource, such as a module or library. This application uses an example where the first resource includes a first sub-resource and a second sub-resource to illustrate a method for applying delayed execution of the file corresponding to the resource. For example, the first sub-resource could be module 1, and the second sub-resource could be module 2.

[0088] S402, during the import initialization process, the application executes the file corresponding to the first sub-resource, but does not execute the file corresponding to the second sub-resource.

[0089] The first sub-resource is the resource needed (used) when the application starts cold. Therefore, during the import initialization process, after the application loads the first sub-resource into memory, it can execute the file corresponding to the first sub-resource.

[0090] For example, the first sub-resource may include, but is not limited to: a logging module and some modules related to user login. Specifically, the application loads and executes the logging module, enabling the application to record logs after a cold start for later use. The application loads and executes some modules related to user login, enabling the application to display a page prompting the user to log in after a cold start, or to display the application's homepage indicating that the user is logged in, etc.

[0091] For example, taking a video application as an example, after a cold start, the application's homepage will be displayed. If the resources for the homepage are not loaded during the cold start, it will affect the display of the homepage. For example, the first sub-resource may include variables such as the homepage's theme and language settings. Accordingly, the application executes the file corresponding to the first sub-resource, which can load the homepage's theme and language settings into memory and assign values ​​to these variables. In this way, after the application's cold start, the application can display the homepage based on these variables in memory.

[0092] The second sub-resource is a resource that is not needed (used) during application cold start. Therefore, during the import initialization process, after loading the first sub-resource, the application can choose not to execute the file corresponding to the second sub-resource, but execute the file corresponding to the second sub-resource when the application needs it.

[0093] For example, the second sub-resource may include, but is not limited to, resources that can only be accessed by clicking on controls in the application's homepage. For instance, the application's homepage may include, but is not limited to, scan controls and search controls. Clicking the scan control triggers the electronic device to display a scan page, enabling the device to scan QR codes, barcodes, etc. Clicking the search control triggers the electronic device to display a search page, allowing the device to search for relevant information that meets the user's needs.

[0094] For example, taking a video application as an example, the second sub-resource may include a scanning module and a search module. The scanning module can be understood as a resource that supports the display of a scanning page on an electronic device, and the search module can be understood as a resource that supports the display of a scanning page on an electronic device. After a cold start, the application homepage can be displayed, which may include scanning and search controls. When a user clicks the scanning control, the electronic device can be triggered to display a scanning page to support scanning QR codes, barcodes, etc. When a user clicks the search control, the electronic device can be triggered to display a search page to support searching for relevant information requested by the user. The scanning and search modules are not essential resources for the application homepage; therefore, during the import initialization process, the application may not execute the files corresponding to the second sub-resource initially.

[0095] For the second sub-resource, after loading it, the application can choose not to execute the second sub-resource, but instead load the variables within it into memory without assigning values ​​to them. For example, after loading the scanning and search modules into memory, the application can choose not to assign values ​​to the variables within these modules; the variables in memory do not have specific values ​​or content.

[0096] It is understandable that for different applications, the first sub-resources needed and the second sub-resources not needed during a cold start may be different. The first and second sub-resources in the video application example above are for illustrative purposes.

[0097] S403, at the first moment, the application executes the file corresponding to the second sub-resource.

[0098] The first moment is the moment after the application's cold start is complete, which can also be understood as the moment after import initialization is complete. Specifically, the first moment can be: the moment when the application needs to use the second sub-resource after the application's cold start is complete.

[0099] In this embodiment of the application, the application may delay the execution of the file corresponding to the second sub-resource. The application may execute the file corresponding to the second sub-resource at the first moment, that is, at the moment when the application needs to use the second sub-resource.

[0100] For example, in response to a user's interaction with the "Personal Center" control, the application needs to display the Personal Center page, which includes the user ID. Therefore, in response to a user's interaction with the "Personal Center" control, the application can execute the file corresponding to the second sub-resource and assign a value to the variable "User ID" in memory. In this way, the Personal Center page displayed by the application can include the specific user ID.

[0101] For example, when an application encounters an error (bug), it can query the logs to determine the cause of the error. Therefore, when an application encounters an error, it can execute the file corresponding to the second sub-resource to assign values ​​to the logs in memory, so that the application can determine the cause of the error based on the logs.

[0102] It is understandable that for different second sub-resources in an application, the application needs to use the second sub-resources at different times, so the first time the application executes the file corresponding to different second sub-resources can also be different.

[0103] In this embodiment of the application, during application cold start, after loading the resources required for application operation during the import initialization process, the application can execute the files corresponding to the resources needed for application cold start, but will not execute the files corresponding to the resources not needed for application cold start. The files corresponding to these resources will only be executed when the application needs them. This can reduce the time spent by the application executing files during the import initialization process, thereby reducing the import initialization time and the total application cold start time.

[0104] In some embodiments, the modules, libraries, and other resources imported by an application during import initialization have dependencies on each other. These dependencies are related to the execution order of the files corresponding to the modules, libraries, and other resources. For example, if module 1 depends on module 2, meaning module 1 needs to use the functionality or data of module 2, the application must execute the file corresponding to module 2 first, and then execute the file corresponding to module 1, so that module 1 can use the functionality or data of module 2. Otherwise, if the application executes the file corresponding to module 1 before executing the file corresponding to module 2, application execution errors and other problems will occur.

[0105] In this embodiment of the application, in order to ensure the smooth execution of the application, during the import initialization process, after loading the first resource, the application needs to parse the first resource to obtain the dependency relationship between the sub-resources in the first resource. In this way, the application can determine the execution method and execution order of the sub-resources based on the dependency relationship between the sub-resources.

[0106] Figure 5 This is a schematic flowchart of another embodiment of the application cold start method provided in this application. (Refer to...) Figure 5 The application cold start method provided in this application embodiment may include:

[0107] S501, during application cold start, the application loads the first resource into memory. The first resource includes a first sub-resource, a second sub-resource, and a third sub-resource.

[0108] It should be understood that, in order to facilitate the explanation of the application's determination of the execution method and execution order of sub-resources based on the dependencies between sub-resources, the example is taken where the first resource includes the first sub-resource, the second sub-resource, and the third sub-resource.

[0109] In S501, when an application starts cold, the first resource is loaded into memory, as described in S401.

[0110] S502, the application resolves the dependencies between the first sub-resource, the second sub-resource, and the third sub-resource, and determines that the third sub-resource depends on the second sub-resource.

[0111] Sub-resources may have dependencies on each other. In this embodiment, the third sub-resource depends on the second sub-resource as an example.

[0112] In some embodiments, a third sub-resource may depend on a first sub-resource, or the third sub-resource may depend on neither a first sub-resource nor a second sub-resource.

[0113] In some embodiments, after determining the dependencies between sub-resources, an application can establish a dependency graph. The dependency graph is used to indicate the dependencies between sub-resources. Taking module 1 as the first sub-resource, module 2 as the second sub-resource, and module 3 as the third sub-resource as an example, when module 3 depends on module 2, the dependency graph between the modules can be as follows: Figure 6 As shown.

[0114] S503, during the import initialization process, the application executes the file corresponding to the first sub-resource, but does not execute the files corresponding to the second and third sub-resources.

[0115] S503 can be referred to the description in S402.

[0116] In this embodiment of the application, since the third sub-resource depends on the second sub-resource, the application will not execute the file corresponding to the third sub-resource if the application does not execute the file corresponding to the second sub-resource.

[0117] In some embodiments, the third sub-resource can be a resource that is not needed (used) during application cold start.

[0118] In some embodiments, when the application determines that the third sub-resource depends on the first sub-resource, during the import initialization process, the application executes the file corresponding to the first sub-resource and the file corresponding to the third sub-resource, but does not execute the file corresponding to the second sub-resource.

[0119] In some embodiments, when the third sub-resource depends on neither the first nor the second sub-resource, during the import initialization process, the application executes the file corresponding to the first sub-resource, and can determine whether to execute the file corresponding to the third sub-resource based on whether the application needs to use the third sub-resource during a cold start. Specifically, the application may execute the file corresponding to the third sub-resource if it needs to use the third sub-resource during a cold start, and will not execute the file corresponding to the third sub-resource if it does not need to use the third sub-resource during a cold start.

[0120] S504, at the first moment, the application executes the file corresponding to the second sub-resource.

[0121] S504 can be referred to the description in S403.

[0122] S505, at the second moment, the application executes the file corresponding to the third sub-resource.

[0123] Because the third sub-resource depends on the second sub-resource, the application can execute the file corresponding to the third sub-resource after executing the file corresponding to the second sub-resource. The second moment is later than the first moment; in some embodiments, the second moment can be the moment when the application needs to use the third sub-resource.

[0124] The method by which the application executes the file corresponding to the third sub-resource can be referred to the relevant description in S403 regarding the application executing the file corresponding to the second sub-resource.

[0125] In some embodiments, refer to Figure 7 The application cold start method provided in this application embodiment can be summarized as follows:

[0126] Step 1, Construction

[0127] During the build process, the application can locate, download, and parse the imported first resource. Specifically, the application can load the first resource into memory and parse it to obtain the dependencies between its sub-resources.

[0128] Step 2, Instantiation

[0129] During instantiation, the application can load variables from sub-resources into memory (i.e., import variables) and point the sub-resources and their variables to the same memory location. It's important to note that for the first sub-resource, which is needed for application cold starts, after loading its variables into memory, the application can execute the corresponding file to assign values ​​to the variables. For the second and third sub-resources, which are not needed for application cold starts, after loading their variables into memory, the application does not need to execute the corresponding files; the variables in the second and third sub-resources in memory will be unassigned.

[0130] In some embodiments, for sub-resources that are not needed during application cold start, the application can add these sub-resources (such as second and third sub-resources) to a first list so that the application can execute the file corresponding to the sub-resource when needed. In some embodiments, the first list may include the memory locations of the second and third sub-resources, so that the application can query the second and third sub-resources in memory according to the first list when needed.

[0131] Step 3, Evaluation

[0132] During the evaluation process, the application can execute the files corresponding to the sub-resources that are needed. For example, the application can execute the files corresponding to the second sub-resource and the third sub-resource to assign values ​​to the variables in the second sub-resource and the third sub-resource in memory.

[0133] In this embodiment of the application, during the import initialization process, after loading the first resource, the application can parse the first resource to obtain the dependency relationship between the sub-resources in the first resource. In this way, the application can determine the execution method and execution order of the sub-resources based on the dependency relationship between the sub-resources to ensure the smooth execution of the application.

[0134] The following two examples illustrate the delayed execution method provided in the embodiments of this application:

[0135] Example 1: During a cold start, the application imports module 1, module 2, and module 3. Both module 2 and module 3 depend on module 1, and the import statement indicates that module 3 should be executed late.

[0136] In this example, refer to Figure 8 In the example 'a', the application imports module 1, module 2, and module 3. By resolving the modules, the application can obtain the dependencies between them, such as... Figure 8As shown in b, both module 2 and module 3 depend on module 1, and the application determines to delay the execution of module 3 by executing the import statement. (See reference...) Figure 8 In the `c` block, during the `import` initialization process, the application executes module 1 and its dependency module 2, but not module 3. During this process, the application can load variables from module 1 and module 2 into memory and assign values ​​to them. The application can also load variables from module 3 into memory but not assign values ​​to them. The application can record the location of module 3 in memory, such as adding its location to a first list.

[0137] Reference Figure 8 In the context of 'd', when the application needs to use module 3, the application can read the location of module 3 in memory from the first list and retrieve module 3 from memory to execute module 3. It should be understood that the application execution module in this embodiment can be understood as the file corresponding to the application execution module.

[0138] The following example compares and contrasts statically imported code with deferred execution code: one:

[0140] The code for static imports can be shown below:

[0141]

[0142] In the static import code (1), the import statement indicates that files a and b are imported, and the variable in file a is a, and the variable in file b is b. In the static import code (2), during the import initialization process, the application needs to execute files a and b, load the variable a in file a and the variable b in file b into memory, and assign values ​​to the variable a in file a and the variable b in file b.

[0143] In this example, the code executed by the application during the import initialization process can be as follows:

[0144] / / a.js

[0145] Let a = 1

[0146] export default a

[0147] console.log('a.js')

[0148] / / a.js

[0149] Let b = 2

[0150] export default b

[0151] console.log('b.js')

[0152] Referring to the code above, we can see that during the import initialization process, the application executes files a and b, loads the variable 'a' from file a and the variable 'b' from file b into memory, and assigns values ​​to the variables 'a' and 'b'. For example, the application assigns the value 1 to variable 'a' in file a and the value 2 to variable 'b' in file b. two:

[0154] The delayed execution code provided in this application can be shown as follows:

[0155]

[0156] Unlike the static import code (1), the deferred execution code (1) provided in this application indicates that the import statement imports file a and file b, and deferred execution of file b.

[0157] Therefore, in this example, the code executed by the application during the import initialization process can be as follows:

[0158] / / a.js

[0159] Let a = 1

[0160] export default a

[0161] console.log('a.js')

[0162] During the import initialization process, the application executes file a, loads variable a from file a into memory, and assigns a value to variable a. During the import initialization process, the application does not execute file b, but loads variable b from file b into memory, without assigning a value to variable b.

[0163] When the application needs to use file b at the first moment, it can execute the following code:

[0164] / / a.js

[0165] Let b = 2

[0166] export default b

[0167] console.log('b.js')

[0168] As can be seen from the code above: at the first moment, the application executes file b and assigns a value to the variable b in file b in memory.

[0169] Example 2: During a cold start, the application imports module 1, module 2, and module 3. Module 1 and module 2 have no dependency relationship, module 3 depends on module 1, and the import statement indicates that module 1 should be executed late.

[0170] In this example, refer to Figure 9 In the example 'a', the application imports module 1, module 2, and module 3. By resolving the modules, the application can obtain the dependencies between them, such as... Figure 9 As shown in b, module 1 and module 2 have no dependency relationship, module 3 depends on module 1, and the application determines to delay the execution of module 1 by executing the import statement. (See reference...) Figure 9 In the `c` block, during the `import` initialization process, the application executes module 2 but not module 1 or module 3, which depends on module 1. During this process, the application can load variables from module 2 into memory and assign values ​​to them. Similarly, the application can load variables from both module 1 and module 3 into memory but does not assign values ​​to them. The application can record the memory locations of module 1 and module 3, adding these locations to a first list.

[0171] Reference Figure 9 In the context of 'd', when the application needs to use module 1, it can read the location of module 1 from the first list, retrieve module 1 from memory, and execute module 1. Similarly, when the application needs to use module 3, it can read the location of module 3 from the first list, retrieve module 3 from memory, and execute module 3.

[0172] It is understood that the above example has the same technical principles and effects as the above embodiments, and the description in the above embodiments can be referred to.

[0173] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0174] The application cold start method of this application embodiment has been described above. The apparatus for executing the above method provided in this application embodiment is described below. Those skilled in the art will understand that the methods and apparatus can be combined and referenced with each other, and the related apparatus provided in this application embodiment can execute the steps in the above application cold start method.

[0175] This application provides an electronic device, with reference to... Figure 10 The electronic device may include a processor 1001 (e.g., a CPU) and a memory 1002. The memory 1002 may include high-speed random-access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device. The memory 1002 may store various instructions for performing various processing functions and implementing the method steps of this application.

[0176] Optionally, the electronic device involved in this application may further include: a power supply 1003, a communication bus 1004, and a communication port 1005. The communication port 1005 is used to enable communication between the electronic device and other peripherals. In this embodiment, the memory 1002 is used to store computer-executable program code, which includes instructions; when the processor 1001 executes the instructions, the instructions cause the processor 1001 of the electronic device to perform the actions in the above method embodiment. The implementation principle and technical effects are similar, and will not be repeated here.

[0177] Optionally, the electronic device involved in this application may further include: a display screen 1006. The display screen 1006 is used to display the interface of the electronic device.

[0178] This application provides a chip. The chip includes a processor, which calls a computer program in memory to execute the technical solutions in the above embodiments. Its implementation principle and technical effects are similar to those in the related embodiments described above, and will not be repeated here.

[0179] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, it implements the methods described above. The methods described in the above embodiments can be implemented wholly or partially by software, hardware, firmware, or any combination thereof. If implemented in software, the functionality can be stored as one or more instructions or code on or transmitted over the computer-readable medium. The computer-readable medium can include computer storage media and communication media, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.

[0180] In one possible implementation, a computer-readable medium may include random access memory (RAM), read-only memory (ROM), compact discread-only memory (CD-ROM) or other optical disc storage, magnetic disk storage or other magnetic storage devices, or any other medium targeted to carry or to store required program code in the form of instructions or data structures, and accessible by a computer. Furthermore, any connection is appropriately referred to as a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. As used herein, disks and optical discs include optical discs, laser discs, optical discs, digital versatile discs (DVDs), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0181] This application provides a computer program product, which includes a computer program that, when run, causes a computer to perform the above-described method.

[0182] It should be noted that the modules or components described in the above embodiments can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs), etc. Furthermore, when a module is implemented through processing element scheduler code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processors capable of calling program code, such as a controller. Additionally, these modules can be integrated together to implement a system-on-a-chip (SOC).

[0183] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).

[0184] The term "multiple" in this document refers to two or more. The term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Furthermore, the character " / " in this document generally indicates an "or" relationship between the preceding and following related objects; in formulas, " / " indicates a "division" relationship. Additionally, it should be understood that in the description of this application, words such as "first" and "second" are used only for descriptive purposes and should not be construed as indicating or implying relative importance or order.

[0185] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application.

[0186] It is understood that, in the embodiments of this application, the order of the above-mentioned process numbers does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

Claims

1. A method for applying cold start, characterized in that, Applied to electronic devices, the method includes: During application cold start, the first resource is loaded into memory, and the first resource includes a first sub-resource and a second sub-resource; Execute the file corresponding to the first sub-resource; At the first moment, the file corresponding to the second sub-resource is executed, where the first moment is the moment after the application's cold start is completed.

2. The method according to claim 1, characterized in that, After loading the first resource into memory, the process also includes: Load the variables from the first sub-resource and the variables from the second sub-resource into memory; The file corresponding to the first sub-resource is executed to assign values ​​to the variables in the first sub-resource. When the application cold start is completed, the variables in the first sub-resource in memory are assigned values, while the variables in the second sub-resource are not assigned values. The file corresponding to the second sub-resource is executed to assign values ​​to the variables in the second sub-resource in the memory.

3. The method according to claim 1 or 2, characterized in that, The first resource further includes a third sub-resource, which depends on the second sub-resource, and the method further includes: At a second time point, the file corresponding to the third sub-resource is executed, and the second time point is later than the first time point.

4. The method according to claim 3, characterized in that, After loading the first resource into memory, the process also includes: The dependencies between the sub-resources in the first resource are analyzed to find that the third sub-resource depends on the second sub-resource.

5. The method according to claim 3 or 4, characterized in that, After loading the first resource into memory, the process also includes: The variables in the third sub-resource are loaded into memory. When the application cold start is completed, the variables in the third sub-resource in memory have not been assigned values. The file corresponding to the third sub-resource is executed to assign values ​​to the variables in the third sub-resource in the memory.

6. The method according to any one of claims 1-5, characterized in that, Before loading the first resource into memory, the process also includes: Execute the import statement, which is used to instruct the loading of the first resource and to delay the execution of the file corresponding to the second sub-resource.

7. The method according to any one of claims 1-6, characterized in that, Before the application cold start is complete, it also includes: Write the location of the second sub-resource in the memory into the first list; The file corresponding to the second sub-resource is executed, including: Query the first list to determine the location of the second sub-resource in the memory; The second sub-resource is obtained at the stated location, and the file corresponding to the second sub-resource is executed.

8. An electronic device, characterized in that, The electronic device includes: one or more processors and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-7.

9. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the one or more processors being used to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes computer program code that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1-7.