A method and apparatus for compiling an application

By processing benchmark configuration files on the electronic device side, the problem of low application performance caused by the lack of profile files when the electronic device is idle is solved, and the application performance improvement and user experience improvement in the target compilation scenario are achieved.

CN117130617BActive Publication Date: 2025-04-01HONOR DEVICE CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310141098.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-19
Publication Date
2025-04-01
Estimated Expiration
2043-01-19

AI Technical Summary

Technical Problem

When the prior art triggers compilation optimization when the electronic device is idle, the lack of profile files makes it impossible to trigger the speed-profile compilation mode, resulting in low application performance.

Method used

Provides an application compilation method, which compiles and optimizes the application's dex file in the speed-profile compilation mode by processing the baseline profile file embedded in the APK on the electronic device side.

Benefits of technology

In the target compilation scenario, it can improve the performance of the application, save compilation time, improve user experience, and eliminate the need to rely on profile files provided by the application market.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117130617B_ABST
    Figure CN117130617B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a method and device for compiling an application, which relates to the field of terminals, and can ensure that the application obtains a benchmark configuration file in scenarios such as idle trigger compilation of an electronic device, and can perform compilation optimization based on the benchmark configuration file, which can improve the performance of the application, thereby improving the user experience when the user uses the application. The method is as follows: the electronic device determines whether the installation package of the target application includes a benchmark configuration file in a target compilation scenario, and the benchmark configuration file is used to indicate the hotspot functions in the installation package of the target application; wherein the target compilation scenario includes a scenario in which the electronic device triggers compilation in an idle state; if it is determined that the installation package of the target application includes a benchmark configuration file, the electronic device verifies the dex file in the installation package of the target application based on the first compilation mode, and compiles the hotspot functions indicated by the benchmark configuration file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminals, and in particular to a method and device for compiling an application. Background Art

[0002] The application (APP) runs in a virtual machine. The execution of the application code by the virtual machine includes two parts. The first part is to compile the source code into bytecode, also known as front-end compilation. The work performed at this time is mainly to analyze the lexical, grammatical and semantic aspects. The second part is to compile the bytecode into machine code for interpretation and execution. However, due to the low efficiency of interpretation and execution, it has a serious impact on the user experience. In order to solve this problem, dex2oat (dalvik excutable file to optimized art file) came into being. dex2oat can compile the bytecode of the application into machine code in advance, so the machine code can be directly executed during actual operation, thereby greatly improving the operating efficiency of the application.

[0003] dex2oat includes multiple different compilation modes, which are sorted according to the performance of the application after execution. The common compilation modes include: speed compilation mode, speed-profile compilation mode, verify compilation mode, etc. Among them, the speed compilation mode compiles and optimizes all application codes, and the resulting product has good performance, but the generated file is large, time-consuming, and consumes a lot of mobile phone storage space. The speed-profile compilation mode depends on the profile file and can compile and optimize the hot functions of the application. The verify compilation mode only verifies the dex file of the application. The verify compilation mode is inferior to the speed-profile compilation mode in terms of compilation performance.

[0004] In some cases, electronic devices (e.g., Android phones) can adopt a background idle compilation optimization strategy, that is, trigger the speed-profile compilation mode to compile and optimize the application when the electronic device is idle. The speed-profile compilation mode must rely on the profile file. When there is no profile file, the speed-profile compilation mode will be downgraded to the verify compilation mode. Currently, the sources of profile files can include the following two: 1) When a user installs an application in an application market (e.g., Huawei App Market or Google App Market), the application market provides a data meta (DM, Data meta) file, which contains profile information; 2) After the electronic device is turned on for the first time / factory settings are restored, or after the electronic device is OTA upgraded, or after the application is installed, the hotspot functions of the application can be recorded during the user's use of the application to generate a profile file.

[0005] However, the above profile file sources have corresponding shortcomings: 1) The generation of DM files often lags behind, and the application market will only provide them to users after the application has actually run for a period of time. For applications that have just been launched or frequently updated, the application market cannot provide DM files in a timely manner, or the DM files are invalid or not configured due to some reasons, so the speed-profile compilation mode cannot be triggered for compilation optimization, and the application performance is low; 2) Although the application market has configured the DM file, the DM file may have incomplete or inaccurate configuration of hot functions. Even if the speed-profile compilation mode is triggered for compilation optimization, the application performance is still low; 3) After the user starts the computer for the first time / after the system is upgraded, only the verify compilation mode can be triggered to compile and optimize the application. If the user has not used the corresponding application (system application and / or third-party application), the profile file cannot be generated, and the speed-profile compilation mode cannot be triggered for compilation optimization during background idle compilation optimization, and the application performance is low. 4) After the application is installed from the application market, if the user has not used the application, the profile file cannot be generated, and the speed-profile compilation mode cannot be triggered for compilation optimization during background idle compilation optimization, and the application performance is low. Summary of the invention

[0006] The embodiments of the present application provide a method and device for compiling an application, which can ensure that the application obtains a baseline configuration file in a scenario where the compilation is triggered when the electronic device is idle, and can perform compilation optimization based on the baseline configuration file, thereby improving the performance of the application and thus improving the user experience when the user uses the application.

[0007] In a first aspect, an embodiment of the present application provides a method for compiling an application, comprising: an electronic device, in a target compilation scenario, determines whether an installation package of a target application includes a baseline configuration file, the baseline configuration file being used to indicate hotspot functions in the installation package of the target application; wherein the target compilation scenario includes a scenario in which the electronic device triggers compilation in an idle state; if it is determined that the installation package of the target application includes a baseline configuration file, the electronic device verifies the dex file in the installation package of the target application based on a first compilation mode, and compiles the hotspot functions indicated by the baseline configuration file.

[0008] Based on the method provided by the embodiment of the present application, in the target compilation scenario (the scenario where the electronic device triggers compilation when idle), the electronic device can obtain the baseline profile file (benchmark configuration file) of the target application, and verify the dex file in the installation package of the target application based on the first compilation mode (speed-profile (have profile) compilation mode), and compile the hotspot function indicated by the benchmark configuration file. After the compilation is completed, when the electronic device runs the target application, the compilation optimization file can be directly called, and there is no need to compile the dex file of the target application in real time, which saves the compilation time, improves the execution efficiency of the electronic device for the application, makes the application run more smoothly, and can improve the user experience. The compilation method of the application provided by the present application does not need to rely on the application market to provide the DM file (the DM file includes the profile file) for the application, nor does it need to wait for the application to run to record the hotspot function of the application to generate a profile file. Even if the user has not used the target application and cannot record the hotspot function of the application to generate a profile file when the application is running, the speed-profile (have profile) compilation mode can be triggered to compile and optimize the application, which can improve the performance of the application (the startup, sliding and other performance of the application), thereby bringing a better experience to the user.

[0009] In a possible implementation, the target compilation scenario also includes a scenario where the electronic device is turned on for the first time to trigger compilation, and a scenario where the electronic device performs an over-the-air OTA upgrade to trigger compilation. It should be noted that in the scenario where the electronic device is turned on for the first time / after restoring the factory settings or the electronic device is upgraded to OTA (in the OTA upgrade startup process or after the OTA upgrade enters the desktop), the target application is compiled and optimized in the speed-profile (have profile) compilation mode on the electronic device side according to the baseline profile file, which saves more storage space than compiling and optimizing the target application in the speed-profile (have profile) compilation mode in the preset stage (the stage where the electronic device burns the operating system, system applications, and some third-party applications). This is because the volume of the baseline profile file is smaller than the compilation optimization file (the compilation optimization file obtained by compiling and optimizing the target application in the speed-profile (have profile) compilation mode in the preset stage), which can reduce the number of files preset by the electronic device and save the storage space of the electronic device.

[0010] In a possible implementation, the method further includes: the electronic device records the hotspot functions of the target application when the target application is running, and generates a first configuration file based on the recorded hotspot functions; the electronic device verifies the dex file in the installation package of the target application based on the first compilation mode, and compiles the hotspot functions indicated by the benchmark configuration file, including: the electronic device verifies the dex file in the installation package of the target application based on the first compilation mode, and compiles the hotspot functions indicated by the benchmark configuration file and the hotspot functions indicated by the first configuration file. That is, in the target compilation scenario, a more accurate and comprehensive hotspot function can be obtained by combining the baseline profile file and the profile file generated by the electronic device, and the application is compiled and optimized in the speed-profile (have profile) compilation mode. Compared with compiling and optimizing the speed-profile compilation mode only according to the profile file generated by the electronic device, compiling and optimizing the speed-profile compilation mode according to the baseline profile file and the profile file generated by the electronic device can better improve the performance of the application, thereby bringing a better experience to the user.

[0011] In a possible implementation, the electronic device determines whether the installation package of the target application includes a benchmark configuration file, including: the electronic device parses the manifest file in the installation package of the target application, sets a first flag in the manifest file, and the first flag is used to indicate whether the installation package of the target application includes the benchmark configuration file; reads the first flag, if the first flag is true, it means that the installation package of the target application includes the benchmark configuration file, if the first flag is false, it means that the installation package of the target application does not include the benchmark configuration file. That is, the electronic device can determine whether the installation package of the target application includes the benchmark configuration file based on the first flag in the manifest file. If the installation package of the target application includes the benchmark configuration file, the electronic device can verify the dex file in the installation package of the target application based on the first compilation mode (speed-profile (haveprofile) compilation mode), and compile the hotspot function indicated by the benchmark configuration file. In this way, the startup, sliding and other performances of the target application when it is first started can be improved, which can bring a better experience to the user.

[0012] In one possible implementation, the electronic device determines whether the installation package of the target application includes a benchmark configuration file, including: the electronic device detects whether the benchmark configuration file exists in the installation directory of the target application. That is, the electronic device can actively check whether the installation package of the target application contains the benchmark configuration file. If the installation package of the target application contains the benchmark configuration file, the electronic device can verify the dex file in the installation package of the target application based on the first compilation mode (speed-profile (haveprofile) compilation mode), and compile the hotspot functions indicated by the benchmark configuration file. In this way, the startup, sliding and other performance of the target application when it is first started can be improved, which can bring a better experience to the user.

[0013] In one possible implementation, the electronic device verifies the dex file in the installation package of the target application based on the first compilation mode, and before compiling the hot spot functions in the installation package of the target application, the method also includes: the electronic device checks whether the first configuration directory exists, and creates the first configuration directory if the first configuration directory does not exist; the electronic device moves the baseline configuration file from the installation directory to the first configuration directory; the electronic device sets and updates the second flag, and the second flag is used to trigger the merging of the baseline configuration file, and the electronic device moves the baseline configuration file under the first configuration directory to the second configuration directory.

[0014] In a second aspect, the present application provides a chip system, which includes one or more interface circuits and one or more processors. The interface circuits and processors are interconnected via lines.

[0015] The chip system can be applied to an electronic device including a communication module and a memory. The interface circuit is used to receive a signal from the memory of the electronic device and send the received signal to the processor, where the signal includes a computer instruction stored in the memory. When the processor executes the computer instruction, the electronic device can execute the method described in the first aspect and any possible design thereof.

[0016] In a third aspect, the present application provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on an electronic device (such as a mobile phone), the electronic device executes the method described in the first aspect and any possible design thereof.

[0017] In a fourth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method described in the first aspect and any possible design thereof.

[0018] In a fifth aspect, an embodiment of the present application provides a compiling device for an application, including a processor, the processor and a memory are coupled, the memory stores program instructions, and when the program instructions stored in the memory are executed by the processor, the device implements the method described in the first aspect and any possible design thereof. The device may be an electronic device; or may be a component of an electronic device, such as a chip.

[0019] In a sixth aspect, an embodiment of the present application provides a compiling device for an application program, wherein the device may be divided into different logical units or modules according to functions, and each unit or module performs a different function, so that the device executes the method described in the first aspect and any possible design method thereof.

[0020] In the seventh aspect, an embodiment of the present application provides a compilation system for an application, including an electronic device and an application server, wherein the electronic device and the application server respectively execute part of the steps and cooperate with each other to implement the method described in the first aspect and any possible design method thereof.

[0021] It can be understood that the beneficial effects that can be achieved by the chip system described in the second aspect, the computer-readable storage medium described in the third aspect, the computer program product described in the fourth aspect, the devices described in the fifth aspect and the sixth aspect, and the system described in the seventh aspect provided above can refer to the beneficial effects in the first aspect and any possible design method thereof, and will not be repeated here.

[0022] Based on the method provided by the embodiment of the present application, in the target compilation scenario (for example, the scenario where the electronic device triggers compilation when idle), the electronic device can obtain the baseline profile file (benchmark configuration file) of the target application, and verify the dex file in the installation package of the target application based on the first compilation mode (speed-profile (have profile) compilation mode), and compile the hotspot function indicated by the benchmark configuration file. After the compilation is completed, when the electronic device runs the target application, the compilation optimization file can be directly called, and there is no need to compile the dex file of the target application in real time, which saves the compilation time, improves the execution efficiency of the electronic device for the application, makes the application run more smoothly, and can improve the user experience. The compilation method of the application provided by the present application does not need to rely on the application market to provide a DM file for the application (the DM file includes a profile file), nor does it need to wait for the application to run to record the hotspot function of the application to generate a profile file. Even if the user has not used the target application and cannot record the hotspot function of the application to generate a profile file when the application is running, the speed-profile (have profile) compilation mode can be triggered to compile and optimize the application, which can improve the performance of the application (the startup, sliding and other performance of the application), thereby bringing a better experience to the user. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Figure 1 A schematic diagram of a dex2oat triggering scenario provided in an embodiment of the present application;

[0024] Figure 2 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;

[0025] Figure 3 A schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;

[0026] Figure 4 A schematic diagram of a compilation process of an electronic device provided in an embodiment of the present application;

[0027] Figure 5 A schematic diagram of interaction between modules of an electronic device provided in an embodiment of the present application;

[0028] Figure 6 A schematic diagram of module interaction of a method for compiling an application program provided in an embodiment of the present application;

[0029] Figure 7A schematic diagram of a process for processing a baseline profile file provided in an embodiment of the present application;

[0030] Figure 8 A schematic diagram of a process for processing a baseline profile file and a generated profile file provided in an embodiment of the present application;

[0031] Fig. 9 A schematic diagram of a process of calling dex2oat by a compilation optimization module provided in an embodiment of the present application;

[0032] Fig.10 A schematic diagram of the structure of the chip system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] In order to make the description of the following embodiments clear and concise, a brief introduction to the related technology is first given:

[0034] In order to make the application installed in the electronic device run more smoothly, dex2oat can be used to compile the application's dex file during the application installation process or before the application is started, and compile it into machine code that the electronic device can directly run, so that the electronic device can directly load these machine codes during the application running process, making the application run more smoothly. Among them, the application's dex file exists in the application's Android installation package (Android package, APK), which contains all the application's operating instructions and runtime data, that is, the dex file contains all the application's code.

[0035] like Figure 1 As shown in , dex2oat compiles dex files in several scenarios, including the first time the electronic device is turned on, the electronic device is restored to factory settings, the electronic device is upgraded using over-the-air technology (OTA), the electronic device installs an application, the electronic device clones applications in other devices, the electronic device triggers compilation when idle, the application itself triggers compilation, and other scenarios that trigger dex2oat to compile the application's dex file.

[0036] The following describes several scenarios in which dex2oat compiles dex files.

[0037] When an electronic device is turned on for the first time, multiple applications need to be installed in the electronic device. At this time, dex2oat can be triggered to compile the dex files extracted from the installation package during the installation of these applications to obtain odex files. Based on this, during the operation of the installed application, the electronic device can directly load and execute the odex file, making the application run more smoothly.

[0038] In the scenario where the electronic device is restored to factory settings, multiple applications need to be reinstalled in the electronic device. At this time, dex2oat can be triggered to compile the dex files extracted from the installation package during the installation of these applications to obtain odex files. Based on this, during the operation of the installed application, the electronic device can directly load and execute the odex file, making the application run more smoothly.

[0039] In the scenario of OTA upgrade of electronic devices, when the electronic device is turned on after OTA is completed, or after the electronic device is turned on and enters the desktop after OTA is completed, the dex files of various applications in the electronic device are recompiled to obtain odex files. Based on this, during the operation of the recompiled application, the electronic device can directly load and execute the recompiled odex file, so that the application runs more smoothly.

[0040] In the scenario where an electronic device installs an application, the electronic device can download the installation package of the application to be installed from the application market. In the process of executing the installation package and then installing the application, dex2oat can be triggered to compile the dex file extracted from the installation package of the application to obtain an odex file. Based on this, during the operation of the installed application, the electronic device can directly load and execute the odex file, making the application run more smoothly.

[0041] In the scenario where an electronic device clones an application in another device, the electronic device installs the corresponding application locally according to the application installed on the other device. During the process of installing these applications on the electronic device, the electronic device can trigger dex2oat to compile the dex file of the application cloned to the local electronic device to obtain an odex file. Based on this, during the operation of the cloned application, the electronic device can directly load and execute the odex file, making the application run more smoothly.

[0042] In the scenario where the idle compilation of the electronic device is triggered, if the electronic device is in an idle state for a time greater than or equal to a preset time (for example, 31 minutes), and / or the electronic device is charging. For example, when the charging power of the electronic device reaches 90% of the idle state, dex2oat can be triggered in the electronic device to compile the dex file of the installed but non-running application to obtain the odex file. At this time, the application is not started. Based on this, when the application is run again, such as when the application is cold-started, the electronic device can directly load and execute the odex file during the cold-start process of the application, so that the startup process of the application and the running process after startup are smoother.

[0043] In the scenario where the application itself triggers compilation, when the application's own triggering conditions are met, the application triggers dex2oat through instructions to compile the application's dex file to obtain an odex file. Based on this, during the application's running process, the electronic device can directly load and execute the odex file, making the application run more smoothly.

[0044] Of course, there are other scenarios where dex2oat is triggered to compile the application's dex files, such as some applications are set by the application provider to trigger dex2oat to compile the application's dex files when the application is first started, etc. This application does not limit this.

[0045] It should be noted that scenarios where electronic devices are idle and trigger compilation, scenarios where electronic devices are turned on for the first time / factory settings are restored, and scenarios where electronic devices are upgraded via OTA are all important scenarios for using compilation optimization to improve user experience. In these scenarios, large quantities of applications in electronic devices can be compiled and optimized to improve application performance, thereby improving user experience.

[0046] Since the electronic device is in idle state and has sufficient power, it can avoid problems such as foreground application freezing when in use due to dex2oat compilation occupying more CPU resources, IO resources and memory resources of the terminal device. It can also avoid users wasting time waiting for compilation optimization, and avoid the problem of insufficient power caused by excessive power consumption of electronic devices.

[0047] dex2oat includes multiple different compilation optimization modes, which are sorted according to the performance of the application after execution. Currently, common compilation optimization modes include: speed compilation mode, speed-profile compilation mode, verify compilation mode, etc. The comparison of these typical compilation optimization modes is shown in Table 1.

[0048] Table 1

[0049]

[0050] In the above scenarios, when dex2oat compiles the dex file, it can use one of the multiple compilation modes shown in Table 1.

[0051] Speed ​​compilation mode: In this compilation mode, dex2oat can perform AOT compilation on all function codes in the dex file to obtain the corresponding compilation products: odex, vdex. Speed ​​compilation mode compiles and optimizes all program codes, and the obtained products have good performance, but the generated files are large, time-consuming, and consume more mobile phone storage space.

[0052] Speed-profile (have profile) compilation mode: In this compilation mode, in addition to verifying the dex file to obtain the corresponding odex file, dex2oat will also perform AOT compilation on the function code specified in the profile file in the application's dex file according to the information of the specified function in the profile file, and obtain the corresponding compilation product: art file. Among them, the profile file refers to a file containing information about hot functions (also called hot codes). The art file contains the addresses of these specified function codes, which is convenient for addressing these specified functions. These specified function codes are the codes of functions that are commonly used in the application. Therefore, during the operation of the application, after loading the art file into the memory, the electronic device can quickly address and run the found code, so that the application runs more smoothly.

[0053] Speed-profile (no profile) compilation mode: In this compilation mode, dex2oat verifies the dex file and optimizes the dex instructions in the dex file to obtain the corresponding odex file. The optimized dex instructions have higher interpretation performance and can be efficiently recognized by electronic devices.

[0054] Among them, since the speed-profile (no profile) compilation mode only verifies the dex file and optimizes the dex instructions without involving AOT compilation, the speed-profile (no profile) compilation mode has a shorter compilation time than the speed-profile (have profile) compilation mode. However, the speed-profile (no profile) compilation mode has poorer compilation performance than the speed-profile (have profile) compilation mode.

[0055] Verify compilation mode: In this compilation mode, dex2oat verifies the dex file to obtain the corresponding odex file. Since the verify compilation mode only verifies the dex file but does not involve AOT compilation and dex instruction optimization, the verify compilation mode has a shorter compilation time than the speed-profile (have profile) compilation mode and the speed-profile (no profile) compilation mode. However, the compilation performance of the verify compilation mode is worse than that of the speed-profile (have profile) compilation mode and the speed-profile (no profile) compilation mode.

[0056] Of course, if dex2oat is not triggered or dex2oat is triggered but the dex file is not compiled, the dex file will not be processed. After the application is started, the dex file of the application is loaded and interpreted. When running the code in the dex file, the application will verify the dex file. Therefore, if the compilation optimization of any of the above compilation modes is not performed on the dex file, then compared with the running process of directly loading the odex file after the application is started without verifying the dex file, the application will run slower because the dex file is loaded and verified after startup.

[0057] It should be noted that after the electronic device is turned on for the first time / factory settings are restored, or after the electronic device is OTA upgraded, or after the application is installed, the user may not run the application immediately, so the electronic device cannot record the hot functions according to the running status of the application and then generate a profile file. If the electronic device reaches the idle trigger compilation scenario before the user uses the application, due to the lack of a profile file generated by the hot functions recorded according to the running status of the application, the electronic device can only trigger dex2oat to use the speed-profile (no profile) compilation mode to compile the dex file unzipped from the installation package. Although the compilation mode uses speed-profile, no profile file is provided, and the actual effect is verify-level compilation optimization. As a result, the performance at application startup is low and the user experience is poor.

[0058] In response to the above problem of not being able to provide profile files in a timely manner, the industry has proposed baseline profile technology (baseline profile mechanism), which is a new mechanism for providing profile files. Application developers can count the hot functions of the application in advance to obtain the profile file, and then send the profile file to the application market as part of the application's APK. When a user downloads an application from the application market, the profile file is sent from the application market to the user's electronic device along with the APK. The profile file provided by the baseline profile technology can be automatically generated using the Android Gradle plug-in (Google's native tool). Alternatively, developers can manually define the hot functions that the developer believes need to be compiled and optimized and add them to the profile file.

[0059] In the baseline profile technology, the profile file carried in the APK of the application can be processed in the cloud of the Google Play Market and sent to the user's electronic device in the form of a DM file. When the ART cloud configuration file (for example, the DM file) is not yet available, the baseline profile file fills the gap in the ART cloud configuration file pipeline (that is, the baseline profile file can replace the DM file). When the cloud configuration file is available, it can be automatically merged with it (that is, the baseline profile file can be merged with the DM file) to obtain a more accurate and comprehensive profile file, so that speed-profile compilation optimization can be performed when the application is installed. However, the current baseline profile technology relies on the cloud capabilities of the application market. For some third-party application markets (such as third-party application markets such as App Store and Wandoujia), even if the APK of the application contains a baseline profile file, the third-party application market cannot perform cloud processing on the baseline profile file carried in the APK, that is, it cannot provide a DM file. Therefore, in the scenario of the electronic device being turned on for the first time / restoring factory settings, and the scenario of the electronic device being upgraded OTA, the electronic device cannot use the speed-profile (have profile) compilation mode to compile the dex file of the application, resulting in low performance of startup and sliding when the application is started, and poor user experience. In addition, if the user reaches the scenario where the electronic device idle triggers compilation before using the application, due to the lack of a profile file generated by hot functions recorded based on the running status of the application, the electronic device cannot use the speed-profile (have profile) compilation mode to compile the application's dex file, resulting in low startup, sliding and other performance when the application is started, and a poor user experience.

[0060] The present application provides a method and device for compiling an application, which can combine the baseline profile technology with the application installation scenario, without relying on the application market to process the baseline profile file (benchmark configuration file) in the APK in the cloud, but instead processes the baseline profile file embedded in the APK on the electronic device side (for example, the mobile phone side), so that the application downloaded by the electronic device from the third-party application market can also compile the application's dex file in the speed-profile (have profile) compilation mode when it is installed. In this way, the startup, sliding and other performance of the application when it is first started will be improved, which can bring a better experience to users.

[0061] Based on the method provided in the embodiment of the present application, in the scenario where the electronic device triggers idle compilation, the electronic device is powered on for the first time / factory settings are restored, and the electronic device is upgraded OTA, the baseline profile file (benchmark configuration file) of the target application can be obtained, and the dex file of the target application is compiled in the speed-profile (have profile) compilation mode according to the baseline profile file to obtain a compilation optimization file. After the compilation is completed, when the electronic device runs the target application, the compilation optimization file can be directly called, and there is no need to compile the dex file of the target application in real time, which saves compilation time, improves the execution efficiency of the electronic device on the application, makes the application run more smoothly, and can improve the user experience.

[0062] Figure 2 A schematic diagram of the structure of an electronic device 100 provided in an embodiment of the present application.

[0063] like Figure 2 As shown, the 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, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0064] Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light 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.

[0065] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0066] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0067] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0068] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0069] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0070] It is understandable that the interface connection relationship between the modules shown in this embodiment is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0071] The charging management module 140 is used to receive charging input from a charger. While the charging management module 140 is charging the battery 142 , it can also power the electronic device through the power management module 141 .

[0072] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, and the wireless communication module 160. In some other embodiments, the power management module 141 may also be provided in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may also be provided in the same device.

[0073] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0074] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network.

[0075] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1.

[0076] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194.

[0077] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0078] In some embodiments, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).

[0079] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0080] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), a light-emitting diode (LED), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light emitting diode (QLED), etc.

[0081] The electronic device 100 can realize the shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor. The ISP is used to process the data fed back by the camera 193. The camera 193 is used to capture static images or videos. The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. The video codec is used to compress or decompress digital videos. The electronic device 100 can support one or more video codecs. In this way, the electronic device 100 can play or record videos in multiple encoding formats, such as: moving picture experts group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0082] The number of cameras 193 may be 1 to N. For example, the electronic device may include 2 front cameras and 4 rear cameras.

[0083] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0084] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos are stored in an external memory card. The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 can execute various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0085] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0086] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. The speaker 170A, also known as the "speaker", is used to convert audio electrical signals into sound signals. The receiver 170B, also known as the "earpiece", is used to convert audio electrical signals into sound signals. The microphone 170C, also known as the "microphone" or "microphone", is used to convert sound signals into electrical signals. The headphone jack 170D is used to connect wired headphones.

[0087] The button 190 includes a power button, a volume button, etc. The button 190 can be a mechanical button. It can also be a touch button. The electronic device 100 can receive the button input and generate a key signal input related to the user settings and function control of the electronic device 100. The motor 191 can generate a vibration prompt. The motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. The indicator 192 can be an indicator light, which can be used to indicate the charging status, power changes, messages, missed calls, notifications, etc. The SIM card interface 195 is used to connect the SIM card. The SIM card can be inserted into the SIM card interface 195, or pulled out from the SIM card interface 195 to achieve contact and separation with the electronic device 100. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc.

[0088] The methods in the following embodiments can all be implemented in the electronic device 100 having the above hardware structure.

[0089] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.

[0090] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through interfaces. In some embodiments, the Android system may include an application layer, an application framework layer, an Android runtime (Android runtime) and a system library, a hardware abstraction layer (HAL) and a kernel layer. It should be noted that the embodiments of the present application are illustrated by taking the Android system as an example. In other operating systems (such as Hongmeng system, IOS system, etc.), as long as the functions implemented by each functional module are similar to those of the embodiments of the present application, the solutions of the present application can also be implemented.

[0091] Among them, the application layer can include a series of application packages.

[0092] like Figure 3 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, lock screen application, setting application, etc. Of course, the application layer may also include other application packages, such as application market (such as ), etc., and this application does not limit this.

[0093] The application framework layer provides an application programming interface (API) and a programming framework for the application programs in the application layer. The application framework layer includes some predefined functions. For example, it may include an activity manager, a window manager, a content provider, a view system, a resource manager, a notification manager, etc., and the embodiments of the present application do not impose any restrictions on this.

[0094] In an embodiment of the present application, the application framework layer may provide a package management service (PMS), which includes at least: an application installation module and a compilation optimization preprocessing module.

[0095] Among them, the application installation module can be used to scan the installation package of the application in the scenario of triggering compilation when the electronic device is idle, the scenario of the electronic device being turned on for the first time / restoring factory settings, and the scenario of the electronic device performing OTA upgrade, decompress the resources of the installation package of the application, parse AndroidManifest.xml, etc., and install the installation package of the application to the corresponding installation directory (i.e., installation path) of the electronic device. The application installation module can also send the information required for compilation, such as the package name, installation directory, and compilation parameters of the application, to the compilation optimization preprocessing module.

[0096] The compilation optimization preprocessing module is used to determine whether the current scenario is idle-triggered compilation of the electronic device (i.e., whether the electronic device has triggered idle-triggered compilation), the scenario of the electronic device being powered on for the first time / restoring factory settings, the scenario of the electronic device performing OTA upgrade (i.e., whether the electronic device has triggered idle-triggered compilation), etc., and can preprocess the relevant parameter information of the compilation optimization, and preprocess the parameters and files for the compilation optimization process.

[0097] In the embodiment of the present application, the application framework layer can also provide a daemon thread (Installd), which at least includes: a profile processing module and a compilation optimization module. The daemon thread can also be called a background thread or a service thread, which is not limited in the present application.

[0098] The profile processing module can be used to call the profman function to merge the profile files and / or baseline profile files that the compilation optimization process depends on (merge profile), that is, the hotspot functions indicated by the profile files and / or baseline profile files can be integrated into data / misc / profiles / ref / <packagename> / primary.prof directory, providing dex2oat with valid and available profile files.

[0099] The compiled optimization module can be used to call ART to perform dex2oat on the application.

[0100] The compilation optimization preprocessing module in PMS can also call the performDexopt function to access the compilation optimization module in Installd and obtain the compilation results from the compilation optimization module.

[0101] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0102] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0103] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0104] OpenGL ES is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0105] SGL is a graphics engine for 2D graphics.

[0106] Android Runtime (ART) includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.

[0107] In the embodiment of the present application, ART may include dex2oat, which may be called a bytecode optimization module. dex2oat can compile and process the dex file of the application.

[0108] The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0109] The HAL layer is an encapsulation of the Linux kernel driver, providing an interface to the upper layer and shielding the implementation details of the low-level hardware.

[0110] The HAL layer may include Wi-Fi HAL, audio HAL, camera HAL, etc.

[0111] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0112] The hardware layer includes displays, cameras, sensors, etc.

[0113] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. Wherein, in the description of the present application, unless otherwise specified, "at least one" refers to one or more, and "a plurality of" refers to two or more than two. In addition, in order to facilitate the clear description of the technical solutions in the embodiments of the present application, in the embodiments of the present application, the words "first", "second" and the like are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art will understand that the words "first", "second" and the like do not limit the quantity and execution order, and the words "first", "second" and the like do not limit them to be necessarily different.

[0114] This application combines the baseline profile technology with target compilation scenarios (scenarios where compilation is triggered when the electronic device is idle, scenarios where the electronic device is powered on for the first time / factory settings are restored, or scenarios where the electronic device is undergoing an OTA upgrade). Figure 4 As shown, in the scenario where the electronic device triggers compilation when idle, the electronic device is turned on for the first time / factory settings are restored, or the electronic device is upgraded OTA, the electronic device can obtain the baseline profile of the target application from the installation package of the target application, and perform speed-profile compilation on the dex file of the target application according to the baseline profile file to obtain a compiled optimization file. Subsequently, after the target application is installed, when the electronic device runs the target application, it can directly call the compiled optimization file without the need to compile the dex file of the target application on the fly, which saves compilation time, improves the execution efficiency of the electronic device on the application, makes the application run more smoothly, and can improve the user experience.

[0115] The target application refers to any application to be installed. For example, the target application may be a game application, a video application, an instant messaging application, a social application, a shopping application, etc. The specific type of the target application is not limited in the embodiment of the present application.

[0116] The following describes the software modules and the interactions between the modules involved in the application compilation method provided in the embodiment of the present application.

[0117] like Figure 5 As shown, the application installation module in the PMS of the electronic device executes the installation program in the installation package of the application. And, the application installation module determines whether the installation package of the application includes a baseline profile file. In some embodiments, the application installation module can determine whether the installation package of the application includes a baseline profile file by parsing the AndroidManifest.xml file in the installation package and reading the flag in the AndroidManifest.xml file. Among them, the flag is used to indicate whether the installation package of the application is configured with a baseline profile file. In other embodiments, the application installation module can actively check whether the installation package of the application contains a baseline profile file. If the application installation module determines that the installation package of the application includes a baseline profile file, the baseline profile file can be unzipped to a folder under the data / app / directory. In the scenario of idle trigger compilation of the electronic device, the scenario of the first startup / factory restoration of the electronic device, and the scenario of OTA upgrade of the electronic device, the compilation optimization preprocessing module requests the profile processing module of Installd to process the baseline profile file. The profile processing module integrates the hot function information in the baseline profile file. The compilation optimization preprocessing module can also preprocess the relevant parameter information of the compilation optimization on the PMS side, and preprocess the parameters and files for the compilation optimization process. The compiled optimization module can also call ART to perform dex2oat on the application.

[0118] The following is a detailed introduction to the application compilation method provided in the embodiment of the present application in conjunction with the accompanying drawings.

[0119] like Figure 6 As shown, the embodiment of the present application provides a method for compiling an application, including:

[0120] 601. When an electronic device (e.g., a mobile phone) installs a third-party application, or when the electronic device is turned on for the first time for scanning, or after the electronic device is restored to factory settings, the application installation module in the PMS of the mobile phone executes the installation program in the installation package of the target application.

[0121] When an electronic device (e.g., a mobile phone) installs a third-party application, or when the electronic device is turned on for the first time for scanning, or after the electronic device is restored to factory settings, the application installation module in the mobile phone's PMS can scan the installation package of the target application to extract the dex file in the installation package.

[0122] The target application may be any one or more third-party applications to be installed or any one or more pre-installed applications (system applications or pre-installed third-party applications) in the electronic device. For example, the target application may be a game application, a video application, an instant messaging application, a social application, a shopping application, etc. The specific type of the target application is not limited in the embodiments of the present application.

[0123] Among them, the third-party application to be installed can be downloaded from an application market, or can be downloaded from a web page, or can be shared by other devices, which is not limited in this application.

[0124] The application installation module can create an installation directory of the target application in the electronic device, and write the dex file in the installation package into the installation directory of the electronic device.

[0125] For example, if the target application is The application installation module can be created in the mobile phone The installation directory, such as data / app / *** / com.tencent.mm***, and The dex files in the installation package are written to the installation directory.

[0126] 602. The application installation module determines whether the installation package of the target application program includes a baseline profile file.

[0127] In some embodiments, when parsing the AndroidManifest.xml file (manifest file) in the installation package of the target application, the application installation module reads the flag (first flag) for configuring the baseline profile file, and determines whether the installation package of the target application contains the baseline profile file based on the first flag.

[0128] In a possible design, a flag (first flag) can be set in AndroidManifest.xml, and the first flag is used to indicate whether the installation package of the target application contains the baseline profile file. If the first flag is true, it means that the installation package of the target application contains the baseline profile file; if the first flag is false, it means that the installation package of the target application does not contain the baseline profile file.

[0129] The baseline profile file is a file compiled into the installation package of the target application. The baseline profile file records the hot functions of the target application and can be placed in the assets / dexopt / baseline.prof directory of the installation package. The baseline profile file and AndroidManifest.xml can be in the same directory.

[0130] When installing the target application, the application installation module can parse the AndroidManifest.xml file, read the first flag of the configuration baseline profile file, and store the first flag in the structure recording the installation package information. If the first flag is true, it means that the installation package of the target application contains the baselineprofile file; if the first flag is false, it means that the installation package of the target application does not contain the baselineprofile file.

[0131] In other embodiments, the application installation module may check whether the installation package of the target application contains the baseline profile file. That is, the application installation module may actively detect whether the assets / dexopt / baseline.prof file (i.e., the baseline profile file) exists in the installation package of the target application in the installation directory of the target application. If it is determined that the assets / dexopt / baseline.prof file exists, it is determined that the installation package of the target application contains the baseline profile file; if it is determined that the assets / dexopt / baseline.prof file does not exist, it is determined that the installation package of the target application does not contain the baseline profile file.

[0132] If the application installation module determines that the installation package of the application contains the baseline profile file, that is, the flag of the configuration baseline profile file is true, the baseline profile file of the application can be decompressed to a folder under the data / app / directory of the electronic device. The / data / app directory is the directory where the installation package of the application installed by the user is stored.

[0133] If the application installation module confirms that the installation package of the target application contains the baseline profile file, that is, the first flag bit of the baseline profile file is configured to be true, the mobile phone can verify the dex file in the installation package of the target application based on the first compilation mode (that is, the speed-profile (have profile) compilation mode), and compile the hot spots in the installation package of the target application, that is, steps 605-609 can be executed.

[0134] If it is determined that the installation package of the target application does not contain the baseline profile file, that is, the first flag bit of the baseline profile file is configured to false, the mobile phone can verify the dex file in the installation package of the target application based on the second compilation mode (speed-profile (noprofile) compilation mode or verify compilation mode).

[0135] 603. The compilation optimization preprocessing module determines the current compilation scenario (target compilation scenario).

[0136] In a mobile phone operating system (e.g., Android 8.0), there may be multiple compilation times (compilation times may also be referred to as compilation reasons). dexopt may perform different compilation processes according to different compilation times. The compilation methods used by different compilation processes may be preset in SystemProperty in advance and read from SystemProperty when used.

[0137] As shown in Table 2, the compilation modes and triggering scenarios corresponding to 7 compilation opportunities are shown.

[0138] Table 2

[0139]

[0140]

[0141] If the compilation optimization preprocessing module determines that the current compilation scenario is a scenario where the electronic device is idle and triggers compilation, as shown in Table 2, the compilation timing corresponding to the current compilation scenario is bg-dexopt, and the default compilation mode is the speed-profile compilation mode.

[0142] If the compilation optimization preprocessing module determines that the current compilation scenario is the first startup of the electronic device or the scenario after restoring the factory settings, as shown in Table 2, the compilation timing corresponding to the current compilation scenario is first-boot, and the default compilation mode is the verify compilation mode.

[0143] If the compilation optimization preprocessing module determines that the current compilation scenario is a scenario in which the electronic device performs an OTA upgrade (during the OTA upgrade startup process), as shown in Table 2, the compilation timing corresponding to the current compilation scenario is boot-after-ota, and the default compilation mode is the verify compilation mode.

[0144] If the compilation optimization preprocessing module determines that the current compilation scenario is a scenario where the electronic device performs an OTA upgrade (after the OTA upgrade enters the desktop), as shown in Table 2, the compilation timing corresponding to the current compilation scenario is post-boot, and the default compilation mode is the verify compilation mode.

[0145] In some embodiments, if the current standard compilation scenario is the scenario of the electronic device being powered on for the first time / after restoring factory settings or the electronic device being upgraded via OTA (during the OTA upgrade startup process or after the OTA upgrade enters the desktop), if the installation package of the target application includes a benchmark configuration file, the compilation optimization preprocessing module can modify the default compilation mode to the speed-profile compilation mode (i.e., the speed-profile (have profile) compilation mode). For example, the default compilation mode is verify or boot-after-ota or post-boot, and the modified compilation mode is speed-profile.

[0146] In some embodiments, if the current compilation scenario is a scenario in which the electronic device idle triggers compilation, the compilation optimization preprocessing module determines whether the target application is compiled for the first time. If it is not the first compilation, it determines whether the compilation timing (compilation reason) of the last compilation of the target application is bg-dexopt. If the compilation timing of the last compilation of the target application is not bg-dexopt, steps 604 and 605 can be executed.

[0147] The compilation optimization preprocessing module can check the compilation time of the last compilation of the target application from the odex file obtained by the last compilation of the target application.

[0148] 604. The compilation optimization preprocessing module sends a first request message to the profile processing module, where the first request message is used to request processing of a baseline profile file.

[0149] The first request message may include the package name (packagename), installation directory (for example, data / app / directory), compilation parameters and other information required for compilation of the target application. The compilation parameters include the mode identifier of the first compilation mode (speed-profile (have profile) compilation mode), compilation timing and the like.

[0150] For example, if the target application is For example, the compilation optimization preprocessing module can be based on Application Name The first request message is generated based on the installation directory "data / app / *** / com.tencent.mm***", the mode identifier of the first compilation mode (speed-profile (have profile) compilation mode), the compilation timing and other compilation parameters and sent to the profile processing module.

[0151] 605. The profile processing module processes the baseline profile file.

[0152] The profile processing module receives the first request message from the application installation module and performs the following processing according to the first request message:

[0153] (1) Check / data / misc / profiles / cur / 0 / <packagename>Check whether the directory (first configuration directory) exists. If the path does not exist, create the directory. <packagename>Indicates the package name of the target application.

[0154] (2) Move the baseline profile file from the data / app directory to / data / misc / profiles / cur / 0 / <packagename>directory.

[0155] (3) Set and update the isCheckForProfileUpdates flag (the second flag). The second flag is used to trigger the merge processing of the baseline profile file, that is, to trigger the merge profile process to provide dex2oat with a valid and available profile file.

[0156] like Figure 7 As shown, the merge profile process can refer to the profile processing module calling the profman function to integrate / data / misc / profiles / cur / 0 / <packagename>The hot function information in the baseline profile file in the directory. The integrated hot function information is stored in data / misc / profiles / ref / <packagename> / primary.prof directory (second configuration directory). Subsequently, dex2oat compiles according to the files in the second configuration directory (baselineprofile files).

[0157] In some embodiments, the electronic device can collect the hotspot functions of the target application during the operation of the target application, and generate a profile file (second configuration file) based on the collected hotspot functions. The profile file in the DM file can be stored in the data / app / directory. The profile file can be stored in / data / misc / profiles / cur / 0 / <packagename>Directory. Figure 8 As shown, the profile processing module can integrate / data / misc / profiles / cur / 0 / <packagename>The baseline profile files in the directory and the profile files generated by the electronic device based on the collected hotspot functions are used to obtain more accurate and comprehensive hotspot function information. The integrated hotspot function information is stored in data / misc / profiles / ref / <packagename> / primary.prof directory (second configuration directory). Subsequently, dex2oat compiles according to the files in the second configuration directory (baseline profile file and profile file generated by the electronic device according to the collected hotspot functions).

[0158] After the profile processing module completes processing of the baseline profile file (i.e., completes the merge profile process), it can notify the compilation optimization preprocessing module to complete processing of the baseline profile file (i.e., complete the merge profile process).

[0159] 606. The compilation optimization preprocessing module preprocesses the information required for compilation.

[0160] The compilation optimization preprocessing module can preprocess the information required for compilation on the PMS side, and preprocess parameters and files for the compilation optimization process in scenarios where compilation is triggered when the electronic device is idle, when the electronic device is turned on for the first time / restoring factory settings, and when the electronic device is upgraded OTA.

[0161] For example, the compilation optimization preprocessing module can perform security checks and protection on the information required for compilation, verify, check, and determine the necessity of compilation optimization based on the information required for compilation, and can perform lock operations and Split APK processing. Among them, Split APK is a solution to the problem of increasing size of APK installation packages. SplitAPK can split a large APK into multiple independent APKs. When the application is updated, it is not necessary to download the entire APK, but only a certain module can be downloaded separately to install the update.

[0162] 607. The compilation optimization preprocessing module sends a second request message to the compilation optimization module, where the second request message is used to request the compilation optimization module to enable compilation optimization for the current compilation scenario.

[0163] The second request message may include information required for compilation, such as the package name, installation directory, and compilation parameters of the target application.

[0164] 608. The compilation optimization module calls dex2oat in ART to compile the dex file of the target application.

[0165] After receiving the fourth request message, the compilation optimization module may call dex2oat in ART to compile the dex file of the target application in the speed-profile (have profile) compilation mode. Fig. 9 As shown, the specific process includes the following steps S1-S3.

[0166] S1. The compilation optimization module sends compilation instructions to dex2oat in the ART virtual machine.

[0167] The compilation optimization module can add the target application's package name, installation directory, mode identifier of the default compilation mode, compilation timing and other information required for compilation to the compilation instructions, and send the compilation instructions to dex2oat.

[0168] S2. dex2oat compiles the dex files in the installation directory according to the compilation instructions.

[0169] In addition to verifying the dex file and obtaining the corresponding odex file, dex2oat also performs AOT compilation on the code of the hot functions in the dex file of the target application according to the information of the hot functions indicated by the profile file, and obtains the corresponding compilation product: art file. The art file contains the address of the code of these hot functions, which is convenient for addressing these hot functions. The code of these hot functions is the code of the functions commonly used by the target application. Therefore, during the operation of the target application, after loading the art file into the memory, the electronic device can quickly address and run the found code, so that the target application runs more smoothly.

[0170] The compilation optimization module may also adjust compilation optimization parameters, that is, check and adjust the information in the fourth request message, create a path for an odex file to save the generated odex file, and so on.

[0171] S3. After the compilation is completed, dex2oat returns a compilation completion message to the compilation optimization module.

[0172] The compilation completion message may include the package name of the target application to indicate that the dex file of the target application has been compiled.

[0173] 609. The compilation optimization module sends the compilation optimization result to the compilation optimization preprocessing module.

[0174] The compilation optimization result is used to indicate that dex2oat has completed the compilation optimization of the dex file of the target application. The compilation optimization result may include the package name of the target application to indicate that the dex file of the target application has been compiled.

[0175] The present application solves the problem that the speed-profile (have profile) compilation mode cannot be triggered for compilation optimization due to the lack of a profile file in the target compilation scenario (for example, the scenario where the electronic device is idle and triggers compilation, the scenario where the electronic device is turned on for the first time / factory settings are restored, and the scenario where the electronic device is upgraded OTA). The compilation method and device of the application provided in the present application can combine the baseline profile technology with the target compilation scenario, without relying on the application market to provide DM files for the application (the DM file includes the profile file), and without waiting for the application to run to record the hot functions of the application to generate a profile file. The method provided in the present application can process the baseline profile file embedded in the APK on the electronic device side (for example, the mobile phone side), so that in the target compilation scenario, even if the user has not used the target application and the hot functions of the application cannot be recorded to generate a profile file when the application is running, the speed-profile (have profile) compilation mode can be triggered to compile and optimize the application, which can improve the performance of the application (application startup, sliding, etc.), thereby bringing a better experience to the user.

[0176] In some embodiments, if the user has used an application, the electronic device can record the hotspot functions of the application while the application is running to generate a profile file. In the target compilation scenario, the baselineprofile file and the profile file generated by the electronic device can be combined to obtain more accurate and comprehensive hotspot functions, and the application can be compiled and optimized in the speed-profile (have profile) compilation mode. Compared with compiling and optimizing the speed-profile compilation mode based only on the profile file generated by the electronic device, compiling and optimizing the speed-profile compilation mode based on the baseline profile file and the profile file generated by the electronic device can better improve the performance of the application, thereby bringing a better experience to the user.

[0177] It should be noted that in the scenario where the electronic device is turned on for the first time / after restoring the factory settings or the scenario where the electronic device is OTA upgraded (in the OTA upgrade startup process or after the OTA upgrade enters the desktop), the target application is compiled and optimized in the speed-profile (have profile) compilation mode on the electronic device side according to the baseline profile file, which saves more storage space than compiling and optimizing the target application in the speed-profile (have profile) compilation mode in the preset stage (the stage where the electronic device burns the operating system, system applications, and some third-party applications). This is because the size of the baseline profile file is smaller than the compilation optimization file (the compilation optimization file obtained by compiling and optimizing the target application in the speed-profile (have profile) compilation mode in the preset stage), which can reduce the number of files preset in the electronic device and save the storage space of the electronic device.

[0178] Based on the method provided in the embodiment of the present application, in the scenario where the electronic device triggers idle compilation, the scenario where the electronic device is turned on for the first time / factory settings are restored, and the scenario where the electronic device is upgraded OTA, the baseline profile file (benchmark configuration file) of the target application is obtained, and the dex file of the target application is compiled in the speed-profile (have profile) compilation mode according to the baseline profile file to obtain a compilation optimization file. After the compilation is completed, when the electronic device runs the target application, the compilation optimization file can be directly called, and there is no need to compile the dex file of the target application in real time, which saves compilation time, improves the execution efficiency of the electronic device for the application, makes the application run more smoothly, and can improve the user experience.

[0179] Some embodiments of the present application provide an electronic device, which may include: a touch screen, a memory, and one or more processors. The touch screen, the memory, and the processor are coupled. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device can perform the various functions or steps performed by the electronic device in the above method embodiment. The structure of the electronic device can refer to Figure 2 The structure of the electronic device 100 is shown.

[0180] The present application also provides a chip system (eg, a system on a chip (SoC)), such as Fig.10 As shown, the chip system includes at least one processor 1001 and at least one interface circuit 1002. The processor 1001 and the interface circuit 1002 can be interconnected via lines. For example, the interface circuit 1002 can be used to receive signals from other devices (such as a memory of an electronic device). For another example, the interface circuit 1002 can be used to send signals to other devices (such as a processor 1001 or a touch screen of an electronic device). Exemplarily, the interface circuit 1002 can read instructions stored in the memory and send the instructions to the processor 1001. When the instructions are executed by the processor 1001, the electronic device can execute the various steps in the above embodiments. Of course, the chip system may also include other discrete devices, which are not specifically limited in the embodiments of the present application.

[0181] An embodiment of the present application also provides a computer-readable storage medium, which includes computer instructions. When the computer instructions are executed on the above-mentioned electronic device, the electronic device executes each function or step executed by the electronic device in the above-mentioned method embodiment.

[0182] The embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes each function or step executed by the electronic device in the above method embodiment.

[0183] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0184] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0185] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0186] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0187] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0188] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.< / packagename> < / packagename> < / packagename> < / packagename> < / packagename> < / packagename> < / packagename> < / packagename> < / packagename>

Claims

1. A method for compiling an application, characterized in that: Applied to an electronic device, the electronic device includes an application installation module, a compilation optimization preprocessing module, a configuration file processing module, a compilation optimization module and a bytecode optimization module, and the method includes: The application installation module determines whether the installation package of the target application includes a reference configuration file in a target compilation scenario, wherein the reference configuration file is used to indicate hot functions in the installation package of the target application; wherein the target compilation scenario includes a scenario in which the electronic device triggers compilation in an idle state; If it is determined that the installation package of the target application includes the benchmark configuration file, the application installation module decompresses the benchmark configuration file to an installation directory; The configuration file processing module moves the reference configuration file from the installation directory to the first configuration directory; The configuration file processing module merges the hotspot functions indicated by the benchmark configuration file and the hotspot functions indicated by the first configuration file, and saves the merged hotspot function information to the second configuration directory; wherein the first configuration file is generated according to the hotspot functions recorded when the target application is running; The compilation optimization preprocessing module sends a request message to the compilation optimization module, wherein the request message is used to request the compilation optimization module to compile the target application, and the request message includes the package name of the target application; The compiling and optimizing module calls the bytecode optimizing module to compile the target application program; The bytecode optimization module performs AOT compilation on the code of the hotspot function in the dex file of the target application according to the hotspot function information in the second configuration directory to obtain a compiled product art file, wherein the art file contains the address of the code of the hotspot function.

2. The method according to claim 1, characterized in that The target compilation scenario also includes a scenario where the electronic device is powered on for the first time to trigger compilation, and a scenario where the electronic device is performing an over-the-air OTA upgrade to trigger compilation.

3. The method according to claim 1 or 2, characterized in that: The application installation module determines whether the installation package of the target application includes the reference configuration file, including: The electronic device parses a manifest file in an installation package of the target application, wherein a first flag is set in the manifest file, and the first flag is used to indicate whether the installation package of the target application includes the reference configuration file; The first flag is read. If the first flag is true, it means that the installation package of the target application includes the benchmark configuration file. If the first flag is false, it means that the installation package of the target application does not include the benchmark configuration file.

4. The method according to claim 1 or 2, characterized in that: The electronic device determining whether the installation package of the target application includes a reference configuration file comprises: The electronic device detects whether the reference configuration file exists in the installation directory of the target application.

5. An electronic device, characterized in that: The electronic device comprises a display screen, a processor and a memory; the memory stores program instructions; the processor is used to run the program instructions stored in the memory, so that the electronic device executes the method according to any one of claims 1-4.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes program instructions, and when the program instructions are executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Application program installation package compiling method, terminal, server and storage medium

    CN112596751A

  • Hotspot code processing method and device, server, electronic equipment and storage medium

    CN112948026A

  • Application program updating method and system, electronic equipment and terminal equipment

    CN113885870A