Application program compiling method and electronic equipment

By rapidly installing applications under high load and optimizing compilation when the load decreases, the problem of low execution efficiency of DEX file interpretation is solved, thereby improving application running efficiency and making reasonable use of system resources.

CN121635893APending Publication Date: 2026-03-10HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

In Android virtual machines, the interpretation and execution efficiency of DEX files is low, resulting in low application running efficiency. Furthermore, the dex2oat compilation optimization method is time-consuming and consumes a lot of device resources.

Method used

Under high load, the application is installed using the first compilation mode without compilation optimization. Once the load decreases, compilation optimization is performed to ensure application installation speed and system load balance, thereby improving operating efficiency.

Benefits of technology

By dynamically adjusting the compilation mode, the system load is reduced, the application running efficiency is improved, long-term inefficient operation is avoided, and the user experience is optimized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121635893A_ABST
    Figure CN121635893A_ABST
Patent Text Reader

Abstract

The application program compiling method comprises the steps that in response to a first installation operation on a first target application, the electronic equipment installs the first target application through a first compiling mode under the conditions that the first target application is not a long keep-alive application and the load state is a high load; the first compiling mode does not execute compiling optimization; and after the first target application is installed, if the load state is changed from the high load state to the low load state, the electronic equipment compiles and optimizes the first target application in a second compiling mode. The embodiment of the invention can be used for avoiding overload operation of the equipment and ensuring the operation efficiency of the first application.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of terminal equipment, and in particular to an application program compiling method and an electronic device. BACKGROUND

[0002] After an application is installed on an electronic device, an Android virtual machine can identify a DEX file, and load the DEX file into memory during use of the application, interpret and execute byte code, and the running efficiency is very low, which affects the experience of the user using the device. To solve the above problem, dex2oat compiling optimization can be used, and before the Android system runs, the dex file byte code can be converted into machine code that can be executed on the virtual machine in advance, and the machine code can be directly executed during application running, so as to improve the application running efficiency. However, the installation time is long and the device processing resources are more occupied by using the dex2oat compiling optimization mode. SUMMARY

[0003] The application embodiment provides an application program compiling method and an electronic device, which can be used to avoid overloading of the device and ensure the running efficiency of the first application.

[0004] In a first aspect, an application program compiling method is provided, which is applied to an electronic device, and the method comprises the following steps: in response to a first installation operation of a first target application, when the first target application is not a long-keep-alive application and a load state is high load, the electronic device installs the first target application through a first compiling mode; the first compiling mode does not perform compiling optimization; after the first target application is installed, when the load state changes from high load to low load, the electronic device performs compiling optimization on the first target application through a second compiling mode.

[0005] In the application embodiment, when the system load is high, the electronic device installs an application that is not a long-keep-alive application, and can be installed according to the first compiling mode without performing compiling optimization, so that the installation speed is fast, the system load is reduced, the situation of lag is reduced, and the user experience is improved; when the system load changes from high load to low load, the second compiling mode is used for compiling optimization, so that the system load is not too high and the running efficiency of the first target application is higher.

[0006] In a possible implementation, after the first target application is installed by the first compiling mode and before the first target application is compiled and optimized by the second compiling mode, the electronic device converts the bytecode of the first target application into machine code during running of the first target application; after the first target application is compiled and optimized by the second compiling mode, the electronic device directly executes the machine code of the first target application during running of the first target application. In this way, after the first target application is compiled and optimized according to the second compiling mode, the electronic device can directly execute the machine code of the first target application, thereby improving the running efficiency of the first target application.

[0007] In a possible implementation, the method further includes: in a case where the first target application is the long-keep-alive application, installing the first target application by the second compiling mode. In this way, in the case of installing the long-keep-alive application, the second compiling mode is directly used for installation regardless of the system load, the running efficiency after installation is considered preferentially, and the problem of low running efficiency and high resource occupation of the long-keep-alive application caused by long-term inability to restart is avoided, thereby improving the system execution efficiency in the long term and relieving the system load pressure.

[0008] In a possible implementation, the method further includes: in a case where the first target application is not the long-keep-alive application and the load state is the low load, installing the first target application by the second compiling mode. In this way, in the case where the system load is in the low load, the second compiling mode is directly used for installation, the installation times are reduced, and the case where the system load is high is avoided, thereby ensuring smooth running of the device and user experience.

[0009] In a possible implementation, the method further includes: in response to a first installation operation of the first target application, determining, by the electronic device, whether the first target application is the long-keep-alive application; the long-keep-alive application is an application that can keep a life cycle in an active state in response to a user exit operation; in a case where the first target application is not the long-keep-alive application, determining, by the electronic device, whether the load state is the high load. In this way, the electronic device can ensure that the long-keep-alive application is directly installed according to the second compiling mode, and the application that is not the long-keep-alive application can be installed according to the load state, the system load is ensured to be small, the system lag is reduced, and the smooth running of the system is ensured.

[0010] In a possible implementation, the electronic device determining whether the load state is high load includes: the electronic device determining whether a first condition is met; the first condition includes at least one of a core state condition, a memory usage condition and a temperature condition; the core state condition is a condition that a first core busy state rate is less than or equal to a threshold core busy state rate, the first core busy state rate being a probability that a core state of the electronic device is busy in a first time period; the memory usage condition is a condition that a first memory usage is less than or equal to a threshold memory usage; the temperature condition is a condition that a processor temperature is less than or equal to a threshold temperature; the electronic device determining that the load state is high load when the first condition is not met; and determining that the load state is low load when the first condition is met. In this way, the electronic device can determine the load state according to the characteristic information of the memory load, thereby ensuring the accuracy of the load determination and the accuracy of the selection of the compilation mode.

[0011] In a possible implementation, in response to a first installation operation of the first target application, the method further includes: the electronic device starting to acquire load parameters, the load parameters including one or more of a core state of the electronic device, the first memory usage and the processor temperature; and after the electronic device installs the first target application by the first compilation mode, the method further includes: the electronic device acquiring load information based on the load parameters; and the load information including a first core busy state rate, the first memory usage and the processor temperature. In this way, the electronic device can acquire the load parameters in advance, thereby ensuring the accuracy of the load information, and further ensuring the accuracy of the selection of the compilation mode and the timing.

[0012] The load information is used to measure the load state.

[0013] In a possible implementation, the electronic device determining whether the first target application is a long-keep-alive application includes: the electronic device determining whether a long-keep-alive application list includes an application package name of the first target application; the first target application being a long-keep-alive application when the long-keep-alive application list includes the application package name of the first target application; and the first target application not being a long-keep-alive application when the long-keep-alive application list does not include the application package name of the first target application. In this way, the electronic device can determine whether the installed application is a long-keep-alive application according to the preset long-keep-alive application list, thereby ensuring the accuracy of the determination, and further ensuring the accuracy of the selection of the compilation mode and the timing.

[0014] The electronic device can be preset with a long-keep-alive application list, and the long-keep-alive application list includes at least one application package name.

[0015] In a possible implementation, after the installation of the first target application is completed, the method further includes: determining, by the electronic device, whether the load state is a low load; the load information is used to represent the load degree of the memory of the electronic device; when the load state is not a low load, the electronic device continues to determine whether the load state is a low load. In this way, after the installation according to the first compilation mode is completed, the running efficiency of the first target application is low, and therefore the load state of the monitoring system is monitored, the monitoring is maintained in a high load, and the optimization according to the second compilation mode is compiled in a low load, so as to ensure the efficient running after the compilation, and the overall low system load and the improved application running efficiency can be taken into account.

[0016] In one possible implementation, the electronic device includes a first target application, a package management service (PMS), a real-time service module, and a bytecode optimization module. In response to a first installation operation on the first target application, when the first target application is not a long-running application and is under high load, the electronic device installs the first target application via a first compilation mode, comprising: the first target application, in response to the first installation operation, sending a target application installation request to the PMS, the target application installation request including the application package name of the first target application; the PMS sending installation request information to the real-time service module, the installation request information being used to request the installation of the first target application; the real-time service module determining whether the first target application is a long-running application based on the installation request information; if the first target application is not a long-running application, the real-time service module obtaining load information and determining whether the load state is high load based on the load information; if the load state is high load, the real-time service module sending target compilation mode information to the PMS; the target compilation mode information being used to request the installation of the first target application according to the first compilation mode; and the PMS installing the first target application according to the target compilation mode. The information is used to install the first target application according to the first compilation mode; the PMS sends installation request information to the bytecode optimization module; the bytecode optimization module verifies the first file based on the installation request information, and sends an installation completion notification to the PMS; after the first target application is installed, the electronic device determines whether the load state is low load, including: after the first target application is installed, the real-time service module determines whether the load state is low load; if the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through a second compilation mode, including: when the load state is low load, the real-time service module sends second compilation mode information to the PMS; the second compilation mode information is used to request compilation optimization of the first target application according to the second compilation mode; the PMS compiles the first target application according to the second compilation mode; the PMS sends compilation request information to the bytecode optimization module; the bytecode optimization module compiles the first file based on the compilation request information to obtain a second file, and the bytecode optimization module sends a compilation completion notification to the PMS. In this way, for applications that are kept alive for a long time, the installation package can be directly interpreted and executed to obtain a second file for fast execution, avoiding the inefficiency of not being able to run the second file due to the low probability of startup after installation.For applications that are not kept alive for extended periods and are under high load, electronic devices can install using the first compilation mode to improve installation speed, reduce processing load, and ensure smooth device operation. When the target compilation mode is the first compilation mode, the electronic device needs to continue monitoring the load status. When the load is low, it should be optimized using the second compilation mode. For applications that are not kept alive for extended periods, the second compilation mode can avoid high-load periods and compile during low-load periods, reasonably controlling the use of processing resources, reducing system lag, and improving user experience.

[0017] The first file is a DEX file, and the second file is an OAT file.

[0018] In a second aspect, embodiments of this application provide an electronic device, the electronic device including one or more processors and one or more memories; the one or more processors are coupled to the one or more memories, the one or more memories being used to store computer program code, the computer program code including computer instructions, and when the one or more processors execute the computer instructions, causing the electronic device to perform an application compilation method as described in the first aspect or any possible implementation of the first aspect.

[0019] Thirdly, embodiments of this application provide a computer program product containing instructions that, when run on an electronic device, cause the electronic device to execute an application compilation method as described in the first aspect or any possible implementation thereof.

[0020] Fourthly, embodiments of this application provide a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform an application compilation method as described in the first aspect or any possible implementation thereof.

[0021] Fifthly, embodiments of this application provide a chip system applied to an electronic device. The chip system includes one or more processors, which are configured to invoke computer instructions to cause the electronic device to execute an application compilation method as described in the first aspect or any possible implementation thereof. Attached Figure Description

[0022] Figure 1 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application;

[0023] Figure 2 This is a schematic diagram of the software structure of an electronic device according to an embodiment of this application;

[0024] Figures 3A-3EThese are schematic diagrams of a set of user interfaces proposed in the embodiments of this application;

[0025] Figure 4A and Figure 4B This is a schematic diagram illustrating the process of compiling and running an application under different compilation modes as proposed in the embodiments of this application;

[0026] Figure 5 This is a schematic diagram of an application compilation method flow proposed in an embodiment of this application;

[0027] Figure 6 This is a schematic diagram of an application installation and compilation process proposed in an embodiment of this application;

[0028] Figure 7 This is a schematic diagram of an application compilation method flow proposed in an embodiment of this application;

[0029] Figure 8 This is a schematic diagram of a method for obtaining a target compilation mode according to an embodiment of this application;

[0030] Figure 9 This is a schematic diagram of an application installation and compilation process proposed in an embodiment of this application. Detailed Implementation

[0031] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to and includes any or all possible combinations of one or more of the listed items.

[0032] The following section first introduces the terminology used in the embodiments of this application.

[0033] I. Compiling the application:

[0034] An application (APP) runs in a virtual machine (Android Runtime Library ART in Android systems). The execution of application code by the virtual machine consists of two parts. The first part is compiling the source code into bytecode, also known as front-end compilation, which mainly involves lexical, syntactic, and semantic analysis. The second part is compiling the bytecode into machine code for interpretation and execution.

[0035] In Just-in-Time (JIT) compilation, bytecode is compiled into native machine code at runtime. However, when the interpreter performs JIT compilation, it needs to compile the native machine code, which is time-consuming. This results in low interpreter efficiency and a significant impact on user experience. Action-Oriented (AOT) technology addresses this issue. In AOT, during the installation of the Android application package (Android APK), the system uses the dex2oat (Dalvik Executable file to optimized ART file) tool to compile the DEX (Dalvik Executable) files in the APK into an OAT (Optimized ART) file containing native machine code for storage. In the Android system, there are two runtime executable file formats: DEX files and OAT files. DEX files are the standard executable file format running on the Dalvik virtual machine, while OAT files are an optimized executable file format running on the ART virtual machine. In other words, dex2oat can compile the application's bytecode into machine code in advance, allowing direct execution of the machine code at runtime, thus greatly improving application performance. The application needs to load the DEX file at runtime. If an OAT file is included, ART uses the OAT file directly; if no OAT file is included, ART executes the DEX file via JIT and an interpreter.

[0036] II. Different compilation modes:

[0037] dex2oat includes several different build modes, ranked by application performance. Common build modes include: speed, speed-profile, and verify. The speed build mode optimizes all application code, resulting in high-performance output, but it generates large files, takes a long time, and consumes a lot of phone storage. The speed-profile build mode relies on a profile file and can optimize hot functions of the application. The verify build mode only verifies the application's dex file. The verify build mode generally performs worse compilation performance than the speed-profile build mode.

[0038] The electronic devices in the embodiments of this application may be mobile phones, tablets, desktops, laptops, handheld computers, smart bracelets, super mobile personal computers, netbooks, personal phones, personal data assistants, augmented reality (AR) / virtual reality (VR) and other touch screen devices. This application does not limit the specific form of the electronic devices.

[0039] The apparatus involved in the embodiments of this application is described below.

[0040] Figure 1 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application.

[0041] Electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, 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.

[0042] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device 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.

[0043] Processor 110 may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). These different processing units may be independent devices or integrated into one or more processors.

[0044] 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.

[0045] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a limitation on the structure of the electronic device. In other embodiments of this application, the electronic device may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0046] The wireless communication function of electronic devices can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0047] Electronic devices implement display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connecting the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0048] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.

[0049] Touch sensor 180K, also known as a "touch panel". Touch sensor 180K can be set on display screen 194. Touch sensor 180K and display screen 194 together form a touch screen, also known as a "touch screen". Touch sensor 180K is used to detect touch operations on or near it.

[0050] In this embodiment, the electronic device 100 can detect user operations via the touch sensor 180K. User operations may include touch events from the user to the display screen 194, such as the user tapping an object in the shooting preview screen to focus.

[0051] Alternatively, user operation can also be air operation, voice operation commands, etc. For example, electronic devices are equipped with gesture sensing sensors that can detect air operations by the user.

[0052] Figure 2 This is a schematic diagram of the software structure of an electronic device provided in an embodiment of this application.

[0053] like Figure 2 As shown, the software framework of the electronic device involved in this application may include an application layer, an application framework layer (framework, FWK), an Android runtime (ART), and system libraries.

[0054] The application layer may include a series of application packages, such as calendar, map, music, gallery, SMS, call, social software, browser, app store, etc. (These applications are not shown in the above examples). In this embodiment, the electronic device can install applications through a first application, such as an app store or browser. The app store can obtain the user's operation to install each application and request the electronic device to install that application.

[0055] 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. For example... Figure 2 As shown, the application framework layer may include a window manager, a content manager, an activity manager service (AMS), a resource manager, etc.

[0056] Android Management System (AMS) is a service in the Android system responsible for managing and scheduling the lifecycle and task stack of application activities. AMS manages the activity lifecycle by using system resources and data structures (such as processes, task stacks, and recording the state of the activity lifecycle). For example, it manages the creation, running, and destruction of applications.

[0057] In this embodiment of the application, the application framework layer may also provide system services, which may include package manager service (PMS), Android runtime server (ART server), and real-time service modules (e.g., IAware real-time service).

[0058] PMS can perform application installation and compilation optimization, and its main workload is to install, manage and uninstall applications on Android devices. PMS receives installation requests for target applications from the first application and performs installation processing based on the target compilation mode of the target application.

[0059] As a communication interface with the Android runtime, the Art service can interact with modules of the Android runtime through PMS and participate in the execution of compilation optimization processes.

[0060] The real-time service module, upon receiving an installation request from the PMS, determines the target compilation mode for installation based on the current target application and current load.

[0061] The Android runtime is responsible for scheduling and managing the Android system. In this embodiment, ART provides a bytecode optimization module (dex2oat) for application startup.

[0062] The bytecode optimization module is capable of compiling and processing the application's DEX file. After receiving compilation instructions, the bytecode optimization module can compile and process the DEX file according to the instructions. The target compilation mode identifier in the compilation instructions instructs the bytecode optimization module to compile and process the application's DEX file using the corresponding compilation mode, while the target kernel identifier in the compilation instructions instructs the bytecode optimization module to run on the corresponding kernel to compile and process the application's DEX file.

[0063] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0064] 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.

[0065] It should be noted that the application provides Figure 2 The software architecture diagram of the electronic device shown is only an example and does not limit the specific module division in different layers of the Android operating system. For details, please refer to the introduction of the Android operating system software architecture in conventional technology.

[0066] Combination Figure 2 The software structure in this application is obtained through Figures 3A-3E Describe the user scenarios that illustrate the application installation process.

[0067] Figures 3A-3E These are exemplary user interface diagrams disclosed in the embodiments of this application. Figures 3A-3E This describes how the electronic device displays the installation process when a user performs the operation of installing a target application on the app store interface.

[0068] like Figure 3A As shown, when a user turns on an electronic device, the desktop interface 310 that can be displayed on the electronic device is shown. Figure 3A This is a schematic diagram of the user's desktop interface on an electronic device. For example... Figure 3AAs shown, the electronic device can display application icons such as clock, calendar, gallery, memo, file manager, email, music, calculator, browser, and app store 311. Users can click on the app store 311 application icon, responding to the actions described above, such as... Figure 3B As shown, the electronic device can display the user interface 320 of an app store. The first application used here is an app store as an example.

[0069] like Figure 3B As shown, the app store's user interface 320 displays a curated list of apps 321, which includes several recommended apps. The user clicks the install button corresponding to app A in the app list 321. In response to this user action, the electronic device installs app A and displays the app store's user interface 330, as shown. Figure 3C As shown, the app store's user interface 330 displays an icon 331 indicating that app A is being installed. After installation, the electronic device displays the app store's user interface 340, as shown... Figure 3D As shown, the user interface 340 of the application store displays the open control 341 for application A.

[0070] When the user interface 340 of the application store is displayed on the electronic device, the user can click the open control 341 of application A. For example... Figure 3E As shown, in response to the aforementioned opening operation, the electronic device begins running application A and displays application A's startup interface 350. The startup interface varies depending on the application installed, and this application does not limit this.

[0071] The above installation of application A is based on the selected recommendations within the app store. Users can also search for a specific application to install, or install or upgrade a new version of an existing application, etc. The above situations are just examples and are not limited.

[0072] It should be noted that the above application installation process is only one installation method and interface of the application store. Users can also perform installation operations through a browser or other applications with application installation permissions, and electronic devices can perform corresponding installation processes, etc. This application does not limit this.

[0073] exist Figures 3A-3E During application installation, electronic devices should be installed according to the corresponding compilation mode. The following describes two different compilation modes: verify and speed-profile.

[0074] Figure 4A and Figure 4B This is a schematic diagram illustrating the process of compiling and running an application under different compilation modes, as provided in an embodiment of this application.

[0075] like Figure 4A As shown, in the verify build mode, after the electronic device receives the installation request for the target application, it begins the installation using the verify build mode. Since no compilation is required, only verification, the installation time is short and fast. After the target application is installed, when the electronic device receives the running request for the target application, the target application runs according to the first mode. During the running process, the virtual machine needs to interpret and execute the bytecode (i.e., interpret and execute the DEX file). Only after interpretation and execution can machine code be obtained and processed. Therefore, the running efficiency of the target application in the first mode is low.

[0076] like Figure 4B As shown, in the speed-profile compilation mode, after the electronic device receives the installation request for the target application, it optimizes the compilation using a profile file, converting the bytecode in the application installation package into machine code (the target application's installation package may include a profile file). This profile file is large, and the compilation process is time-consuming. Therefore, compared to the verify compilation mode, the installation time of the target application in the speed-profile compilation mode is longer. After the target application is installed, if the electronic device receives a request to run the target application, the target application runs according to the second mode. During the target application's execution, the machine code can be directly executed on the hardware platform (i.e., the OAT file is executed). Therefore, the target application runs efficiently after the speed-profile compilation mode. Machine code is binary instructions directly executed by computer hardware, has a low level of abstraction, and is code that the hardware can directly understand and execute.

[0077] After comparison, it was found that the verify compilation mode only performs verification processing during installation, without converting bytecode to machine code. This results in a shorter installation time and faster speed, but the virtual machine needs to interpret and execute the bytecode during runtime, leading to lower efficiency. Conversely, the speed-profile compilation mode requires converting the bytecode of the installation package to machine code during installation, resulting in a longer installation time and slower speed. However, the virtual machine does not need to interpret the bytecode during runtime; the hardware can directly execute the machine code, resulting in faster and smoother operation.

[0078] Based on the above, to make the application run more smoothly, the application's DEX file should be compiled using des2oat during the application installation process. This compilation, achieved through speed-profile compilation, transforms the application into machine code that the electronic device can directly run. The electronic device can then directly load this machine code during application execution, resulting in smoother application performance.

[0079] It should be noted that electronic devices can also be compiled using the speed compilation mode or other methods, and this application does not limit this.

[0080] Combination Figure 4A and Figure 4B To ensure a smoother application installation process, the following describes an application compilation method.

[0081] Figure 5 This is a schematic flowchart illustrating an application compilation method disclosed in an exemplary embodiment of this application. The electronic device may include a first application, a PMS, an ART service, and a bytecode optimization module. The above four modules can be referenced... Figure 2 The relevant descriptions in the text will not be repeated here.

[0082] like Figure 5 As shown, the compilation method for this application may include, but is not limited to, the following steps:

[0083] S501: The first application obtains the first operation of the target application.

[0084] The first step is to install the target application. The first step could be... Figure 3B The installation operation can be a click-to-install operation, a user voice control operation, a gesture control operation, or an installation operation within other applications. This application does not limit the specific operation method of the first operation. The first application can be a browser, an app store, or other application with application installation permissions; this application does not limit this. The target application is the application that needs to be installed.

[0085] In addition, after the electronic device obtains the first operation of the target application, it can start downloading the target application's installation package (APK file). The installation package may include a DEX file, which is used for compilation optimization during the installation process.

[0086] S502: The first application responds to the first operation by sending a target application installation request to the PMS.

[0087] After the first application receives the initial operation to install the target application, in response to the aforementioned operation, the first application can send a target application installation request to the PMS. The target application installation request includes the installation package name of the target application. The target application installation request is used to request the installation of the target application.

[0088] S503: PMS performs installation processing on the installation package of the target application.

[0089] Specifically, PMS creates an installation directory for the application on the electronic device and writes the installation files from the installation package into the installation directory. For example, PWS creates an installation directory for "Application A" on the phone, such as data / app / ... / applicationA, and writes the installation files, such as DEX files, from the target application's APK installation package into the installation directory.

[0090] After receiving the target application installation request, PMS can call the ProcessPendingInstall() function to wait for the process to install and the ProcessInstallRequests() function to request the process to install. It can also call the ProcessApkInstallRequests() function to handle APK installation tasks and the InstallPackages() function to request the start of the target application installation.

[0091] S504: PMS sends a compilation request message to the ART service.

[0092] Installation request information can be used to request the compilation of an installation package. This information includes parameters such as the target application's installation package name and installation directory.

[0093] Specifically, PMS can call the ExecutePostCommitStepsLIF() function to send installation request information to the bytecode optimization module.

[0094] S505: The ART service determines the compilation mode.

[0095] After receiving the installation request information, the ART service can determine the compilation mode. The ART service can determine the compilation mode by executing functions including decoptPackage() and dexopt(), which are used to determine the compilation mode used when installing the current target application.

[0096] S506: The ART service sends a request for compilation task information to the bytecode optimization module.

[0097] The request for compilation task information can be used to request the compilation of the installation package. Installation request information includes parameters such as the target application's compilation mode, the installation package name, and the installation directory.

[0098] S507: The bytecode optimization module compiles the first file based on the requested compilation task information.

[0099] The first file is the DEX file in the APK installation package of the target application. The bytecode optimization module can compile the first file based on the requested compilation task information.

[0100] The bytecode optimization module calls the Dexopt() function to perform dex2opt compilation optimization. Specifically, the bytecode optimization module can compile the target application's installation package according to the speed-profile compilation mode, that is, interpret and execute the DEX file (i.e., the first file) in the installation package to obtain the OAT file (the second file), and store the OAT file.

[0101] S508: The bytecode optimization module sends a compilation completion notification to the PMS via the ART service.

[0102] After the bytecode optimization module completes the compilation of the first file based on the installation request information, it can send a compilation completion notification to the PMS via the ART service. Correspondingly, the PMS can receive the compilation completion notification from the bytecode optimization module via the ART service. The compilation completion notification indicates that the target application has been compiled successfully.

[0103] S509: PMS sends an installation completion notification to the first application.

[0104] After receiving the compilation completion notification, PMS sends an installation completion notification to the first application. Correspondingly, the first application receives the installation completion notification from PMS. The installation completion notification indicates that the target application has been successfully installed.

[0105] S510: The first application displays installation completion information.

[0106] After the first application receives the installation completion notification, it can display installation completion information. For example, such as... Figure 3D As shown, after the target application (e.g., application A) is installed, the open control 341 can be displayed to indicate that application A has been installed.

[0107] Optionally, if the electronic device is currently displaying its main desktop interface, the main desktop interface can begin displaying the icon of the target application from the point where no icon of the target application is currently displayed. In this case, the electronic device also includes a desktop application, which can begin displaying installation completion information, i.e., begin displaying the icon of the target application.

[0108] Figure 5 During the application compilation process, installation is performed using only the speed-profile compilation mode. After installation, the machine code in the OAT file can be directly executed by the hardware, resulting in high application performance. However, this also leads to longer installation times, longer waiting times for users, and a poor user experience.

[0109] To address the above situation, an application compilation method is proposed. First, the application can be installed using the verify compilation mode. After installation, the target application can run immediately upon user startup. Following installation using the verify compilation mode, the electronic device can compile the installation package according to the speed-profile compilation mode. Once installation is complete, when the application's thread starts, the machine code compiled according to the speed-profile compilation mode can be run, resulting in higher running efficiency for the target application.

[0110] Figure 6 This is a schematic diagram illustrating an application installation and compilation process provided in this application. For example... Figure 6 As shown, after the electronic device receives the target application installation request, it first verifies the installation package using the verify compilation mode and then installs the target application. After the target application is installed, it receives a target application execution request (the user can quickly use the target application by clicking to open it), and the electronic device runs the target application according to the first mode. During the first mode execution, the virtual machine needs to interpret and execute the bytecode. Simultaneously, after the target application is installed, the installation package can be optimized through the speed-profile compilation mode after a period of time. Only after the optimization is complete, and if the target application is started (the startup conditions must exist after compilation), can the target application run in the optimized second mode, i.e., it can directly execute machine code.

[0111] Typically, after compiling and installing in verify mode, the user opens the target application and runs it in the first mode. Simultaneously, the electronic device optimizes the application's installation package using speed-profile mode. Only after the target application's running thread terminates and is recreated can it run in the second mode. However, some application threads remain active for extended periods. For example, for applications frequently used by users, to reduce processing time each time the user opens the device, the electronic device doesn't terminate these application threads in the background, thus reducing response time and improving user experience. Installing such applications can cause the electronic device, even after compiling in speed-profile mode, to continue running in the first mode without waiting for the application's thread to be recreated, resulting in low efficiency and excessive resource consumption.

[0112] In addition, the speed-profile compilation mode consumes a lot of processing resources for the installation package. If the current memory load is high, continuing to use the speed-profile compilation mode will further squeeze processing resources. When the memory is overloaded, the power consumption is high, the overall processing efficiency of the machine is low, the response time is long, and the user experience of the device is poor.

[0113] To address the aforementioned issues, this application proposes an application compilation method and an electronic device. During the installation of a target application, the electronic device can determine the target compilation mode based on whether the target application is a long-term keep-alive application and its current load status. The electronic device can then install the target application according to the target compilation mode. For long-term keep-alive applications, or non-long-term keep-alive applications with low load status, the electronic device can install according to a second compilation mode, generating a second file after compilation to improve running efficiency. This allows long-term keep-alive applications to directly interpret and execute the installation package, obtaining a second file for fast execution, avoiding inefficient operation due to low likelihood of startup after installation and the inability to use the second file. For non-long-term keep-alive applications with high load status, the electronic device can install according to a first compilation mode, improving installation speed, reducing processing load, and ensuring smooth device processing. When the target compilation mode is the first compilation mode, the electronic device needs to continue monitoring the load status and optimize compilation according to the second compilation mode when the load status is low. For non-long-term keep-alive applications, the second compilation mode can avoid high-load periods, compiling during low-load periods, reasonably controlling the use of processing resources, reducing system lag, and improving user experience.

[0114] Figure 7 This application provides an exemplary method for compiling an application, such as... Figure 7As shown, the electronic device may include a first application, a PMS, a real-time service module, an ART service, and a bytecode optimization module. These modules can be referenced from [reference needed]. Figure 2 The relevant descriptions in the documentation are omitted here. The compilation methods for this application may include, but are not limited to, executing the following methods:

[0115] S701: The first application obtains the first operation of the target application.

[0116] The processing procedure of S701 can be referred to the relevant content of S501, and will not be repeated here.

[0117] S702: In response to the first operation, the first application sends a load parameter acquisition request to the real-time service module.

[0118] After the real-time service module receives the load detection request, it can begin to obtain load information.

[0119] S703: The real-time service module begins acquiring load parameters.

[0120] The load parameters reflect the current system performance and resource scheduling. Load information may include kernel status.

[0121] It should be noted that, if the load information can include the first kernel busy rate, the electronic device can begin acquiring the kernel status of all processor cores of the electronic device at a first frequency. The kernel status can include busy and idle states. A busy state indicates that a task is being executed or a request is being processed; an idle state indicates that there are currently no tasks to process or that the device is waiting.

[0122] S702 and S703 are optional steps. When the load parameters do not include the kernel state, the electronic device may not execute steps S702 and S703. This application does not limit this.

[0123] S704: The first application responds to the first operation by sending a target application installation request to the PMS.

[0124] The steps in S704 can be referenced from those in S502, and will not be elaborated here.

[0125] S705: PMS sends the first installation request information to the real-time service module.

[0126] After receiving the target application installation request, the PMS can send the first installation request information to the real-time service module. Correspondingly, the real-time service module receives the installation request information from the PMS. This installation request information may include the application package name of the target application.

[0127] S706: PMS sends a second installation request to the ART service.

[0128] After receiving the target application installation request, the PMS can send a second installation request to the ART service. This second installation request can be used to request the installation of the target application, and the ART service will process the installation task based on this second installation request. The second installation request may include the application package name of the target application.

[0129] There is no restriction on the execution order between S705 and S706; both S705 and S706 can be executed after S704.

[0130] S707: The real-time service module determines the target compilation mode based on the first installation request information and the system load status.

[0131] After receiving the installation request information from the PMS, the real-time service module needs to determine the target compilation mode based on the installation request information and system load status. The S707 processing procedure is as follows: Figure 8 The method for obtaining the target compilation mode is explained below:

[0132] Figure 8 This is a schematic diagram of a method for obtaining a target compilation mode according to an embodiment of this application. Figure 8 As shown, the method for obtaining the target compilation mode may include, but is not limited to, the following steps:

[0133] S801: The real-time service module obtains the package name of the target application based on the installation request information.

[0134] The installation request information includes the package name of the target application, and the real-time service module can obtain the package name of the target application based on the installation request information.

[0135] S802: The real-time service module determines whether the target application is a long-term, keep-alive application. If the target application is a long-term, keep-alive application, execute S806; if the target application is not a long-term, keep-alive application, execute S803.

[0136] Electronic devices are stored in a long-term active application list. The real-time service module can determine whether a target application is a long-term active application by checking if the target application's package name is included in the long-term active application list. If the target application's package name is included in the long-term active application list, the target application is confirmed to be a long-term active application; if the target application's package name is not included in the long-term active application list, the target application is confirmed not to be a long-term active application.

[0137] For example, the list of apps that are kept active includes social media app A, message notification app B, etc. Specifically, if the target app is social media app A, then the target app is determined to be a long-term active app; if the target app is health and fitness app C, then health and fitness app C is not included in the long-term active app list, and the target app is determined not to be a long-term active app. The above is merely an illustrative description and does not constitute a limitation.

[0138] Among them, "long-term active applications" are those that remain active in their lifecycle after the user terminates the application; "non-long-term active applications" are those that terminate in their lifecycle after the user terminates the application (changing from an active state to a terminated state). The differences between long-term active and non-long-term active applications are explained below in conjunction with the interface display and the application's lifecycle (activity).

[0139] When application A is a persistent application, while the electronic device displays the user interface of application A (application A's lifecycle is active), the user swipes up to enter the multitasking desktop, which includes an interface card for application A. The user then swipes up on the interface card for application A in the multitasking desktop to terminate the current execution thread of application A (i.e., the user terminates the application). In response to the user's termination of application A, the electronic device does not terminate the lifecycle of application A; application A remains active in the background, and its activity is not destroyed. In other words, the user's termination of application A's execution does not end the lifecycle of the (active) persistent application A.

[0140] If application B is not a persistent application, when the electronic device displays the multitasking desktop interface, including the card interface of application B (application B's lifecycle is active), the user swipes up on the card interface of application B in the multitasking desktop to terminate the current execution thread of application B. In response to the above operation, the electronic device ends the lifecycle of application B, and the lifecycle of application B becomes terminated (killed). The activity of application A is destroyed. That is, the user's operation to terminate the running of application B will terminate the lifecycle of application B (a non-persistent application).

[0141] It should be noted that the list of applications kept alive for extended periods can be fixed or can change according to user habits; this application does not limit this. The list of applications kept alive for extended periods is generally related to the device's thread management for each application, and should include at least one application, though the specific number is not limited.

[0142] S803: The real-time service module obtains the current system load information.

[0143] Load information indicates the current system load level and reflects the current system performance and resource scheduling. Load information may include one or more of the following: first kernel busy rate, first memory usage, and processor temperature. The following provides a detailed explanation of first kernel busy rate, first memory usage, and processor temperature:

[0144] The first kernel busy rate is the probability that the electronic device's kernel is in a busy state within a first time period. Kernel state refers to the core state of the electronic device's processor. Kernel states can include both busy and idle states. A busy state indicates that the corresponding processor core is occupied and processing a task; an idle state indicates that the corresponding processor core is not occupied and is idle. The electronic device can obtain the kernel state of each core at a first frequency within the first time period, and then calculate the first kernel busy rate, which is the ratio of the number of busy states to the total number of kernel states. The first time period can be from 30 seconds to 5 minutes.

[0145] For example, for an 8-core electronic device, the kernel status of each of the 8 cores is acquired 5 times within 2 minutes, resulting in a total of 40 kernel statuses. If 24 kernel statuses are busy, the first kernel busy rate is 24 / 40 = 60%. If 32 kernel statuses are busy, the first kernel busy rate is 32 / 40 = 80%. The above calculations of the number of memory cores and the first kernel busy rate for the electronic device are illustrative and not limiting.

[0146] The primary memory usage is the ratio of the memory currently used by the electronic device to the total memory. The primary memory usage can be the most recently obtained memory usage or the average of memory usage obtained within the most recent second time period.

[0147] Processor temperature can be the temperature value of the processor in an electronic device. The first processor temperature can be the most recently acquired processor temperature, or it can be the average of the processor temperatures acquired within the most recent third time period.

[0148] S804: The real-time service module determines whether the load status is high. If the load status is high, the electronic device executes S805; if the load status is low (not high), the electronic device executes S806.

[0149] The load status includes two states: high load and low load. Electronic devices can determine whether the current load level is high based on the load information.

[0150] The electronic device determines whether the current load state is high load by judging whether the load information meets a first condition. If the first condition is met, the load state is high load; otherwise, it is low load. The first condition may include at least one of the following three conditions. If all the conditions included in the first condition are met, the electronic device can determine that the first condition is met; if one or more conditions (at least one condition) are not met, it can determine that the first condition is not met. The three conditions that may be included in the first condition are explained below:

[0151] Condition 1: The first kernel busy rate is less than or equal to (less than) the threshold kernel busy rate.

[0152] The electronic device is configured with a threshold kernel busy rate. The device determines whether a first kernel busy rate is less than or equal to (less than) the threshold kernel busy rate. If the first kernel busy rate is less than or equal to (less than) the threshold kernel busy rate, the electronic device determines that condition 1 is met; if the first kernel busy rate is greater than (greater than or equal to) the threshold kernel busy rate, the electronic device determines that neither condition 1 nor condition 1 is met. The threshold kernel busy rate can be set to 50%–95%.

[0153] Electronic devices can collect kernel status data over a recent period and calculate the probability of a busy state, thereby accurately determining the system load and ensuring the accuracy and effectiveness of load status measurement.

[0154] Condition 2: The first memory usage is less than or equal to (less than) the threshold memory usage.

[0155] Electronic devices can be set with a threshold memory usage. The electronic device determines whether the first memory usage is less than or equal to (less than) the threshold memory usage. If the first memory usage is less than or equal to (less than) the threshold memory usage, condition 2 is satisfied. If the first memory usage is greater than (greater than or equal to) the threshold memory usage, it is determined that neither condition 2 nor condition 1 is satisfied.

[0156] The threshold memory usage can be set from 50% to 90%. For example, if the threshold memory usage is 70%, and the first memory usage is 80%, then condition 2 is not met; if the first memory usage is 60%, then condition 2 is met.

[0157] Memory usage is a direct reflection of system load. Electronic devices can determine the load level by measuring memory usage, ensuring the accuracy and effectiveness of load measurement.

[0158] Condition 3: The processor temperature is less than or equal to (less than) the threshold temperature.

[0159] Electronic devices can be set with a threshold temperature. The electronic device determines whether the processor temperature is less than or equal to (less than) the threshold temperature. If the processor temperature is less than or equal to (less than) the threshold temperature, condition 2 is satisfied. If the processor temperature is greater than (greater than or equal to) the threshold temperature, condition 3 is not satisfied, nor is condition 1. The threshold temperature can be in the range of 30 degrees Celsius to 50 degrees Celsius.

[0160] The higher the processing load, the higher the processor temperature. Therefore, temperature can indirectly reflect the processor's operating status, and the load status can be effectively judged by temperature.

[0161] S805: The real-time service module determines the target compilation mode as the first compilation mode.

[0162] In the first compilation mode, the interpreter does not execute the interpretation of the first file during compilation. For example, the first compilation mode is the verify compilation mode.

[0163] Specifically, when the target application is not a long-lived application and the load status is high, the target compilation mode is determined to be the first compilation mode.

[0164] S806: The real-time service module determines the target compilation mode as the second compilation mode.

[0165] The compilation process in the second compilation mode includes the interpreter's interpretation and execution of the first file. For example, the second compilation mode is either the speed-profile compilation mode or the speed compilation mode.

[0166] Specifically, when the target application is a long-term keep-alive application, or when the target application is not a long-term keep-alive application and its load status is low, the target compilation mode is determined to be the second compilation mode.

[0167] The target compilation mode includes one of the first compilation mode and the second compilation mode. The first compilation mode performs verification processing during installation but does not perform compilation optimization. The second compilation mode requires compilation optimization during installation.

[0168] After the above processing steps S801 to S806, the electronic device can determine the target compilation mode and then continue to execute based on the target compilation mode.

[0169] In this embodiment, the target compilation mode includes a first compilation mode and a second compilation mode. The first compilation mode does not require the conversion of the bytecode of the installation package into machine code during installation; the second compilation mode requires the conversion of the bytecode of the installation package into machine code during installation.

[0170] S708: The Real-Time Service Module sends target compilation mode information to the ART Service.

[0171] After the real-time service module determines the target compilation mode, it can send the target compilation mode information to the ART service. Correspondingly, the ART service can receive the target compilation mode information from the real-time service module.

[0172] S709: The ART service determines the installation compilation mode based on the second installation request information and the target compilation mode information.

[0173] After receiving the target build mode information, the ART service can set the target application's installation build mode as the target build mode, i.e., the installation build mode is the target build mode. The ART service can then perform the installation process for the target application according to the target build mode.

[0174] S710: The ART service sends a request for compilation task information to the bytecode optimization module.

[0175] After determining the installation compilation mode based on the second installation request information and the target compilation mode information, the ART service can send a request compilation task information to the bytecode optimization module.

[0176] The request compilation task information includes the target compilation mode, which is used to request that the target application be processed according to the target compilation mode.

[0177] S711: The bytecode optimization module processes the first file based on the requested compilation task information.

[0178] After the bytecode optimization module receives the request compilation task information, it can process the first file according to the target compilation mode in the request compilation task information.

[0179] When the target compilation mode is the first compilation mode, the first file can be verified, which means verifying the installation package of the target application. When the target compilation mode is the second compilation mode, the first file can be optimized, which means pre-interpreting and executing the first file (DEX file) of the target application's installation package to obtain the second file (OAT file) (i.e., compilation optimization). Furthermore, verification can also be performed before interpretation and execution.

[0180] S712: The bytecode optimization module sends the first compilation completion notification to PMS via the ART service.

[0181] After the bytecode optimization module processes the first file based on the installation request information, it can send the first compilation completion notification to PMS via the ART service.

[0182] S713: PMS sends an installation completion notification to the first application.

[0183] After receiving the compilation completion notification, PMS can send an installation completion notification to the first application. The installation completion notification is used to indicate that the current target application has been installed.

[0184] In addition, after receiving the compilation completion notification, PMS can also send another installation completion notification to the desktop application, triggering the desktop application to draw and display the target application's icon.

[0185] S714: The first application displays installation completion information.

[0186] The processing procedures for S711 to S714 can be referenced from the relevant content of S507 to S510, and will not be elaborated here.

[0187] S715: The real-time service module obtains load information when the target compilation mode is the first compilation mode.

[0188] After executing S707, if the target compilation mode is the first compilation mode, the electronic device continues to acquire load information (and if load parameters are needed, it can continue to acquire load parameters). The process of acquiring load information can be found in the relevant sections of S703 and S803, and will not be repeated here. If the target compilation mode is not the first compilation mode, the processing steps of S715 to S721 can be skipped, meaning the compilation and optimization are already complete.

[0189] It should be noted that in S715, when the target compilation mode is the first compilation mode, the electronic device will not delete the compilation optimization-related files in the target application's installation package. These files will only be deleted after S720 is executed. Conversely, when the target compilation mode is the second compilation mode, the electronic device can directly delete the compilation optimization-related files in the target application's installation package.

[0190] S716: The real-time service module determines whether the load status is high. If the load status is high, S715 can be executed, i.e., continue to obtain load information; if the load status is low, S717 can be executed.

[0191] The processing procedure of S716 can be referred to the relevant content of S804, and will not be repeated here.

[0192] S717: The real-time service module sends the second compilation mode information to the PMS.

[0193] When the load is low, the real-time service module sends a second compilation mode information to the PMS. Correspondingly, the PMS receives the second compilation mode information from the real-time service module. This second compilation mode information may include a second compilation mode, used to request that the first file of the installation package be compiled according to the second compilation mode, i.e., the process of converting the bytecode of the target application's installation package into machine code.

[0194] S718: PMS compiles the target application according to the second compilation mode.

[0195] After receiving the second compilation mode information from the real-time service module, the PMS can compile the target application according to the second compilation mode.

[0196] In S715-S718 above, the electronic device can continue to monitor the load state (by repeatedly executing S715 and S716) even if the bytecode of the installation package is not converted into machine code during installation. Under low load, the compilation process of the second compilation mode is executed, converting the bytecode of the installation package into machine code. This ensures higher running efficiency of the target application after installation while avoiding the large data processing volume required during installation under high load, thus ensuring system smoothness and stability and improving the user installation experience.

[0197] S719: PMS sends compilation request information to the bytecode optimization module through the ART service.

[0198] The compilation request information may include a second compilation mode, which is used to request that the installation package of the target file be compiled and optimized according to the second compilation mode.

[0199] S720: The bytecode optimization module compiles the first file based on the compilation request information to obtain the second file.

[0200] After the bytecode optimization module receives the compilation request information, it can compile the first file based on the installation request information to obtain the second file. That is, it can compile and optimize the DEX file (first file) in the target application installation package according to the second compilation mode, that is, interpret and execute it to obtain the OAT file (second file), and the OAT file is stored. The OAT file is used for subsequent execution.

[0201] S721: The bytecode optimization module sends a second compilation completion notification to the ART service.

[0202] The second compilation completion notification indicates that the installation package of the target application has been compiled and processed according to the second compilation mode.

[0203] Optionally, after S721 is executed, if the user clicks the target application's icon, in response to the user's action of launching the target application, the Activity Manager (AMS) begins the process of creating the target application. If the target application is recreated during its lifecycle, the target application can be run according to the generated second file.

[0204] After S713 is executed, the electronic device can run the target application. If it is only compiled according to the first compilation mode and has not yet been compiled according to the second compilation mode, the electronic device needs to interpret and execute the bytecode during operation. If it has been compiled according to the second compilation mode, the electronic device does not need to interpret and execute the bytecode during operation, but can directly execute the machine code.

[0205] Figure 7 In this approach, electronic devices can determine whether to use the faster first compilation mode during installation or the more efficient second compilation mode based on the application's long-term keep-alive status and system load. Long-term keep-alive applications, because they are rarely recreated after their lifecycle is active, directly choosing the second compilation mode avoids the situation where, after installation using the first compilation mode, the application cannot run as it was compiled in the second mode, leading to long-term low performance. Furthermore, for long-term keep-alive applications, the electronic device needs to monitor system load during installation. If the load is high, it installs using the first compilation mode; after installation, it waits for the load to decrease before switching to the second compilation mode. This reduces the pressure on memory under high load, improving the smoothness and stability of device operation.

[0206] Combination Figure 7 Implementation method, Figure 9 illustrate Figure 7 The process involves compiling and running the application according to the target application's timeline. Figure 9 This is a schematic diagram illustrating the process of compiling and running an application, as exemplarily provided in an embodiment of this application.

[0207] like Figure 9As shown, this describes the installation process when the target application is not a long-running application and the electronic device is under high load during installation. After receiving the target application installation request, the electronic device determines that the target application is not a long-running application and is under high load, and installs it using the verify build mode (first build mode), while continuing to monitor the load status. Optionally, after the target application is installed, if a target application run request 1 is received, the target application runs according to the first mode, which is inefficient. After a period of time, if a target application termination request is received, the target application's lifecycle is terminated, and the target application's running thread is closed. When the monitored load status changes from high load to low load, the electronic device can compile and optimize according to the speed-profile build mode (second build mode). After the compilation optimization is completed, if a target application run start request is detected, the target application runs according to the second mode, which is more efficient.

[0208] It should be noted that if the target application is a long-term keep-alive application; or, if the target application is not a long-term keep-alive application and is under low load, the installation process for the electronic device can refer to... Figure 4B The processing steps are not detailed here. Under high load, the second compilation mode is used for installation, completing the process in one step and reducing multiple compilation steps, thus improving installation and post-installation execution efficiency. In the above process, the long-term keep-alive application screening eliminates situations where the second compilation result is unusable for an extended period after two separate compilations, ensuring timely execution and effectiveness after subsequent two compilations.

[0209] As used in the above embodiments, depending on the context, the term "when..." can be interpreted as meaning "if...", "after...", "in response to determining...", or "in response to detecting...". Similarly, depending on the context, the phrase "when determining..." or "if (the stated condition or event) is interpreted as meaning "if determining...", "in response to determining...", "when (the stated condition or event) is detected", or "in response to detecting (the stated condition or event)".

[0210] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The 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 processes or functions described in the embodiments of this application are 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, the 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) 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., solid-state drive), etc.

[0211] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This program can be stored in a computer-readable storage medium, and when executed, it can include the processes described in the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.

Claims

1. An application program compiling method characterized by comprising: The method is applied to an electronic device, and the method comprises: In response to a first installation operation on a first target application, the electronic device installs the first target application by a first compilation mode when the first target application is not a long keep-alive application and a load state is high load; the first compilation mode does not perform compilation optimization; after the first target application is installed, the electronic device performs compilation optimization on the first target application by a second compilation mode when the load state is low load; After the first target application is installed by the first compilation mode and before the first target application is compiled by the second compilation mode, the electronic device runs the first target application according to the installation result of the first compilation mode in response to a first operation of starting the first target application by a user; after the first target application is compiled by the second compilation mode, the electronic device runs the first target application according to the compilation optimization result of the second compilation mode in response to a second operation of starting the first target application by a user when a life cycle of the first target application is in an end state; When the first target application is the long keep-alive application, the electronic device installs the first target application by the second compilation mode.

2. The method of claim 1, wherein, After the first target application is installed by the first compilation mode and before the first target application is compiled by the second compilation mode, the electronic device converts bytecode of the first target application into machine code during running of the first target application; After the first target application is compiled by the second compilation mode, the electronic device directly executes machine code of the first target application during running of the first target application.

3. The method according to claim 1 or 2, characterized in that, The method further comprises: When the first target application is not the long keep-alive application and the load state is low load, the electronic device installs the first target application by the second compilation mode.

4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises: In response to a first installation operation on the first target application, the electronic device determines whether the first target application is the long keep-alive application; When the first target application is not the long keep-alive application, the electronic device determines whether the load state is high load.

5. The method of claim 4, wherein, The electronic device determines whether the load state is high load, comprising: The electronic device determines whether a first condition is met; the first condition comprises at least one of a kernel state condition, a memory usage condition and a temperature condition; The kernel state condition is a condition that a first kernel busy state rate is less than or equal to a threshold kernel busy state rate, the first kernel busy state rate being a probability that a kernel state of the electronic device is in a busy state in a first time period; the memory usage condition is a condition that a first memory usage is less than or equal to a threshold memory usage; and the temperature condition is a condition that a processor temperature is less than or equal to a threshold temperature. The electronic device determines the load state as high load when the first condition is not met, and determines the load state as low load when the first condition is met.

6. The method of claim 5, wherein, In response to a first installation operation of the first target application, the method further includes that the electronic device starts to acquire a load parameter, the load parameter including one or more of a kernel state, the first memory usage, and the processor temperature of the electronic device; After the electronic device installs the first target application through the first compilation mode, the method further includes: The electronic device acquires load information based on the load parameter; the load information including a first kernel busy state rate, the first memory usage, and the processor temperature.

7. The method of claim 4, wherein, The electronic device determines whether the first target application is a long-keep-alive application, including: The electronic device determines whether a long-keep-alive application list includes an application package name of the first target application, and the first target application is a long-keep-alive application when the long-keep-alive application list includes the application package name of the first target application; and the first target application is not a long-keep-alive application when the long-keep-alive application list does not include the application package name of the first target application.

8. The method of claim 1 or 2, wherein, After the first target application is installed, the method further includes: The electronic device determines whether the load state is low load; the load information being used to represent a load degree of an electronic device memory; When the load state is not low load, the electronic device continues to perform the process of determining whether the load state is low load.

9. The method according to any one of claims 1 to 3, characterized in that, The electronic device includes a first target application, a package management service (PMS), a real-time service module, and a bytecode optimization module; In response to a first installation operation of the first target application, when the first target application is not a long-keep-alive application and the load state is high load, the electronic device installs the first target application through a first compilation mode, including: The first target application sends a target application installation request to the PMS in response to the first installation operation of the first target application, the target application installation request including an application package name of the first target application; The PMS sends installation request information to the real-time service module, the installation request information being used to request to install the first target application; The real-time service module determines whether the first target application belongs to a long-keep-alive application based on the installation request information; when the first target application does not belong to the long-keep-alive application, the real-time service module acquires load information and determines whether the load state is high load based on the load information; When the load state is high load, the real-time service module sends target compilation mode information to the PMS; the target compilation mode information being used to request to install the first target application according to the first compilation mode. The PMS installs the first target application according to the first compiling mode based on the target compiling mode information; the PMS sends installation request information to the bytecode optimization module; the bytecode optimization module checks the first file based on the installation request information, and the bytecode optimization module sends installation completion notification to the PMS; After the first target application is installed, the electronic device determines whether the load state is low load, including: After the first target application is installed, the real-time service module determines whether the load state is low load; If the load state changes from high load to low load, the electronic device compiles and optimizes the first target application through a second compiling mode, including: When the load state is low load, the real-time service module sends second compiling mode information to the PMS; the second compiling mode information is used to request to compile and optimize the first target information according to the second compiling mode; The PMS compiles the first target application according to the second compiling mode; the PMS sends compiling request information to the bytecode optimization module; the bytecode optimization module compiles the first file based on the compiling request information to obtain a second file, and the bytecode optimization module sends compiling completion notification to the PMS.

10. An electronic device, comprising: including: One or more processors and one or more memories; the one or more processors are coupled with the one or more memories, the one or more memories are used to store computer program codes, the computer program codes include computer instructions, when the one or more processors execute the computer instructions, the electronic device executes the method as claimed in any one of claims 1-9.

11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, when the computer program is executed by a processor, the method as claimed in any one of claims 1-9 is realized.