Application starting method, electronic equipment and storage medium
By dividing the application's task group into multiple sub-task groups and creating sub-threads, the main thread monitors and takes over the sub-thread tasks, solving the problem of excessively long startup time for large applications, achieving fast response and efficient startup, and improving the user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, the application startup process relies on the main thread to load modules and resources, which leads to extended startup time for large applications and makes it difficult to meet users' needs for fast response and efficient startup.
By dividing the application's task groups into multiple sub-task groups and creating corresponding sub-threads, the main thread monitors the progress of the sub-threads and takes over their execution when a sub-task is not completed, thus avoiding the repeated execution of completed tasks and optimizing the task execution order of the main thread.
It effectively shortens application startup time, improves response speed, enhances user experience, and optimizes application startup efficiency.
Smart Images

Figure CN121764604A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal technology, and in particular to an application startup method, electronic device, and storage medium. Background Technology
[0002] In existing technologies, application startup often relies on the main thread to load the application's modules and resources (such as software development kits, SDKs). This design pattern, when dealing with large applications with complex functions and numerous modules, can lead to all loading tasks being executed on the main thread, thus prolonging application startup time, degrading user experience, and failing to meet users' demands for fast application response and efficient startup. Therefore, there is an urgent need to optimize relevant design patterns to further reduce application startup latency and ensure that users can quickly access the application after interacting with its icon. Summary of the Invention
[0003] This application provides an application startup method, an electronic device, and a storage medium, which can effectively reduce the startup time of applications.
[0004] To achieve the above objectives, this application adopts the following technical solution:
[0005] Firstly, this application provides an application startup method, which includes: determining M task groups corresponding to the startup of a first application, each task group including one or more subtasks, where M is an integer greater than or equal to 1; creating M sub-threads corresponding to a main thread based on the M task groups, the main thread being used to start the first application, the sub-threads corresponding one-to-one with the task groups, and the sub-threads being used to execute one or more subtasks in the corresponding task group; when it is detected that the first task to be executed by the main thread is the first subtask in the first task group that the first sub-thread has not yet completed, then notifying the first sub-thread to stop executing the first sub-task, and the main thread continuing to execute the first sub-task, wherein the first sub-thread is one of the M sub-threads, and the first task group is the task group corresponding to the first sub-thread among the M task groups; and starting the first application.
[0006] The application startup method provided in this application creates sub-threads corresponding to the number of task groups, so that the sub-threads execute multiple sub-tasks in the corresponding task group. When the first task that the main thread is about to execute is the same as the first sub-task that the sub-thread has not yet completed, the sub-thread stops executing the first sub-task, and the main thread takes over and executes the first sub-task. In this way, the main thread does not need to repeat the sub-tasks that the sub-thread has already completed, so that the time for the main thread to execute the sub-tasks that the sub-thread has already completed can be effectively saved during the startup process of the first application, further accelerating the startup process of the first application and optimizing the startup efficiency of the first application.
[0007] Furthermore, compared to the first child thread continuing to execute the first subtask, having the main thread take over the execution of the first subtask avoids the main thread being idle while waiting for the child thread to complete the first subtask, further speeding up the completion of the first subtask, effectively reducing the response time of the first application, accelerating the response speed of the first application, and improving the user experience.
[0008] The first application can be any application displayed on the desktop of an electronic device; it can also be an application encapsulated based on a web kernel or an application embedded in other applications (such as a mini-program).
[0009] It should be understood that the application startup method provided in the embodiments of this application can trigger any control, application icon or service during the startup process of the first application, so that the electronic device can start the first application in response to the above-mentioned triggering operation.
[0010] In practical design, the specific operation that triggers any control, application icon, or service can be a click, touch, single click, double click, two-finger swipe, or long press on any control or application icon for a preset duration. It can also be one or more of the following operations: key input, gesture recognition, body language recognition, voice recognition, facial expression recognition, eye movement recognition, and face recognition. This application does not impose specific limitations on this.
[0011] For example, during the startup process of the first application, M task groups can be obtained from the configuration file corresponding to the first application. These M task groups can be predefined during the development of the first application.
[0012] It should be understood that during the initial application startup process, the subtasks in the task group may include: error handling, security checks, permission checks, loading of asynchronous tasks (such as AsyncTask, Loader, etc.), callbacks and listeners, loading of resources corresponding to language and locale settings, component initialization, debugging, logging, performance monitoring and optimization, etc.
[0013] The tasks executed by the main thread can include not only the multiple subtasks in the task group in the example above, but also window creation, view management (such as measurement, layout, drawing, etc.), initialization operations (such as initializing database connections, initializing global variables or network requests, etc.), message loop processing, lifecycle callbacks, etc.
[0014] In one possible implementation of the first aspect, the method further includes: after the main thread has completed executing the first subtask, executing the second subtask, wherein the second subtask and the first subtask are subtasks in the same task group.
[0015] In one possible implementation of the first aspect, the main thread executes the first subtask, including: obtaining the task node corresponding to when the first subthread stops executing the first subtask; and the main thread executing the first subtask according to the task node.
[0016] In one possible implementation of the first aspect, creating M sub-threads corresponding to the main thread for launching the first application based on M task groups includes: creating M sub-threads based on the M task groups when the number of tasks executed by the main thread is less than or equal to a preset threshold.
[0017] In one possible implementation of the first aspect, the method for creating M child threads includes: the main thread calling a first interface to create M child threads; wherein, for the first application, the child threads created through the first interface have a higher priority than the child threads created through other interfaces.
[0018] In one possible implementation of the first aspect, the first interface includes the ffrt interface and the handler interface.
[0019] In one possible implementation of the first aspect, all M child threads are the highest priority child threads during the startup of the first application.
[0020] In one possible implementation of the first aspect, the subtasks in each task group belong to the same task type.
[0021] Secondly, this application provides an electronic device configured to perform the method in any possible implementation of the first aspect.
[0022] Optionally, the electronic device may include: a processor configured to: determine M task groups corresponding to the launch of a first application, each task group including one or more subtasks, where M is an integer greater than or equal to 1; create M sub-threads corresponding to a main thread based on the M task groups, the main thread being used to launch the first application, the sub-threads corresponding one-to-one with the task groups, and the sub-threads being used to execute one or more sub-tasks in the corresponding task group; when it is detected that the first task to be executed by the main thread is the first sub-task in the first task group that the first sub-thread has not yet completed, then notify the first sub-thread to stop executing the first sub-task, and let the main thread execute the first sub-task, where the first sub-thread is one of the M sub-threads, and the first task group is the task group corresponding to the first sub-thread among the M task groups; and launch the first application.
[0023] In one possible implementation of the second aspect, the processor is configured to execute the second subtask after the main thread has completed executing the first subtask.
[0024] In one possible implementation of the second aspect, the execution of the first subtask by the main thread includes: the processor being configured to obtain the task node corresponding to when the first subthread stops executing the first subtask; and the main thread executing the first subtask according to the task node.
[0025] In one possible implementation of the second aspect, M child threads corresponding to the main thread used to start the first application are created according to M task groups, including: when the number of tasks executed by the main thread is less than a preset threshold, M child threads are created according to the M task groups.
[0026] In one possible implementation of the second aspect, the method for creating M child threads includes: the main thread calling a first interface to create M child threads.
[0027] In one possible implementation of the second aspect, the first interface includes the ffrt interface and the handler interface.
[0028] In one possible implementation of the second aspect, all M child threads are the highest priority child threads during the startup of the first application.
[0029] In one possible implementation of the second aspect, the subtasks in each task group belong to the same task type.
[0030] Thirdly, this application provides a chip system including a processor that executes a computer program stored in a memory to implement the method in any possible implementation of the first aspect.
[0031] Fourthly, this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method in any possible implementation of the first aspect.
[0032] Fifthly, this application provides a computer program product including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method in any possible implementation of the first aspect.
[0033] The technical effects of the second to fifth aspects provided in this application can be found in the technical effects of the various possible implementations of the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0034] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0035] Figure 2 This is a schematic diagram of the software structure of an electronic device provided in an embodiment of this application.
[0036] Figure 3 This is a flowchart illustrating the application startup process provided in an embodiment of this application.
[0037] Figure 4 This is a schematic diagram of the trace recording result of the main thread during the application startup process, provided as an embodiment of this application.
[0038] Figure 5 This is a flowchart illustrating an application startup method provided in an embodiment of this application.
[0039] Figure 6 This is a schematic interactive diagram illustrating an application startup method provided in an embodiment of this application. Detailed Implementation
[0040] The technical solutions of the embodiments of this application are described below with reference to the accompanying drawings and related embodiments. In the description of the embodiments of this application, the terminology used in the following embodiments is for the purpose of describing specific embodiments only and is not intended to limit the application. As used in the specification and appended claims of this application, the singular expressions "a," "the," "the," "the," and "this" are intended to also include expressions such as "one or more," unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, "at least one" and "one or more" refer to one or more (including two). The term "and / or" is used to describe 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, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship.
[0041] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized. The term "connection" includes direct connections and indirect connections, unless otherwise stated. "First" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated.
[0042] In the embodiments of this application, the words "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of the words "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.
[0043] The application launch method provided in this application can be applied to electronic devices. For example, electronic devices may include, but are not limited to, personal computers (PCs), smartphones, netbooks, tablets, smart cameras, wearable devices, handheld computers, smart TVs, personal digital assistants (PDAs), portable multimedia players (PMPs), projection devices, smart screen devices, augmented reality (AR) / virtual reality (VR) devices, mixed reality (MR) devices, in-vehicle devices, smart screens, cloud servers, televisions, or motion-sensing game consoles in human-computer interaction scenarios. This application does not impose any restrictions on the specific type of electronic device.
[0044] See Figure 1 This is a schematic diagram of the structure of an electronic device 100 provided in this application. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 131, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0045] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0046] For example, when the electronic device 100 is a mobile phone or a tablet computer, it may include all the components shown in the figure, or it may include only some of the components shown in the figure.
[0047] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0048] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0049] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0050] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0051] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU performs mathematical and geometric calculations and is used for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information. The display screen 194 is used to display images, videos, etc.
[0052] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0053] Internal memory 131 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 131. Internal memory 131 may include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a given function (such as sound playback, image playback, etc.). The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.).
[0054] In addition, the internal memory 131 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0055] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. For example, the software system of electronic device 100 can adopt a layered architecture. Operating system (OS). In some implementations, the operating system of electronic device 100 can adopt a layered architecture.
[0056] See Figure 2 This is a software structure block diagram of the electronic device 100 according to an embodiment of this application.
[0057] In some embodiments, a layered architecture can divide software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the operating system is divided into four layers, from top to bottom: the application layer, the application framework layer, the runtime and system libraries, and the kernel layer.
[0058] The application layer can include a series of application packages.
[0059] like Figure 2 As shown, the application package may include applications such as camera, gallery, calendar, call, memo, navigation, WLAN, Bluetooth, music, video, and SMS.
[0060] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0061] like Figure 2 As shown, the application framework layer may include a runtime management service, a window manager, a content provider, a view system, a phone manager, a resource manager, and a notification manager, etc.
[0062] Runtime management services are a type of service within the operating system used to manage the operation of applications, such as managing the lifecycle of activities. Most applications can contain user interface components, primarily used for user interaction, such as making phone calls, sending emails, and viewing maps. Most of the content users see in the application is provided by these components. For example, depending on the operating system, user interface components can be capabilities, activities, or UIViewControllers. For ease of understanding, the following text will primarily use capabilities as an example.
[0063] During the application startup process, the runtime management service is mainly used to receive the application startup request in order to manage the application's lifecycle, manage the application process and the components corresponding to the process, and be responsible for scheduling the application process to adjust the application's running state.
[0064] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0065] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0066] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0067] The phone manager is used to provide communication functions for electronic device 100. For example, it manages call status (including connection and disconnection).
[0068] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0069] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of download completion or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0070] The runtime includes the core libraries and the virtual machine. The runtime is responsible for the scheduling and management of the operating system.
[0071] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0072] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0073] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, and AMR.
[0074] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0075] A 2D graphics engine is a graphics engine for 2D drawing.
[0076] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0077] To better understand the embodiments of this application, firstly, in conjunction with... Figure 3 An exemplary description is provided of the startup process of any application on the desktop of electronic device 100.
[0078] When a user touches the icon of any application on the desktop of an electronic device, the application's launch process is triggered. During launch, the application (client) first sends a launch request to the runtime management service (server). As the manager of the launch process, the runtime management service creates and starts the application process upon receiving the request. This process then starts its main thread to execute the application's code. After a series of key stages during launch, the main thread finally displays the application's main interface (or homepage) on the desktop.
[0079] See Figure 3 The aforementioned key stages may include:
[0080] Phase 1: Handling the Launch Application
[0081] It's easy to understand that after the main thread starts, it can first enter the application startup phase to prepare for the application to start.
[0082] Runtime initialization: Initializes the application's runtime environment, including starting the virtual machine, loading necessary system libraries (such as libc, libm, etc.), and configuring the class loader (such as PathClassLoader or DexClassLoader) to ensure that the application can successfully load and execute the corresponding code. For example, this virtual machine can be the Ark Virtual Machine, the Java Virtual Machine, or a virtual machine for other programming languages.
[0083] Load extension: Depending on the application, it may load extension modules or libraries that the application depends on to achieve corresponding extended functions, such as security hardening, performance optimization, or specific hardware support.
[0084] Get module info: For applications with multiple modules, this stage can retrieve module information for each module, such as the module's storage path, dependencies, and version, so that the corresponding module can be loaded quickly later.
[0085] Phase Two: HandleLaunchAbility Phase
[0086] This stage primarily involves loading capabilities related to the main interface. It should be understood that capabilities related to the main interface can also be called main capabilities. In summary, main capabilities are a type of component in the application responsible for implementing business functions related to the user interface. This stage mainly involves:
[0087] Transform memory structure: By transforming the memory structure of the compiled bytecode file (e.g., the abc.class file), the corresponding code in the bytecode file can be executed, thereby optimizing memory usage efficiency and reducing resource consumption.
[0088] Resource loading strategy: Use a preset strategy (such as depth first search (DFS) or dependency-driven) to load the resources required by the main Ability (such as Wi-Fi module or Bluetooth module) to ensure that the main interface elements can be rendered correctly.
[0089] `loadmodule`: Modules from dynamic-link libraries (DLLs) can be dynamically loaded using functions like `dlopen`. After a module is loaded, functions like `dlsym` can be used to obtain the addresses of functions or variables defined within the module. These addresses can then be used to initialize the module, thus loading modules that the main Ability depends on (including the aforementioned bytecode files), ensuring the main Ability is ready.
[0090] Phase Three: AbilityTransaction Phase
[0091] After the main Ability's dependent modules are loaded, the capability transaction phase begins, where configurations related to the main interface's lifecycle are performed:
[0092] start: Initiates the lifecycle of the main Ability, such as starting to display the application's main interface on an electronic device.
[0093] `create`: You can initialize the main interface by creating the main Ability instance and calling lifecycle methods such as `onCreate`.
[0094] foreground: This brings the main interface to the foreground. You can perform operations such as setting window properties and drawing interface elements to ultimately present the main interface to the user.
[0095] Phase 4: Window Loading Phase
[0096] Before the main interface with specific content is displayed, the loading window stage is mainly responsible for loading the window frame associated with the main interface, providing a container or carrier for subsequent page rendering and display.
[0097] Fifth stage: Page loading stage
[0098] Finally, the loadpage stage can fill the loaded window with specific display content, including layout files, images, text, etc., to complete the final presentation of the main interface and thus complete the application startup process.
[0099] In some examples, between the capability transaction phase and the loading window phase, there may also be intermediate phases such as main Ability preparation, lifecycle callbacks, page layout parsing, and data binding. These phases work together to ensure a smooth start and display of the application's main interface.
[0100] like Figure 4The diagram shown is a schematic representation of the trace recording results corresponding to the above-mentioned key stages of the main thread execution, provided in an embodiment of this application. Figure 4 The y-axis represents the number of tasks, which is determined by... Figure 4 As can be seen, during application startup, the main thread needs to perform many tasks in certain stages (such as the application startup phase) to load the corresponding modules. This design pattern, when faced with large applications with complex functions and numerous modules, may lead to a large number of loading tasks being executed on the main thread, thus prolonging the application startup time and failing to meet users' needs for fast response and efficient startup, thereby degrading the user experience. Therefore, it is urgent to optimize the relevant design patterns to further reduce application startup latency and ensure that users can quickly enter a usable state after interacting with the application icon.
[0101] Therefore, this application provides the application startup method described in the following embodiments. This method can stop the child thread from executing the first subtask when the first task to be executed by the main thread is the same as the first subtask that the child thread has not yet completed, and instead allow the main thread to take over and complete the first subtask. Based on this, the main thread does not need to repeatedly execute the subtask already completed by the child thread, thus accelerating the application startup process. Furthermore, since the main thread has a higher priority and efficiency in executing tasks than the child thread, having the main thread take over and continue completing the first subtask avoids idle time for the main thread while waiting for the child thread to complete the first subtask, further accelerating the completion of the first subtask, effectively reducing the response time of the first application, further optimizing the startup performance of the first application, and improving the user experience.
[0102] It should be noted that in the embodiments of this application, "application" and "application program" are the same concept, referring to the same content. One of the descriptions is used in different places, and the two can be used interchangeably.
[0103] The application launch method provided in this application will be described below with reference to specific embodiments.
[0104] like Figure 5 The diagram shown is a flowchart of an application startup method provided in an embodiment of this application. See also... Figure 5 The method may include:
[0105] S501, determine the M task groups corresponding to the first application, each task group includes one or more subtasks.
[0106] Where M is an integer greater than or equal to 1. It is easy to understand that the specific value of M can be set according to the actual situation of different applications (such as different functions or storage size, etc.), and no restrictions are imposed here.
[0107] It should be understood that, in the embodiments of this application, the first application can be any application displayed on the desktop of an electronic device; it can also be an application encapsulated based on a web kernel; or it can be an application embedded in other applications (such as a mini-program).
[0108] In some embodiments, the M task groups corresponding to the first application can be obtained from the configuration file corresponding to the first application. In practical applications, the M task groups can be predefined in the configuration file of the first application. In other possible implementations, the M task groups can also be user-defined.
[0109] In this embodiment, any one of the M task groups may include one or more subtasks. A subtask may be a portion of the multiple tasks executed by the main thread during the startup of the first application.
[0110] It should be understood that the number of subtasks in different task groups may be the same or different. This application does not impose any restrictions on this.
[0111] In some examples, the M task groups can be independent of each other, meaning there is no dependency between the task groups. In this way, the M task groups can be executed in parallel during the application startup process. Compared with executing the subtasks in each task group serially, this can further shorten the application startup time and reduce the complexity of program design.
[0112] In other examples, there may be dependencies between the M task groups. Based on this, the execution order of each task group can be set in the configuration file to avoid loading errors and other problems, so that the M task groups can be executed in an orderly manner during the startup of the first application, thereby completing the normal startup of the first application.
[0113] In some embodiments, multiple subtasks within each task group may have the same task type. That is, the subtasks within each task group belong to the same task type.
[0114] Since tasks of the same type often have similar execution requirements and / or similar modules that need to be loaded, grouping tasks of the same type into the same task group can centrally process subtasks of the same type, optimize the order and parallelism of task execution, reduce unnecessary waiting time, and further accelerate the overall startup speed of the application.
[0115] Furthermore, this setup improves code organization and maintainability, enabling developers to more clearly understand and manage the logical relationships and dependencies between task groups and subtasks. A unified error handling mechanism and performance monitoring can also be implemented later, allowing for rapid location and resolution of problems during program execution, as well as performance evaluation and optimization of each task group.
[0116] In some embodiments, a task group may also include one or more subtasks of different task types.
[0117] In this scenario, multiple subtasks within the task group can be sorted by task type. For example, subtasks with the same task type can be executed first (or last). Based on this, multiple subtasks with the same task type can be executed together, minimizing the problem of inefficient subtask execution caused by inconsistent task types.
[0118] As an example, and not a limitation, suppose task group A includes three subtasks: Task 1, Task 2, and Task 3. These three subtasks have the same task type (e.g., all are performance monitoring and optimization subtasks). During application startup, these three subtasks can be executed sequentially. In practice, due to application upgrades or other reasons, Task 4 can be added to task group A. The task type of Task 4 can be different from the three subtasks mentioned above; for example, Task 4 could be an asynchronous task processing subtask. Then, during application startup, for Tasks 1, 2, 3, and 4 in task group A, Tasks 1, 2, and 3 can be executed first, followed by Task 4; or Task 4 can be executed first, followed by Tasks 1, 2, and 3. This approach maintains the execution order of Tasks 1, 2, and 3 with the same task type while also ensuring the execution of Task 4, thus improving the efficiency of executing these multiple subtasks.
[0119] The subtasks in the above task group may include: error handling, security checks, permission checks, loading of asynchronous tasks (such as AsyncTask, Loader, etc.), callbacks and listeners, loading of resources corresponding to language and locale settings, component initialization, debugging, logging, performance monitoring and optimization, etc.
[0120] The tasks executed by the main thread can include not only one or more subtasks from a set of subtasks, as shown in the example above, but also other tasks required to launch the first application. These can include window creation, view management (e.g., measurement, layout, drawing), initialization operations (e.g., initializing database connections, initializing global variables, or network requests), message loop processing, and lifecycle callbacks.
[0121] It's important to note that during the initial application startup, the number of tasks executed by the main thread can be greater than the number of subtasks. This allows the main thread to execute the initial application startup tasks while the subtasks within their respective task groups are executed simultaneously. When the task executed by the main thread is the same as a subtask executed by another thread, the main thread takes over the execution of the unexecuted subtasks in the task group. This allows the main thread to take advantage of the time difference between the subtasks already completed by the subtasks that the other threads no longer need to execute, further reducing the startup time of the initial application and improving its startup efficiency.
[0122] In some embodiments, the electronic device can trigger the startup process of the first application in response to a user's trigger operation on the first application. The trigger operation can be used to trigger any control, application icon, or service, so that the electronic device can respond to the trigger operation and execute the application startup methods provided in the various embodiments of this application to launch the first application.
[0123] It should be understood that the specific operation that triggers any control, application icon, or service can be a click, touch, single click, double click, two-finger swipe, or long press on any control or application icon for a preset duration. It can also be one or more of the following operations: key input, gesture recognition, body language recognition, voice recognition, facial expression recognition, eye movement recognition, and face recognition. This application does not specifically limit this.
[0124] S502, create M child threads corresponding to the main thread based on M task groups. The main thread is used to start the first application. The child threads correspond one-to-one with the task groups and are used to execute one or more sub-tasks in the corresponding task group.
[0125] It should be understood that the relevant content of the main thread can be referred to in the previous introduction, and will not be repeated here.
[0126] In this embodiment, the number of sub-threads created according to the task groups is equal to the number of task groups, meaning each sub-thread corresponds to one task group. During the startup of the first application, each sub-thread can execute one or more sub-tasks in its corresponding task group in parallel.
[0127] For example, suppose there are three task groups corresponding to the first application, namely Group1, Group2 and Group3. Then, three sub-threads can be created according to the above three task groups, such as sub-thread 1, sub-thread 2 and sub-thread 3. Among them, sub-thread 1 can correspond to Group1 and is used to execute one or more sub-tasks in task group Group1; sub-thread 2 can correspond to Group2 and is used to execute one or more sub-tasks in task group Group2; sub-thread 3 can correspond to Group3 and is used to execute one or more sub-tasks in task group Group3.
[0128] In some embodiments, if the main thread meets preset conditions, M corresponding child threads can be created based on M task groups.
[0129] In one example, the preset condition may include the number of tasks executed by the main thread being less than or equal to a preset threshold. The preset threshold can be set according to the actual situation of the first application.
[0130] For example, suppose the first application startup process takes 8 seconds (ignoring the main thread creation time). In time period A (0-2 seconds), 3 tasks are executed; in time period B (2-5 seconds), 20 tasks are executed; in time period C (5-6 seconds), 5 tasks are executed; and in time period D (6-8 seconds), 10 tasks are executed. Then, the preset threshold can be set to 5. That is, if the number of tasks executed by the main thread is less than or equal to 5, then M child threads can be created based on M task groups.
[0131] Based on the above example, the main thread can create M child threads corresponding to the M task groups when the number of tasks executed within the first time period is less than or equal to a preset threshold. Continuing with the above example, the first time period can be time period A and / or time period C. That is, the main thread can create M child threads based on the M task groups when the first application starts (i.e., 0s after the first application starts); and / or at the 5th second during the first application's startup process.
[0132] It is easy to understand that, based on the above example, when the number of tasks executed by the main thread is less than or equal to 5, it can be considered that the number of tasks executed by the main thread during this period is small and the processor's workload is small. In this case, the M child threads created can be used to execute the sub-tasks of the corresponding task group. While making full use of the processor, the speed of completing all sub-tasks in the task group can be accelerated, so as to effectively reduce the response time of the first application.
[0133] In another example, the preset condition may also include that the number of tasks executed by the main thread in the first phase is less than or equal to a preset threshold. In other words, when the number of tasks executed by the main thread in the first phase is less than or equal to the preset threshold, M child threads are created according to the M task groups.
[0134] For example, see Figure 3 and Figure 4 Of the five key stages involved in the illustrated embodiment, the stage prior to processing the application startup phase (see...) Figure 4In the case of t1), the number of tasks executed by the main thread is relatively small. Assuming that the number of tasks in the t1 stage is 2, the preset threshold can be set to 2. Then, if the number of tasks executed by the main thread is less than or equal to 2, the aforementioned M sub-threads can be created according to the M task groups so that the M sub-threads can execute the sub-tasks in the corresponding task groups respectively.
[0135] Based on the example above, the first stage is the stage preceding the application startup stage. It should be understood that, depending on the specific circumstances, the first stage could also be… Figure 3 and Figure 4 Other stages in the illustrated embodiments.
[0136] Of course, the preset threshold in the aforementioned preset conditions can also be 0, that is, when the number of tasks executed by the main thread is 0 (i.e. the processor is idle), the main thread can also create the aforementioned M child threads based on the M task groups.
[0137] In some embodiments, the method for creating M child threads can be that the main thread calls a first interface to create M child threads. The first interface may include a function flow runtime (ffrt) interface, a handler interface, or an interface corresponding to another programming language.
[0138] It should be noted that child threads can also be created based on different interfaces (or modules) provided by different programming languages and libraries. For example, in Java, child threads can be created using the Thread class and the ExecutorService interface; in C++, child threads can be created using std::thread and related standard library functions; in Python, child threads can be created using the threading module, and so on.
[0139] In some embodiments, the M child threads can have the same priority, or the highest priority child thread during the startup of the first application can be selected. That is, the priority of the M child threads is lower than the main thread's priority, but higher than the priorities of other child threads. This ensures that child threads can prioritize processing subtasks within the task group during the startup of the first application, thereby completing subtasks faster and improving the startup efficiency of the first application.
[0140] S503: When it is detected that the first task to be executed by the main thread is the first subtask in the first task group that the first child thread has not completed, the first child thread is notified to stop executing the first subtask, and the main thread continues to execute the first subtask.
[0141] Here, the first child thread can be any one of the M child threads, and the first task group can be the task group corresponding to the first child thread among the M task groups. The first subtask can be a subtask that the first child thread in the first task group is preparing to execute or is currently executing.
[0142] It should be understood that the first task to be executed by the main thread can be any of the tasks executed by the main thread in the aforementioned embodiments. For details, please refer to the relevant content in the aforementioned embodiments, which will not be repeated here.
[0143] If the first task to be executed by the main thread and the first sub-task that the first child thread has not yet completed are the same task, the main thread can notify the first child thread to stop executing the first sub-task, and the main thread can take over the execution of the first sub-task. In other words, when the first task to be executed by the main thread and the first sub-task that the first child thread is actually executing or is currently executing are the same, the completion of the first sub-task can be accelerated by switching threads (i.e., switching from the first child thread to the main thread).
[0144] In some embodiments, if the first subtask is a subtask being executed by the first sub-thread, the main thread can, after notifying the first sub-thread to stop executing the first subtask, obtain the task node corresponding to when the first sub-thread stopped executing the first subtask, so that the main thread can continue executing the first subtask according to the task node. That is, when the main thread detects that the first task to be executed by the main thread is the first subtask being executed by the first sub-thread, the main thread can notify the first sub-thread to stop executing the first subtask and obtain the task node corresponding to when the first sub-thread stopped executing the first subtask, so that the main thread can continue executing the first subtask from the task node corresponding to the first subtask.
[0145] In one possible scenario, the first subtask can be the last subtask in the first task group. That is, when the first task to be executed by the main thread is the last subtask in the first task group (i.e., the first subtask) that the first subthread has not yet completed, the main thread can take over from the first subthread and continue executing the first subtask until the first subtask is completed.
[0146] In another possible scenario, the first subtask may not be the last subtask in the first task group. In this case, when the first subtask is not the last subtask in the first task group, the second subtask can continue to be executed after the main thread finishes executing the first subtask. The second subtask is the subtask in the first task group that has not been executed after the first subtask. That is, the first subtask and the second subtask are both subtasks in the same task group.
[0147] S504, launch the first application.
[0148] It's easy to understand that after the main thread finishes executing the first subtask, or after the main thread finishes executing the first and second subtasks, it can continue to execute other tasks to complete the startup of the first application, thus launching the first application.
[0149] Based on the application startup method described in various embodiments of this application, by creating sub-threads corresponding to the number of task groups, the sub-threads execute multiple sub-tasks in the corresponding task group. When the first task that the main thread is about to execute is the same as the first sub-task that the sub-thread has not yet completed, the sub-thread stops executing the first sub-task, and the main thread takes over and executes the first sub-task. In this way, the main thread does not need to repeat the sub-tasks that the sub-thread has already completed, so that the time for the main thread to execute the sub-tasks that the sub-thread has already completed can be effectively saved during the startup process of the first application, further accelerating the startup process of the first application and improving the startup efficiency of the first application.
[0150] Furthermore, compared to the first child thread continuing to execute the first subtask, the main thread is more efficient in executing the task. The main thread taking over the execution of the first subtask from the first child thread can avoid the main thread being idle while waiting for the child thread to complete the first subtask, further speeding up the completion of the first subtask, effectively reducing the response time of the first application, speeding up the response speed of the first application, and improving the user experience.
[0151] Based on the above Figure 5 The application launch method shown is as follows: Figure 6 The diagram illustrates a data interaction process corresponding to the application startup method described above, as provided in an embodiment of this application. It mainly involves data transmission between the main thread and child threads, where the child threads may include child thread 1, child thread 2, ..., child thread M. See also... Figure 6 The aforementioned data interaction process may specifically include:
[0152] Step 601: The first application loads the configuration file.
[0153] It should be understood that, in the embodiments of this application, the configuration file may include M task groups and multiple subtasks corresponding to each of the M task groups.
[0154] In some embodiments, the configuration file may also include the storage path (realPath) of the compiled file corresponding to the first application, module information, and other information. It is easy to understand that after the first application is installed on the electronic device, the configuration file is usually stored in a certain storage path of the operating system (i.e., the aforementioned realPath). Therefore, the compiled bytecode file corresponding to the first application can be obtained through the storage path to execute the code in the bytecode file and launch the first application. The module information may include information such as the module name, which can be used to call different modules during application startup to implement corresponding functions.
[0155] Step 602: The first application sends a request to the runtime management service to start the first application.
[0156] For example, the request sent by the first application to the runtime management service to start the first application can be StartAbility, so that the runtime management service can start a new Ability.
[0157] During the startup of the first application, its configuration file is first loaded into the code execution environment (e.g., a virtual machine) so that the code corresponding to the first application can be executed. Then, the first application sends a request to the runtime management service to initiate its startup.
[0158] Step 603: The runtime management service creates the corresponding main thread based on the received request to start the first application.
[0159] In practical applications, after receiving a request from the first application to start the first application, the runtime management service can create an application process corresponding to the first application and perform tasks such as allocating process IDs and process memory. Then, it can use the application process corresponding to the first application to create the main thread for starting the first application, allowing the main thread to execute... Figure 3 The document outlines several key stages for launching the first application.
[0160] Step 604: The main thread sends multiple subtasks from the M task groups to the child thread.
[0161] It should be understood that, see Figure 6 After the main thread is created, it can create child thread 1, child thread 2, ..., child thread M by calling the first interface, so that each of the above child threads can execute one or more subtasks in the corresponding task group. In step 604, the main thread can send one or more subtasks in the corresponding task group to the corresponding child thread, so that the child thread can execute the subtasks in the corresponding task group in sequence after receiving the corresponding one or more subtasks.
[0162] Step 605: When the main thread detects that the first task to be executed by the main thread is the first subtask in the first task group that the first child thread has not completed, the main thread notifies the first child thread to stop executing the first subtask.
[0163] It's not hard to understand, see Figure 6 The first child thread can be any one of child thread 1, child thread 2, ..., child thread M. For example, if the first child thread is child thread 1, then the first task group can be the task group corresponding to child thread 1 among the M task groups.
[0164] If the first task to be executed by the main thread is the same subtask that the first child thread is preparing to execute or is currently executing, then the main thread can notify the first child thread to interrupt the execution of the first subtask in the first task group, and the main thread can take over from the first child thread to complete the first subtask. Based on this embodiment, if there is an unexecuted second subtask after the first subtask in the first task group, then the main thread can continue to execute the second subtask after completing the first subtask.
[0165] Correspondingly, if the main thread detects that the second task to be executed by the main thread is the third sub-task that the first sub-thread has already completed, then the main thread can stop executing the second task and continue executing the tasks after the second task.
[0166] Similarly, if the main thread detects that the third task to be executed by the main thread is the fourth subtask in the second task group that the second sub-thread has already completed, then the main thread can stop executing the third task and continue executing the tasks after the third task. It's easy to understand that the second sub-thread can be one of M sub-threads; the second task group can also be one of M task groups; and the fourth subtask can be one of the multiple subtasks in the M task groups that correspond to the second task group.
[0167] The details regarding the first application, M task groups, and multiple subtasks in steps 601 to 605 above can be found in the aforementioned text. Figure 5 The corresponding descriptions in the embodiments described herein will not be repeated here.
[0168] Furthermore, it is understandable that the above Figure 6 The data interaction flow diagram shown is only an example of the above application startup method. The flow diagram provided in this application does not constitute a specific limitation on the processing flow for starting the first application.
[0169] It should be understood that the sequence number of each step in the above embodiments 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.
[0170] Based on the application launch methods provided in the above embodiments, this application also provides the following:
[0171] This application provides an application launch device and / or electronic device for executing the above-described application launch method, achieving the same effect as the above-described implementation method.
[0172] When using an integrated unit, the application launch device and / or electronic device may include a processor (or processing module) and a display (or display module), wherein the processor may implement or execute various exemplary application launch methods described in conjunction with the disclosure of this application. The display may be used to display the user interface corresponding to the application in the foregoing embodiments.
[0173] Optionally, the application initiation device and / or electronic device described above may also include a memory (or storage module), which can be used to store computer programs or instructions.
[0174] This application provides a computer program product, which includes a program that, when run by an electronic device, enables the application launch method shown in the above embodiments of the electronic device.
[0175] This application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the application startup methods shown in the above embodiments.
[0176] This application provides a chip including a memory and a processor. The processor executes a computer program stored in the memory to control the electronic device to execute the application startup method shown in the above embodiments.
[0177] It should be understood that the processor mentioned in the embodiments of this application can be a CPU, or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.
[0178] It should also be understood that the memory mentioned in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0179] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. In the above embodiments, the descriptions of each embodiment have different focuses; parts not described in detail or recorded in a certain embodiment can be referred to in the relevant descriptions of other embodiments.
[0180] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0181] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between devices or units through some interfaces, and may be electrical, mechanical, or other forms.
[0182] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0183] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0184] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a large-screen device, a recording medium, a computer memory, a read-only memory, a random access memory, an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0185] Finally, it should be noted that the above description is only a specific implementation of this application, but the protection scope of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be covered within the protection scope of this application.
Claims
1. An application starting method characterized by comprising: The method comprises: determining M task groups corresponding to starting a first application, each of the task groups comprising one or more sub-tasks, wherein M is an integer greater than or equal to 1; creating M sub-threads corresponding to a main thread according to the M task groups, the main thread being used to start the first application, the sub-threads corresponding to the task groups one by one, and the sub-threads being used to execute one or more sub-tasks in the corresponding task groups; when it is monitored that a first task to be executed by the main thread is a first sub-task in a first task group which is not executed by a first sub-thread, notifying the first sub-thread to stop executing the first sub-task, and continuing to execute the first sub-task by the main thread, wherein the first sub-thread is one of the M sub-threads, and the first task group is a task group corresponding to the first sub-thread in the M task groups; starting the first application.
2. The application launch method of claim 1, wherein, The method further comprises: after the main thread executes the first sub-task, executing a second sub-task; the second sub-task and the first sub-task are sub-tasks in the same task group.
3. The application launch method according to claim 1 or 2, wherein The execution of the first sub-task by the main thread comprises: obtaining a task node corresponding to the first sub-thread stopping executing the first sub-task; the main thread executes the first sub-task according to the task node.
4. The application launch method according to any one of claims 1 to 3, wherein The creation of M sub-threads corresponding to the main thread for starting the first application according to the M task groups comprises: when the number of tasks executed by the main thread is less than or equal to a preset threshold, creating M sub-threads according to the M task groups.
5. The application launch method according to any one of claims 1 to 4, wherein The method further comprises: the main thread calls a first interface to create the M sub-threads; wherein for the first application, the priority of the sub-threads created by the first interface is higher than that of the sub-threads created by other interfaces.
6. The application launch method of claim 5, wherein, The first interface comprises an ffrt interface and a hander interface.
7. The application launch method according to any one of claims 1 to 6, wherein The M sub-threads are all sub-threads with the highest priority in the starting process of the first application.
8. The application launch method according to any one of claims 1 to 7, wherein, The sub-tasks in each of the task groups belong to the same task type.
9. An electronic device, comprising: The electronic device is configured to execute the method of any one of claims 1-8.
10. A chip system, characterized by The chip system comprises a processor, and the processor executes a computer program stored in a memory to implement the method of any one of claims 1-8.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method of any one of claims 1-8.