Method for quickly improving application startup performance based on Android virtual machine
By collecting profile information during application process startup in an Android virtual machine and generating art image code, the problems of harsh optimization conditions of the PGO mechanism and long waiting period in the existing technology are solved, and the application startup performance is quickly and effectively improved, and users are reduced. Waiting time.
Patent Information
- Application Number
- CN202010618098.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2040-06-30
AI Technical Summary
The existing PGO mechanism based on Android virtual machines is harsh in optimization conditions and long waiting periods, resulting in increased optimization pressure and time-consuming, poor user experience, and easy to interrupt optimization due to wake-up operation, which cannot effectively improve application startup performance.
The JIT module collects the startup profile information of functions and classes when the application process is started, and after the application process is started, it compiles and optimizes based on this information, generates art image code, reduces subsequent loading and compilation steps, and improves the application startup speed.
Without affecting the load, high frequency effectively improves the startup performance of the application process, reduces user waiting time, collects and utilizes small orders of magnitude profile information for optimization and compilation, generates execution code, reduces the loading steps of JIT modules, and improves the application Startup speed.
Smart Images

Figure CN111782297B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Android virtual machines, and in particular to a method for quickly improving application startup performance based on an Android virtual machine. Background Art
[0002] Android's system layer and applications are all written in Java and compiled and run based on virtual machines. When the existing optimization based on the Android virtual machine uses the PGO (Profile-Guided Optimization) mechanism to improve performance, the triggering conditions of the PGO mechanism are harsh and the waiting period is extremely long. When performing optimization, all profile information needs to be collected. During the long waiting period, the amount of profile information becomes extremely large, further increasing the optimization pressure and optimization time. In addition, it is very easy to interrupt the optimization due to the wake-up operation during optimization, resulting in long-term ineffective optimization, making the user experience worse. Summary of the invention
[0003] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a method for quickly improving application startup performance based on an Android virtual machine, which can effectively optimize the application startup speed at a high frequency.
[0004] According to the first aspect of the present invention, a method for quickly improving application startup performance based on an Android virtual machine includes: a startup information collection step, when the Android virtual machine starts the application process, the startup profile information generated by the functions and classes during the startup of the application process is collected through the JIT module; a startup compilation optimization step, after the application process is started, compilation optimization is performed according to the startup profile information to generate art mirror code.
[0005] The method for quickly improving application startup performance based on an Android virtual machine according to an embodiment of the present invention has at least the following beneficial effects: by collecting profile information when the application process is started, optimizing and compiling according to the startup profile information, generating corresponding execution code, and loading the execution code without going through the Jit module at the next startup, thereby speeding up the application startup speed; the order of magnitude of the collection is small, and the startup performance of the application process in the Android virtual machine can be continuously and effectively improved at a high frequency without affecting the load, thereby reducing user waiting time.
[0006] According to some embodiments of the present invention, the startup information collection step includes: the Andriod virtual machine monitors and identifies the running status of the application process, detects that the application process switches to the startup state, obtains the functions and classes running during the startup of the application process through the JIT module, and starts the profile thread; according to the functions and classes running during the startup of the application process, collects the startup profile information from the profile information file.
[0007] According to some embodiments of the present invention, the startup information collection step further includes: before collecting the startup Profile information, the Android virtual machine releases the profile information collection threshold limit of the startup part by setting information.
[0008] According to some embodiments of the present invention, the startup information collection step further includes: after the startup profile information is collected, clearing data corresponding to the startup profile information in the profile information file.
[0009] According to some embodiments of the present invention, the startup information collection step further includes: after the startup profile information is collected, marking the collection status of the startup profile information as completed in the runtime of the Android virtual machine.
[0010] According to some embodiments of the present invention, the startup compilation optimization step includes: triggering a detection thread when the application process is started, the detection thread determines whether new startup profile information is collected, and obtains a judgment result; creating a compilation optimization process according to the judgment result, performing optimization compilation based on the startup profile information through dex2oat, and generating art image code.
[0011] According to some embodiments of the present invention, the method of triggering a detection thread when the application process is started includes: AMS triggering a detection mechanism, the detection thread running in a message processing circular queue of a background package management service; through the message processing circular queue, detecting in turn whether the application process meets the PGO conditions; and obtaining the judgment result based on the startup information collection status.
[0012] According to some embodiments of the present invention, the method for creating a compilation optimization process includes: setting the dex2oat compilation overhead thread to -j*, the process scheduling policy to SP_BACKGROUND, and the process priority to ANDROID_PRIORITY_LOWEST.
[0013] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The above and / or additional aspects and advantages of the present invention will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0015] Figure 1 A schematic diagram of the main process steps of an embodiment of the present invention;
[0016] Figure 2 A schematic diagram of a startup information collection step according to an embodiment of the present invention;
[0017] Figure 3 A schematic diagram of the startup compilation optimization steps of an embodiment of the present invention;
[0018] Figure 4 This is a schematic diagram of a new flow chart added to the original PGO mechanism according to an embodiment of the present invention. DETAILED DESCRIPTION
[0019] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0020] Glossary:
[0021] JIT: just-in-time compilation. In a narrow sense, it is compilation when a piece of code is about to be executed for the first time, so it is called "just-in-time compilation".
[0022] AMS: Activity Manager Service, the core service program of the Android system, is the management of the Android upper framework, that is, the management service when the application is running.
[0023] PMS: Package Manager Service, the core service program of the Android system, is the Android upper-layer framework management, that is, the installation package management service of the application.
[0024] PGO: Profile-Guided Optimization, an optimization mechanism provided by the Android virtual machine.
[0025] Profile information: Information generated by the PGO mechanism, used for optimizing compilation.
[0026] dex2oat: An optimization tool provided by the Android virtual machine.
[0027] art image: .art executable file generated by dex2oat.
[0028] Reference Figure 1 In an embodiment of the present invention, the optimization method includes two parts: a startup information collection step and a startup compilation optimization step. In the startup information collection step, the Android virtual machine collects the profile information generated by the functions and classes during the startup of the application process through the JIT module to obtain the startup profile information. In the startup compilation optimization step, after the application is started, the startup profile information obtained in the startup information collection step is compiled and optimized to generate the art image code.
[0029] In the embodiment of the present invention, the startup information collection step refers to Figure 2 , including: First, the Android virtual machine releases the threshold limit for collecting profile information about the application startup part by setting information. Google has set a threshold limit related to profile information collection in order to reduce the amount of information collected. Opening this limit is conducive to obtaining complete profile information related to startup and achieving better optimization results. When the application process starts, the Android virtual machine will compile and run the bytecode through the JIT module, see Figure 4 , the running process of the application process APP includes: startup state, running state and stop state. The Android virtual machine monitors and identifies the startup state of the application, obtains the related functions (in Java, functions are also called methods) and classes in the startup state through the JIT module, and starts the profile thread. The profile thread will collect all profile information and store it in the corresponding profile document. The Android virtual machine extracts the profile information generated by the functions and methods running in the startup state from the profile document to obtain the startup profile information. In an embodiment of the present invention, in the process of collecting the startup profile information, the corresponding profile information collected in the original profile document is also cleared to prevent the profile document from being merged and affecting the profile during the startup period; it also includes marking the collection status of the startup profile information as completed.
[0030] The dynamic compilation optimization step of an embodiment of the present invention includes: when the application process is started, the detection thread is triggered, and the detection thread determines whether there is new startup profile information collected to obtain a judgment result; according to the judgment result, a compilation optimization process is created, and dex2oat is used to optimize the compilation based on the startup profile information to generate art image code. Specifically, when the application is started, the detection mechanism is triggered by the application management service (AMS), and the detection thread runs in the message processing loop queue of the background package management service (PMS). The message processing loop queue will detect whether the current app meets the PGO conditions in turn, such as whether the target application can be compiled, whether the profile information collection file primary.prof of the virtual machine corresponding to the target application is updated, and whether there is enough system storage space at present, etc. If it meets the PGO conditions, it will enter the next step (i.e., compilation optimization action), otherwise exit; the message processing loop processing can ensure mutually exclusive requests. Then, the collection status of the startup profile information is obtained. If the collection is completed, a new thread is created to schedule the virtual machine to perform special compilation actions. The compilation options include: setting the dex2oat compilation overhead thread to -j*, configuring the scheduling policy of the special dex2oat process to SP_BACKGROUND (background operation mode), and setting the process priority to ANDROID_PRIORITY_LOWEST (lowest). Since the compilation optimization is based only on a single startprofile information, the order of magnitude is small, and lowering the scheduling policy and priority can ensure that the user operation of the foreground is not affected. If the load allows, the compilation can be completed quickly and the art image code can be generated. The next startup does not need to be compiled and executed by Jit. At the same time, the art image code can be loaded, which greatly improves the startup performance.
[0031] Reference Figure 4, the left side of the middle vertical dotted line is the general flow chart of PGO, and the right side is the newly added mechanism of the embodiment of the present invention. Among them, the running process of Android app includes startup, running and stopping. If there is a bytecode that needs to be compiled during the running period, it will be compiled and executed by the Jit module in the virtual machine. At this time, the compiled target information will be captured by the Profile thread to generate the corresponding profile file. Before the PGO optimization compilation is started, the above process is repeated to iteratively integrate the profile information in the profile file. The background scheduling task specially used for compilation optimization is scheduled to a period of 1 day. It needs to be in the charging state and maintain the Idle state for 4260 seconds to be triggered, and if the machine wakes up after being triggered, it will be interrupted and it is necessary to wait for the next cycle opportunity; the profile information has many iterations, and it is for all apps that have been collected. The entire compilation optimization process will be particularly time-consuming, affecting the use of the current user, and only after a long wait can an opportunity to improve performance be found. In the newly added mechanism of the embodiment of the present invention, the current app running state is identified in the Android virtual machine, and the profile thread is immediately started at startup to collect the profile information generated by the Jit function (also called method in Java) and class during the start period to obtain the startup profile information. In an embodiment of the present invention, the startup profile information will become less and less as the number of times the application is started, because the profile information during startup will be immediately compiled and optimized to improve performance. In an embodiment of the present invention, the collected startup profile information is stored in a startup profile file, and the startup profile information is also cleared from the original profile file during the collection process. After the startup profile information collection is completed, the collection status of the startup profile information is marked as completed in the virtual machine runtime, and the special compilation process detects that the status is completed, and a new thread schedules the virtual machine for special compilation. In the compilation options of the special compilation, the dex2oat compilation overhead thread is set to -j*, the scheduling policy of the special dex2oat process is configured to SP_BACKGROUND (background operation mode), and the priority of the process is set to ANDROID_PRIORITY_LOWEST (lowest).
[0032] The embodiments of the present invention are described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Various changes can be made within the knowledge scope of ordinary technicians in the technical field without departing from the purpose of the present invention.
Claims
1. A method for quickly improving application startup performance based on an Android virtual machine, characterized in that: include: In the startup information collection step, when the application process is started, the Android virtual machine collects startup profile information generated by functions and classes during the startup of the application process through the JIT module; Start the compilation optimization step, the application process is started, and the compilation optimization is performed according to the startup profile information to generate art image code; The startup information collection step includes: The Android virtual machine monitors and identifies the running state of the application process, detects that the application process switches to the startup state, obtains the functions and classes running during the startup of the application process through the JIT module, and starts the profile thread; Collecting the startup profile information from the profile information file according to the functions and classes running during the startup of the application process; After the startup profile information is collected, the data corresponding to the startup profile information in the profile information file is cleared.
2. The method for quickly improving application startup performance based on Android virtual machine according to claim 1, characterized in that: The startup information collection step also includes: Before collecting the startup Profile information, the Android virtual machine releases the profile information collection threshold limit of the startup part by setting information.
3. The method for quickly improving application startup performance based on Android virtual machine according to claim 1, characterized in that: The startup information collection step also includes: After the startup profile information is collected, the collection status of the startup profile information is marked as completed in the runtime of the Android virtual machine.
4. The method for quickly improving application startup performance based on Android virtual machine according to claim 1, characterized in that: The step of starting compilation optimization includes: When the application process is started, the detection thread is triggered, and the detection thread determines whether new startup profile information is collected to obtain a determination result; A compilation optimization process is created according to the judgment result, and dex2oat is used to perform optimization compilation based on the startup profile information to generate art image code.
5. The method for quickly improving application startup performance based on Android virtual machine according to claim 4 is characterized in that: The method for triggering a detection thread upon completion of the application process startup includes: AMS triggers a detection mechanism, where the detection thread runs in the message processing loop queue of the background package management service; Through the message processing circular queue, detecting in turn whether the application process meets the PGO condition; The determination result is obtained according to the collection status of the startup profile information.
6. The method for rapidly improving application startup performance based on an Android virtual machine according to claim 4, characterized in that: The method for creating a compilation optimization process includes: Set the dex2oat compilation overhead thread to -j*, the process scheduling policy to SP_BACKGROUND, and the process priority to ANDROID_PRIORITY_LOWEST.
Citation Information
Patent Citations
Method and device for starting applications on mobile equipment
CN101957770A