Compiling optimization method and electronic device
By acquiring decision parameters and using a compilation decision model to select a suitable compilation optimization scheme, the problem of excessive compilation time was solved, and the operating performance of electronic devices was improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-26
- Publication Date
- 2026-03-31
AI Technical Summary
In electronic devices, as the usage time of applications increases, the number of hot functions increases, leading to longer compilation and optimization times and affecting device performance.
By acquiring multiple decision parameters, the execution time of the full compilation optimization scheme and the incremental compilation optimization scheme is evaluated using the compilation decision model. The compilation optimization scheme with shorter execution time is selected for compilation optimization. This includes acquiring parameters such as the number of newly added hot functions and classes, and the scale of the previous compilation result, and dynamically selecting the compilation scheme.
It optimizes compilation time, improves the performance of electronic devices, and reduces the impact of compilation on device operation.
Smart Images

Figure CN120909601B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of electronic technology, specifically to a compiler optimization method and an electronic device. Background Technology
[0002] Currently, during the operation of various applications on electronic devices, if an application undergoes functional optimization or upgrades, it needs to be recompiled to function properly. To reduce compilation power consumption and application lag during the compilation process, electronic devices can perform pre-compilation optimizations on applications. For example, during idle periods on the electronic device, the compilation of frequently executed functions can be optimized.
[0003] However, as the usage time of an application increases, the number of hot functions executed also increases accordingly. This leads to the electronic device taking longer and longer to perform compilation optimization, affecting the operating performance of the electronic device. Summary of the Invention
[0004] This application provides a compilation optimization method and an electronic device that can optimize compilation time and improve the operating performance of the electronic device.
[0005] In a first aspect, this application provides a compilation optimization method, which is executed by an electronic device and includes: upon triggering the start of compilation optimization for an application, acquiring multiple decision parameters, the multiple decision parameters being related to the execution time of the compilation optimization; determining a target compilation optimization scheme to be used for compilation optimization based on the multiple decision parameters, the target compilation optimization scheme including a full compilation optimization scheme or an incremental compilation optimization scheme; and performing compilation optimization based on the target compilation optimization scheme.
[0006] In related technologies, when electronic devices trigger the start of application compilation optimization, they typically select a fixed compilation optimization scheme, such as a full compilation optimization scheme or an incremental compilation optimization scheme. However, the full compilation optimization scheme requires compiling all hot functions contained in the application, which can take a long time. The incremental compilation optimization scheme requires loading and merging the oat files generated in the previous compilation, which can also take a long time. Therefore, if a fixed compilation optimization scheme is selected, the compilation execution time may not be optimal. Therefore, in the compilation optimization method of this application, when the electronic device starts application compilation optimization, multiple decision parameters are obtained to comprehensively evaluate the target compilation optimization scheme to be used for compilation optimization, and the compilation optimization scheme with the shorter execution time is selected to execute the compilation optimization task, thereby optimizing the compilation time and improving the operating performance of the electronic device.
[0007] In conjunction with the first aspect, in some implementations of the first aspect, multiple decision parameters include at least one of the following: the number of hotspot functions and classes added by the application from the last compilation to the current compilation; the total number of hotspot functions and classes included in the application when the last compilation was completed; the size of the oat file generated by the last compilation; the type of compilation optimization performed last time; the number of classes included in the application APK; the number of methods included in the application APK; and the execution time of the last compilation.
[0008] The decision parameters collected in this application are typically those that influence the execution time of compilation optimization. For example, the number of hot functions and classes added to the application between the last compilation and the current compilation reflects the scale of hot code during the current runtime, significantly impacting compilation execution time. The size of the oat file generated during the last compilation reflects the scale of the previous compilation result and can be used to assess the magnitude of changes in compilation execution time; for instance, a larger file indicates a larger compilation scale and longer file loading time, and so on. Therefore, by analyzing and evaluating these decision parameters, a suitable compilation optimization scheme for this compilation can be determined.
[0009] In conjunction with the first aspect, in some implementations of the first aspect, the above-mentioned determination of the target compilation optimization scheme based on multiple decision parameters includes: inputting multiple decision parameters into the compilation decision model to determine the target compilation optimization scheme to be used for compilation optimization.
[0010] In this application, an electronic device can process multiple decision parameters through a compilation decision model. This compilation decision model can include mapping relationships between different decision parameters and different types of compilation optimization schemes, and different decision parameters correspond to different weight coefficients. Under the influence of these weight coefficients, a target compilation optimization scheme can be output. In some implementations, the compilation decision model can be a deep learning-based network model.
[0011] In conjunction with the first aspect, in some implementations of the first aspect, the above-mentioned input of multiple decision parameters into the compilation decision model to determine the target compilation optimization scheme for compilation optimization includes: inputting multiple decision parameters into the compilation decision model, performing weighted calculations using the weight coefficients corresponding to the multiple decision parameters respectively, and obtaining a quantization result; if the quantization result is greater than a preset threshold, using the incremental compilation optimization scheme as the target compilation optimization scheme; if the quantization result is not greater than the preset threshold, using the full compilation optimization scheme as the target compilation optimization scheme.
[0012] In this implementation, if the quantization result output by the compilation decision model is greater than a preset threshold (e.g., 80 points), it is determined that the change range between the current compilation and the previous compilation is small, and an incremental compilation optimization scheme is suitable. If the quantization result output by the compilation decision model is not greater than the preset threshold, it is determined that the change range between the current compilation and the previous compilation is large, and a full compilation optimization scheme is suitable. Thus, the electronic device determines the target compilation optimization scheme based on the output of the compilation decision model to optimize the execution time of the compilation optimization.
[0013] In conjunction with the first aspect, in some implementations of the first aspect, the above-mentioned input of multiple decision parameters into the compilation decision model to determine the target compilation optimization scheme for compilation optimization includes: inputting multiple decision parameters into the compilation decision model, performing weighted calculations using the weight coefficients corresponding to the multiple decision parameters respectively, to obtain the first predicted time corresponding to the full compilation optimization scheme and the second predicted time corresponding to the incremental compilation optimization scheme; if the first predicted time is less than the second predicted time, the full compilation optimization scheme is taken as the target compilation optimization scheme; if the first predicted time is not less than the second predicted time, the incremental compilation optimization scheme is taken as the target compilation optimization scheme.
[0014] In this implementation, a compilation decision model can be used to estimate the first predicted time for executing the full compilation optimization scheme and the second predicted time for executing the incremental compilation optimization scheme. The first and second predicted times are then compared, and the compilation optimization scheme with the shorter time is selected as the target compilation optimization scheme. Thus, electronic devices can optimize the execution time of compilation optimizations.
[0015] In conjunction with the first aspect, in some implementations of the first aspect, the weight coefficient corresponding to the first decision parameter among multiple decision parameters is greater than the weight coefficient corresponding to the second decision parameter; the first decision parameter includes the number of hot functions and classes added by the application from the last compilation to the current compilation, and the size of the oat file generated by the last compilation; the second decision parameter includes the total number of hot functions and classes contained in the application when the last compilation was completed, the type of compilation optimization performed last time, the number of classes contained in the application APK, the number of methods contained in the application APK, and the execution time of the last compilation.
[0016] Among the aforementioned decision parameters, they can be categorized into core parameters and auxiliary parameters based on their impact on the execution time of compiler optimization. The weight coefficients of core parameters are greater than those of auxiliary parameters. For example, in this implementation, the first decision parameter is a core parameter, and the second decision parameter is an auxiliary parameter; the weight coefficient of the first decision parameter is greater than that of the second decision parameter. Therefore, by classifying the impact of the decision parameters and adaptively assigning corresponding weight coefficients, the accuracy of the determined target compiler optimization scheme can be improved.
[0017] In conjunction with the first aspect, in some implementations of the first aspect, the above-mentioned triggering to start application compilation optimization includes: triggering to start application compilation optimization when the electronic device is in an idle state.
[0018] The conditions that trigger the start of compilation optimization can be that the electronic device is in an idle state, such as the electronic device being charged and the screen being off for half an hour, or the electronic device being charged and the screen being off for half an hour and the battery level being greater than 95%, etc. Performing compilation optimization in this idle state can greatly reduce the impact on the operation of the electronic device, that is, reduce power consumption and further improve operating performance.
[0019] In conjunction with the first aspect, in some implementations of the first aspect, the above-mentioned compilation optimization based on the target compilation optimization scheme includes: when the target compilation optimization scheme is an incremental compilation optimization scheme, compiling the hot functions added to the application from the last compilation to the current compilation to obtain an oat file, merging the oat file with the oat file obtained from the last compilation to generate a new oat file; when the target compilation optimization scheme is a full compilation optimization scheme, compiling all hot functions included in the application to generate a new oat file.
[0020] Generally, once an electronic device determines whether to execute a full or incremental compilation optimization scheme, it can invoke the virtual machine to execute the corresponding optimization scheme. When executing a full compilation optimization scheme, the virtual machine needs to recompile all the application's hot functions, merging the results into a new oat file to replace the previously compiled oat file. When executing an incremental compilation optimization scheme, the virtual machine needs to compile the hot functions added between the last compilation and the current compilation, generating an oat file. It then loads the previously compiled oat file and merges the two oat files to generate a new oat file. Thus, electronic devices can implement dynamic compilation optimization schemes to optimize compilation time and improve the device's performance.
[0021] In conjunction with the first aspect, in some implementations of the first aspect, the electronic device includes a compilation parameter collection module, an execution module, a big data framework, a performance analysis module, an oat file generation module, and a compilation file module;
[0022] The above-mentioned acquisition of multiple decision parameters includes: the compilation parameter collection module sending a compilation parameter acquisition instruction to the execution module and a last compilation execution time acquisition instruction to the big data framework; the multiple decision parameters include the compilation parameters and the last compilation execution time; the execution module sending a first instruction to the performance analysis module to acquire the total number of hot functions and classes included in the application when the last compilation was completed; the execution module sending a second instruction to the performance analysis module to acquire the number of hot functions and classes added to the application from the last compilation to the current compilation; the execution module sending a third instruction to the oat file generation module to acquire the size of the oat file generated in the last compilation; the execution module sending a fourth instruction to the oat file generation module to acquire the compilation optimization type of the last execution; the execution module sending a fifth instruction to the compilation file module to acquire the number of classes and methods included in the application APK; the execution module sending the acquired compilation parameters back to the compilation parameter collection module; and the big data framework sending the last compilation execution time to the compilation parameter collection module.
[0023] In conjunction with the first aspect, in some implementations of the first aspect, the electronic device also includes a compilation decision module. The above-mentioned determination of the target compilation optimization scheme for compilation optimization based on multiple decision parameters includes: the compilation parameter collection module sending multiple decision parameters to the compilation decision module; and the compilation decision module determining the target compilation optimization scheme for compilation optimization based on the multiple decision parameters.
[0024] In the above implementation, the electronic device can be divided into multiple processing modules. The compilation parameter collection module (dexopter module) collects compilation parameters from the performance analysis module (profman module), the oat file generation module (oat_file_assistant module), and the compilation file module (dexfile module) through the execution module (artd module). It can also collect the execution time of the last compilation from the big data framework. Then, the compilation parameter collection module sends the collected decision parameters to the compilation decision module to determine the compilation optimization scheme to be adopted for this compilation, so as to improve the running performance of the electronic device.
[0025] Secondly, this application provides an apparatus included in an electronic device, which has the function of implementing the behaviors of the electronic device in the first aspect and possible implementations thereof. The function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-described functions. For example, a receiving module or unit, a processing module or unit, etc.
[0026] Thirdly, this application provides an electronic device, which includes: one or more processors, and a memory;
[0027] The memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code including computer instructions, which the one or more processors call to cause the electronic device to perform any one of the methods of the first aspect of the technical solution.
[0028] Fourthly, this application provides a chip system applied to an electronic device, the chip system including one or more processors, the one or more processors being configured to invoke computer instructions to cause the electronic device to perform the methods in the first aspect and any possible implementation thereof.
[0029] Optionally, the chip system also includes a memory, which is connected to the processor via circuitry or wires.
[0030] Alternatively, the chip system may also include a communication interface.
[0031] Fifthly, this application provides a computer-readable storage medium including instructions that, when executed on an electronic device, cause the electronic device to perform any one of the methods in the first aspect of the technical solution.
[0032] Sixthly, this application provides a computer program product, which includes computer program code that, when executed on an electronic device, causes the electronic device to perform any one of the methods in the first aspect of the technical solution. Attached Figure Description
[0033] Figure 1 This is a schematic diagram illustrating the overall process of an electronic device performing compilation optimization, as provided in an embodiment of this application.
[0034] Figure 2 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;
[0035] Figure 3 This is a software structure block diagram of an electronic device provided in an embodiment of this application;
[0036] Figure 4 This is a schematic diagram of the signaling interaction process of an example compilation optimization method provided in an embodiment of this application;
[0037] Figure 5 This is a schematic diagram illustrating the correspondence between multiple decision parameters and different weight coefficients provided in an embodiment of this application.
[0038] Figure 6 This is a flowchart illustrating an example of a compilation optimization method provided in an embodiment of this application. Detailed Implementation
[0039] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.
[0040] Hereinafter, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include one or more of that feature.
[0041] To ensure clarity and conciseness in the description of the following embodiments, a brief introduction to the relevant concepts or technologies is given first:
[0042] Interpreted execution is a method of executing programming languages that translates source code line by line into machine code and executes it immediately. Interpreted languages require code translation at runtime, meaning that the interpreter needs to read the source code line by line and convert it into instructions that the electronic device can understand.
[0043] Just-in-time (JIT) compilation: A compilation method that translates bytecode into machine code on runtime before execution. During program execution, hotspot functions are calculated using algorithms and then compiled in real-time. This consumes runtime resources and can cause process lag.
[0044] Ahead-of-time (AOT) compilation, as opposed to Just-In-Time (JIT) compilation, is a compilation method that converts bytecode into machine code before the program runs, which can improve runtime efficiency.
[0045] dex2oat (dalvik excutable file to optimized art file): is a program that compiles and optimizes dex files, converting the bytecode of a dex file into natively executable machine code. For example, in an Android device, the storage location is / system / bin / dex2oat, and the corresponding process after startup is dex2oat.
[0046] DEX files: Dalvik bytecode files are executable files that can be recognized by virtual machines in electronic devices.
[0047] oat file: A file generated by compiling and optimizing dex files based on dex2oat, which stores executable machine code.
[0048] Profile file: A configuration file that records hot functions and class index information during the compilation and optimization process of electronic devices, and can be continuously updated.
[0049] As electronic technology continues to improve, electronic devices undergo periodic application upgrades or optimizations. Typically, after an application upgrade or optimization, recompilation is required for the device to function properly.
[0050] Compilation refers to the process of using a compiler to generate a target program from a source program written in a source language. It can be the process of translating a program written in one programming language into an equivalent language. Generally, Android application packages (APKs) and JAR (Java archives) downloaded to electronic devices (such as phones running the Android system) are written in Java. To run them on an electronic device, these packages need to be compiled into a language that the device can recognize. When Java code is compiled into an APK, it is simply translated into cross-platform bytecode. This bytecode can be stored in a dex file and can be recognized by the virtual machine (Android runtime, ART) on different platforms (or electronic devices). However, after the virtual machine recognizes the bytecode, it still needs to be compiled into platform-compatible machine code before it can be executed by the central processing unit (CPU).
[0051] In early compilation processes, after translating Java code into bytecode, the virtual machine used JIT compilation or interpreted execution to compile the bytecode. This meant that the bytecode was translated into machine code on runtime and then executed by the CPU. This bytecode-to-machine-code translation operation was performed every time the application ran, undoubtedly increasing compilation power consumption and causing application stuttering. To address this issue, researchers developed AOT (Ahead-of-Time) compilation optimization, which pre-translates the bytecode of frequently used functions (or hot functions) in the APK into machine code and stores it, for example, as an oat file, for use on subsequent runs. This reduces compilation workload and power consumption, improving runtime efficiency. For example... Figure 1 As shown, during the compilation phase, for the bytecode after Java language code translation, if there is a corresponding oat file obtained through compilation optimization, it can be directly executed by the CPU. If there is no corresponding oat file, the virtual machine needs to perform JIT compilation on the bytecode.
[0052] The current compilation optimization method involves background compilation optimization during idle scenarios performed by the virtual machine during normal operation. Specifically, when the electronic device is idle, such as while charging and with the screen off for half an hour, the hot functions in the profile are compiled, and the compilation results (oat file) are stored on disk for direct execution later. The virtual machine can use the dex2oat mechanism for this background compilation. It can be understood that the hot functions in the profile are functions that are frequently executed during application runtime.
[0053] In related technologies, background compilation optimization performed by electronic devices in idle scenarios typically involves recompiling all hot-button functions of the application and replacing the oat file generated in the previous compilation. This compilation optimization method can also be called a full compilation optimization scheme. However, as the usage time of the application increases, the number of hot-button functions executed also increases accordingly, resulting in more and more hot-button functions needing to be compiled. This leads to longer compilation optimization times for electronic devices, affecting their operating performance. Based on this, researchers have proposed an incremental compilation optimization scheme. In this scheme, only hot-button functions added between the last compilation and the current compilation are compiled during the compilation optimization phase. The compiled result (oat file) is then merged with the previously compiled oat file, thereby reducing the number of hot-button functions optimized in each compilation and reducing the compilation optimization time. However, this incremental compilation optimization scheme still has some problems. Although it can reduce the number of hot-button functions during compilation optimization, it increases the time for loading the previously compiled oat file before compilation and the time for merging the currently compiled oat file with the previously compiled oat file. If the size of the oat file continues to increase, the loading time and merging time will also continue to increase, resulting in a longer compilation time.
[0054] In view of this, embodiments of this application provide a compilation optimization method. When compilation optimization is triggered, the execution time of the full compilation optimization scheme and the incremental compilation optimization scheme in an idle scenario can be evaluated, and the compilation optimization scheme with the shorter execution time can be selected to execute the compilation optimization task, thereby optimizing the compilation time and improving the operating performance of the electronic device. It should be noted that the compilation optimization method provided in embodiments of this application can be applied to electronic devices that can be compiled and optimized, such as mobile phones, tablets, wearable devices, in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). Embodiments of this application do not impose any restrictions on the specific type of electronic device.
[0055] For example, Figure 2This is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of this application. Taking a mobile phone as an example, 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, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identity module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0056] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0057] The charging management module 140 receives charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 receives charging input from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 receives wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also supply power to the electronic device via the power management module 141.
[0058] The power management module 141 connects 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, providing power to the processor 110, internal memory 121, external memory, display screen 194, camera 193, and wireless communication module 160, etc. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage current, impedance). In some other embodiments, the power management module 141 may also be located within the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be located in the same device.
[0059] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.
[0060] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLANs) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. 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 antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0061] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0062] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 100 may include one or N displays 194, where N is a positive integer greater than 1.
[0063] Camera 193 is used to capture still images or videos. An object is projected onto a photosensitive element by generating an optical image through the lens. The photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP for processing. The DSP converts the digital image signal into image signals in standard RGB, YUV, or other formats. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1.
[0064] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0065] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0066] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can utilize the characteristics of the collected fingerprints to achieve fingerprint unlocking, accessing application locks, taking photos with fingerprints, answering calls with fingerprints, etc.
[0067] Touch sensor 180K, also known as a "touch panel," can be located on display screen 194. The touch sensor 180K and display screen 194 together form a touchscreen, also known as a "touch screen." Touch sensor 180K detects touch operations applied to or near it. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through display screen 194. In other embodiments, touch sensor 180K may also be located on the surface of electronic device 100, in a different position than display screen 194.
[0068] Buttons 190 include a power button, volume buttons, etc. Buttons 190 can be mechanical buttons or touch-sensitive buttons. Electronic device 100 can receive button input and generate key signal inputs related to user settings and function control of electronic device 100.
[0069] Indicator 192 can be an indicator light, used to indicate charging status, power changes, or to indicate messages, missed calls, notifications, etc.
[0070] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0071] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses the layered architecture Android system as an example to exemplify the software structure of electronic device 100.
[0072] Figure 3 This is a software structure block diagram of an electronic device 100 according to an embodiment of this application. The layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom: the application layer, the application framework layer, the local service layer, and the kernel layer.
[0073] The application layer can include a series of application packages. For example... Figure 3 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS.
[0074] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0075] like Figure 3 As shown, the application framework layer can include a big data framework, window manager, content provider, view system, phone manager, resource manager, notification manager, etc.
[0076] Big data frameworks are used to track the execution time of each compilation optimization.
[0077] The window manager manages window programs. It can obtain screen size, determine the presence of a status bar, lock the screen, and capture screenshots. The content provider stores and retrieves data, making it accessible to applications. Data can include video, images, audio, made and received calls, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text and controls for displaying images. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon can include views for displaying text and views for displaying images. The phone manager provides communication functionality for the electronic device 100. For example, it manages call status (including connection, hang-up, etc.). The resource manager provides applications with various resources, such as localized strings, icons, images, layout files, video files, etc. The notification manager allows applications to display notification information in the status bar. It can be used to convey informational messages and can disappear automatically after a short pause without user interaction. For example, the notification manager is used to notify of download completion, message alerts, etc. The notification manager can also display notifications as icons or scrollbar text in the system's top status bar, such as notifications from background applications, or as dialog boxes on the screen.
[0078] The native service layer consists of the core libraries and the virtual machine. The core libraries comprise two parts: one part contains the functionalities that the Java language needs to call, and the other part is the Android core library.
[0079] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0080] A virtual machine can include a compilation parameter collection module, a compilation decision module, an execution module, a performance analysis module, an oat file generation module, and a compilation file module.
[0081] When preparing for compilation optimization on an electronic device, the compilation parameter collection module (dexopter module) can collect compilation parameters from the performance analysis module (profman module), the oat file generation module (oat_file_assistant module), and the compilation file module (dexfile module) through the execution module (artd module). It can also collect the execution time of the previous compilation from the aforementioned big data framework. These compilation parameters typically have a significant impact on the execution time of compilation optimization. After collecting the compilation parameters, the compilation parameter collection module passes them to the compilation decision module to determine the compilation optimization scheme to be adopted for this compilation. The aforementioned performance analysis module (profman module) is mainly responsible for performance analysis and optimization. Its core functions include monitoring the application's runtime performance, collecting runtime data, and adjusting optimization strategies based on the data. The compilation parameters it can provide include the number of hotspot functions and classes, including the number of hotspot functions and classes added during the period from the last compilation to the current compilation, and the total number of hotspot functions and classes included in the application when the last compilation was completed. The oat file generation module (oat_file_assistant module) is the core module responsible for handling oat file generation during virtual machine runtime. It is primarily used for generating and updating oat files, as well as handling dex2oat conversions. The compilation parameters it can provide include the size of the oat file generated during the last compilation and the type of compilation optimization performed last time (full compilation optimization or incremental compilation optimization). The compilation file module (dexfile module) can provide compilation parameters including the number of classes and methods included in the application APK.
[0082] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0083] For ease of understanding, the following embodiments of this application will be described using the following methods: Figure 2 and Figure 3 Taking the electronic device with the structure shown as an example, and in conjunction with the accompanying drawings and application scenarios, the compilation optimization method provided in this application embodiment will be specifically described.
[0084] Figure 4 This is a schematic diagram of the signaling interaction flow of an example compilation optimization method provided in this application embodiment, applied to the above. Figure 3 The software architecture shown includes the following methods:
[0085] S11, when the application's compilation optimization is triggered, the dexopter module sends a command to the artd module to retrieve compilation parameters.
[0086] S12, the dexopter module sends a command to the big data framework to retrieve the execution time of the last compilation.
[0087] The conditions that trigger the start of application compilation optimization can be that the electronic device is in an idle state, such as the electronic device being in a charging state and the screen being off for half an hour, or the electronic device being in a charging state and the screen being off for half an hour and the battery level being greater than 95%, etc. In this embodiment of the application, when the start of compilation optimization is triggered, the electronic device will first collect various compilation parameters and the execution time of the last compilation through the dexopter module. For ease of description, the various compilation parameters and the execution time of the last compilation can be collectively referred to as decision parameters.
[0088] S13, the artd module obtains the corresponding compilation parameters from each module.
[0089] S14, the artd module passes the various compilation parameters back to the dexopter module.
[0090] S15, the big data framework returns the execution time of the last compilation to the dexopter module.
[0091] In other words, after receiving the retrieval command from the dexopter module, the artd module can obtain the corresponding compilation parameters from the various compilation-related modules and return them to the dexopter module for subsequent compilation decisions. In some implementations, these modules may include, but are not limited to, the performance analysis module (profman module), the oat file generation module (oat_file_assistant module), and the compilation file module (dexfile module). Simultaneously, the big data framework can query the execution time of the last compilation and return it to the dexopter module. Here, the dexopter module can send a retrieval command for the execution time of the last compilation to the big data framework via the getCompileTime interface. The execution time of the last compilation returned by the big data framework can be recorded as last_compilation_time.
[0092] In some embodiments, decision parameters may include, but are not limited to, the number of hotspot functions and classes added to the application since the last compilation and during the current compilation, the total number of hotspot functions and classes included in the application when the last compilation was completed, the size of the oat file generated by the last compilation, the type of compilation optimization performed last time, the number of classes included in the application APK, the number of methods included in the application APK, and the execution time of the last compilation. For these decision parameters, the electronic device can add stubs in multiple modules within the virtual machine and obtain them through corresponding interfaces. For example, the dexopter module can send retrieval instructions to the artd module through different calling interfaces.
[0093] Specifically, see [link to relevant documentation] Figure 4 In S11, the dexopter module sends the instruction to the artd module to obtain compilation parameters, which can include the process in S111-S115:
[0094] S111, the dexopter module sends the first instruction to the artd module to obtain the total number of hot functions and classes included in the application when it was last compiled.
[0095] The index information of hot functions and classes included in the application when it was last compiled can be recorded in the Ref-profile file. Then the dexopter module can call the getOrInitReferenceProfile interface to send the first instruction to the artd module to count the total number of hot functions and classes included in the application when it was last compiled from the Ref-profile file.
[0096] In S112, the dexopter module sends a second instruction to the artd module to obtain the number of hot functions and classes added to the application since the last compilation and during the current compilation.
[0097] The index information of hot functions and classes added by the application from the last compilation to the current compilation can be recorded in the Cur-profile file. The dexopter module can then call the mergeProfilesToIncrementProfile interface to send a second instruction to the artd module to count the number of hot functions and classes added by the application from the last compilation to the current compilation from the Cur-profile file.
[0098] S113, the dexopter module sends a third instruction to the artd module to obtain the size of the oat file generated in the last compilation.
[0099] The dexopter module can call the getOatInfo interface to send a third instruction to the artd module to obtain the size of the oat file generated in the last compilation.
[0100] S114, the dexopter module sends a fourth instruction to the artd module to retrieve the type of compilation optimizations performed in the last execution.
[0101] The dexopter module can call the getBsetInfo interface to send a fourth instruction to the artd module to obtain the type of compilation optimizations performed last time.
[0102] S115, the dexopter module sends the fifth instruction to the artd module to obtain the number of classes and methods contained in the application APK.
[0103] The dexopter module can call the getDexInfo interface to send a fifth instruction to the artd module to obtain the number of classes and methods contained in the application APK.
[0104] After the artd module receives the above instructions, it can then send a retrieval command to the corresponding module to obtain the corresponding compilation parameters. For details, please refer to [link to documentation]. Figure 4 In S13, the artd module obtains the corresponding compilation parameters from various modules, which can include the processes in S131-S140:
[0105] S131, the artd module sends the first instruction to the profman module.
[0106] S132, the profman module returns to the artd module the total number of hot functions and classes included in the application at the time of the last compilation.
[0107] The artd module can call the ProcessProfiles interface to send the first instruction to the profman module to obtain the total number of hot functions and classes included in the application when it was last compiled. The total number of hot functions included in the application when it was last compiled can be recorded as num_of_method_in_ref_prof, and the total number of classes included in the application when it was last compiled can be recorded as num_of_class_in_ref_prof.
[0108] S133, the artd module sends a second instruction to the profman module.
[0109] S134, the profman module returns to the artd module the number of hotspot functions and classes added to the application since the last compilation and during the current compilation.
[0110] The artd module can also call the ProcessProfiles interface to send a second instruction to the profman module to obtain the number of hot functions and classes added by the application from the last compilation to the current compilation. The number of hot functions added by the application from the last compilation to the current compilation can be recorded as num_of_method_in_cur_prof, and the number of classes added by the application from the last compilation to the current compilation can be recorded as num_of_class_in_cur_prof.
[0111] S135, the artd module sends a third instruction to the oat_file_assistant module.
[0112] S136, the oat_file_assistant module returns the size of the oat file generated during the last compilation to the artd module.
[0113] The artd module can call the GetOptimizationStatus interface to send a third instruction to the oat_file_assistant module to obtain the size of the oat file generated in the last compilation. The size of the oat file generated in the last compilation may include size_of_origin_odex and size_of_origin_art.
[0114] S137, the artd module sends the fourth instruction to the oat_file_assistant module.
[0115] S138, the oat_file_assistant module returns the type of the last compilation optimization to the artd module.
[0116] The artd module can call the getBestInfo interface to send a fourth instruction to the oat_file_assistant module to obtain the last executed compilation optimization type, which can be denoted as last_compilation_type.
[0117] S139, the artd module sends the fifth instruction to the dexfile module.
[0118] S140, the dexfile module returns the number of classes and methods contained in the application APK to the artd module.
[0119] The artd module can call the NumClassDefs and NumMethodIds interfaces to send a fifth instruction to the dexfile module to obtain the number of classes and methods contained in the application APK. The number of classes contained in the application APK can be recorded as num_of_class_in_apk, and the number of methods contained in the application APK can be recorded as num_of_method_in_apk.
[0120] After the above process, the dexopter module can collect various decision parameters. Then, the dexopter module can execute the following step S15. It can be understood that the electronic device can collect the aforementioned decision parameters corresponding to each idle scenario for use in big data analysis and other operational needs.
[0121] S16, the dexopter module sends each decision parameter to the compilation decision module.
[0122] S17, the compilation decision module determines the target compilation optimization scheme to be used in this compilation based on various decision parameters.
[0123] In other words, the dexopter module will pass the collected decision parameters to the compilation decision module, which will then determine which compilation optimization scheme to execute, such as whether to execute the full compilation optimization scheme or the incremental compilation optimization scheme.
[0124] In some implementations, the compilation decision module can analyze various decision parameters based on a compilation decision model to determine the target compilation optimization scheme for this compilation. This compilation decision model includes the mapping relationship between different decision parameters and different types of compilation optimization schemes, with different decision parameters corresponding to different weight coefficients. As one possible approach, the compilation decision module inputs the obtained decision parameters into the compilation decision model and performs a weighted calculation on each parameter using different weight coefficients to obtain a quantitative result, such as a comprehensive score. If the quantitative result is greater than a preset threshold (e.g., 80 points), it is determined that the change range between this compilation and the previous compilation is small, and an incremental compilation optimization scheme is suitable. If the quantitative result is not greater than the preset threshold, it is determined that the change range between this compilation and the previous compilation is large, and a full compilation optimization scheme is suitable. As another feasible approach, the compilation decision module inputs the obtained decision parameters into the compilation decision model. By weighting each parameter with different coefficients, a first predicted time for executing the full compilation optimization scheme and a second predicted time for executing the incremental compilation optimization scheme can be obtained. By comparing the first and second predicted times, the compilation optimization scheme with the shorter time is selected as the target optimization scheme. In this implementation, the compilation decision model can also directly output the truth value type of the judgment result, such as true or false, where true indicates executing the incremental compilation optimization scheme and false indicates executing the full compilation optimization scheme.
[0125] For the compilation decision model, when determining the weight coefficients, the decision parameters for different applications executing full compilation optimization schemes and incremental compilation optimization schemes can be systematically collected and analyzed. Curve fitting methods can then be used to determine the weight coefficients of each decision parameter. Specifically, for the decision parameters such as the number of hot functions and classes added between the last compilation and the current compilation, the total number of hot functions and classes included in the application at the time of the last compilation, the size of the oat file generated in the last compilation, the type of compilation optimization performed in the last compilation, the number of classes in the application APK, the number of methods in the application APK, and the execution time of the last compilation, by analyzing the role of each parameter, it is possible to determine which decision parameters are the core parameters affecting compilation execution time and which are auxiliary parameters affecting compilation execution time, and then determine the corresponding weight coefficients for each. For example, the number of hotspot functions and classes added between the last compilation and the current compilation reflects the scale of hotspot code in the current runtime of the application, which has a significant impact on compilation execution time and can be identified as a core parameter; the size of the oat file generated in the last compilation reflects the scale of the previous compilation result and can be used to assess the magnitude of changes in compilation execution time. For example, a larger file indicates a larger compilation scale and a longer file loading time, so it can be identified as a core parameter; the total number of hotspot functions and classes included in the application when the last compilation was completed is used to compare the differences between the previous compilation configuration and the current compilation configuration, so it can be identified as an auxiliary parameter; the number of classes and methods included in the application APK reflects the scale of the application code structure and the number of methods, so it can be identified as an auxiliary parameter; the execution time of the last compilation is used to assess the trend of increase or decrease in compilation time, so it can be identified as an auxiliary parameter; the type of compilation optimization executed in the last execution is used to record historical compilation patterns and assist the compilation decision module in making judgments, so it can be identified as an auxiliary parameter.
[0126] Once the core or auxiliary roles of each decision parameter are determined, the compilation decision module can assign weight coefficients to each parameter. In some implementations, the weight coefficients for core parameters are greater than those for auxiliary parameters. For example, ... Figure 5As shown, among the decision parameters above, the weight coefficients of num_of_method_in_cur_prof are a%, num_of_class_in_cur_prof are b%, size_of_origin_odex are c%, size_of_origin_art are d%, num_of_class_in_ref_prof are e%, num_of_method_in_ref_prof are f%, num_of_method_in_apk are g%, num_of_class_in_apk are h%, last_compilation_time is m%, and last_compilation_type is n%. Among these, the weight coefficients a, b, c, and d can be greater than the other weight coefficients.
[0127] In some implementations, as the number of compilations increases, the relevant data for performing compilation optimization may change, and the degree of influence of the above-mentioned decision modules on compilation optimization may also change. Therefore, their corresponding weight coefficients can be adaptively updated to adapt to the real-time requirements of compilation optimization.
[0128] After determining whether to execute a full compilation optimization scheme or an incremental compilation optimization scheme based on the above process, the compilation decision module can send the determination result to the virtual machine for the virtual machine to execute the corresponding compilation optimization scheme. In the case of executing the full compilation optimization scheme, the virtual machine needs to recompile all the application's hot functions, and the compilation results are merged into a new oat file to replace the oat file obtained in the previous compilation. In the case of executing the incremental compilation optimization scheme, the virtual machine needs to compile the hot functions added to the application from the last compilation to the current compilation, and the compilation result is an oat file. Then, it loads the oat file obtained in the previous compilation, merges the two oat files, and generates a new oat file.
[0129] The compilation optimization method provided in this application allows an electronic device to obtain multiple decision parameters affecting compilation time when evaluating compilation optimization in an idle scenario. Based on these decision parameters, the device analyzes and evaluates the data to determine whether to execute a full compilation optimization scheme or an incremental compilation optimization scheme. This significantly reduces the execution time of compilation optimization and improves the operating performance and resource utilization of the electronic device.
[0130] Based on the process of the above embodiments, Figure 6 A flowchart illustrating a compiler optimization method applied to electronic devices is also provided. This method includes:
[0131] S101, when triggering the start of application compilation optimization, obtains multiple decision parameters.
[0132] The condition for triggering the start of compilation optimization can be that the electronic device is in an idle state. When compilation optimization is triggered, the electronic device begins to collect and acquire multiple decision parameters. These decision parameters can be understood to have a certain impact on the execution time of the electronic device's compilation optimization, including but not limited to the number of hotspot functions and classes added to the application since the last compilation, the total number of hotspot functions and classes included in the application at the time of the last compilation, the size of the oat file generated in the last compilation, the type of compilation optimization performed in the last compilation, the number of classes included in the application APK, the number of methods included in the application APK, and the execution time of the last compilation.
[0133] S102, based on multiple decision parameters, determines the target compilation optimization scheme to be used in this compilation.
[0134] That is, the electronic device can determine whether to execute a full compilation optimization scheme or an incremental compilation optimization scheme based on the above-mentioned multiple decision parameters. It is understood that the process of determining the target compilation optimization scheme can be found in the description of the above embodiments, and will not be repeated here.
[0135] For example, suppose the execution time of the last compilation was 10 minutes, the compilation optimization type was a full compilation optimization scheme, and the total number of hot functions and classes included at the time of compilation was 100. The number of new hot functions and classes added between the last compilation and the current compilation is 10. The estimated time for loading the oat file generated in the last compilation and merging the files is 5 minutes. Therefore, the estimated execution time for this compilation is approximately 11 minutes if a full compilation optimization scheme is used, and approximately 6 minutes if an incremental compilation optimization scheme is used. Since the incremental compilation optimization scheme has a shorter execution time, the target compilation optimization scheme can be the incremental compilation optimization scheme.
[0136] S103 performs compilation optimization based on the target compilation optimization scheme.
[0137] Once the electronic device has determined the target compilation optimization scheme, it can begin background compilation optimization. During compilation optimization, the electronic device can continue to record the generated decision parameters for reference in the next compilation.
[0138] In some embodiments, the electronic device executes the above-described compilation optimization method when it is in an idle state. If the electronic device changes from an idle state to a working state, the compilation optimization process can be paused, the progress of compilation can be recorded, and the compilation optimization can be continued when the device enters an idle state again, so as to reduce the processing power consumption of the electronic device.
[0139] The above-mentioned compilation optimization method allows electronic devices to obtain multiple decision parameters that affect compilation time when evaluating compilation optimization in idle scenarios. Based on these decision parameters, it determines whether to execute a full compilation optimization scheme or an incremental compilation optimization scheme, thereby significantly reducing the execution time of compilation optimization and improving the operating performance and resource utilization of electronic devices.
[0140] The foregoing has detailed examples of the compilation optimization methods provided in the embodiments of this application. It is understood that, in order to achieve the above-described functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.
[0141] This application embodiment can divide the electronic device into functional modules according to the above method example. For example, each function can be divided into a separate functional module, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods.
[0142] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here.
[0143] The electronic device provided in this embodiment is used to execute the above-described compilation optimization method, and therefore can achieve the same effect as the above-described implementation method.
[0144] When using integrated units, the electronic device may further include a processing module, a storage module, and a communication module. The processing module is used to control and manage the operation of the electronic device. The storage module supports the execution of stored program code and data. The communication module supports communication between the electronic device and other devices.
[0145] The processing module can be a processor or a controller. It can implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, or other devices that interact with other electronic devices.
[0146] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment can be a device having... Figure 2 The device with the structure shown.
[0147] This application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor performs the compilation and optimization method of any of the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0148] This application also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the compilation optimization method described in the above embodiments.
[0149] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the chip to execute the compilation optimization methods in the above method embodiments.
[0150] In this embodiment, the electronic device, computer-readable storage medium, computer program product or chip are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding methods provided above, and will not be repeated here.
[0151] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above 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.
[0152] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0153] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method of compilation optimization, the method being performed by an electronic device, the method comprising: The method comprises: In a case that triggering starting the compilation optimization of the application, obtaining a plurality of decision parameters, the plurality of decision parameters being related to the execution time of the compilation optimization, the plurality of decision parameters comprising the number of hotspot functions and classes added by the application from the last compilation to the present compilation, the total number of hotspot functions and classes contained by the application when the last compilation is completed, the oat file size generated by the last compilation, the type of the last executed compilation optimization, the number of classes contained in the application APK, the number of methods contained in the application APK, and the execution time of the last compilation; Based on the plurality of decision parameters, determining a target compilation optimization scheme adopted for the compilation optimization, the target compilation optimization scheme comprising a full-amount compilation optimization scheme or an incremental compilation optimization scheme; Based on the target compilation optimization scheme, performing the compilation optimization.
2. The method of claim 1, wherein, The determination of the target compilation optimization scheme adopted for the compilation optimization based on the plurality of decision parameters comprises: Inputting the plurality of decision parameters into a compilation decision model to determine the target compilation optimization scheme adopted for the compilation optimization.
3. The method of claim 2, wherein, The inputting of the plurality of decision parameters into the compilation decision model to determine the target compilation optimization scheme adopted for the compilation optimization comprises: Inputting the plurality of decision parameters into the compilation decision model to perform weighted calculation through the weight coefficients corresponding to the plurality of decision parameters to obtain a quantization result; In a case that the quantization result is greater than a preset threshold, taking the incremental compilation optimization scheme as the target compilation optimization scheme; In a case that the quantization result is not greater than the preset threshold, taking the full-amount compilation optimization scheme as the target compilation optimization scheme.
4. The method of claim 2, wherein, The inputting of the plurality of decision parameters into the compilation decision model to determine the target compilation optimization scheme adopted for the compilation optimization comprises: Inputting the plurality of decision parameters into the compilation decision model to perform weighted calculation through the weight coefficients corresponding to the plurality of decision parameters to obtain a first predicted time consumption corresponding to the execution of the full-amount compilation optimization scheme and a second predicted time consumption corresponding to the execution of the incremental compilation optimization scheme; In a case that the first predicted time consumption is less than the second predicted time consumption, taking the full-amount compilation optimization scheme as the target compilation optimization scheme; In a case that the first predicted time consumption is not less than the second predicted time consumption, taking the incremental compilation optimization scheme as the target compilation optimization scheme.
5. The method according to claim 3 or 4, characterized in that, The weight coefficient corresponding to a first decision parameter in the plurality of decision parameters is greater than the weight coefficient corresponding to a second decision parameter; The first decision parameter comprises the number of hotspot functions and classes added by the application from the last compilation to the present compilation and the oat file size generated by the last compilation; The second decision parameter comprises the total number of hotspot functions and classes contained by the application when the last compilation is completed, the type of the last executed compilation optimization, the number of classes contained in the application APK, the number of methods contained in the application APK, and the execution time of the last compilation.
6. The method of claim 1, wherein, The triggering of starting the compilation optimization of the application comprises: In a case where the electronic device is in an idle state, triggering to start the compilation optimization of the application.
7. The method of claim 1, wherein, The compilation optimization is performed based on the target compilation optimization scheme, including: In a case where the target compilation optimization scheme is the incremental compilation optimization scheme, compiling the hotspot functions newly added to the application from the last compilation to the present compilation, obtaining an oat file, merging the oat file with the oat file obtained from the last compilation, and generating a new oat file; In a case where the target compilation optimization scheme is the full-amount compilation optimization scheme, compiling all the hotspot functions included in the application, and generating a new oat file.
8. The method of claim 1, wherein, The electronic device includes a compilation parameter collection module, an execution module, a big data framework, a performance analysis module, an oat file generation module, and a compilation file module; The obtaining of the plurality of decision parameters includes: The compilation parameter collection module sends a compilation parameter obtaining instruction to the execution module, and sends a last compilation execution time obtaining instruction to the big data framework, and the plurality of decision parameters include the compilation parameter and the last compilation execution time; The execution module sends a first instruction to the performance analysis module to obtain the total number of hotspot functions and classes included in the application when the last compilation is completed; The execution module sends a second instruction to the performance analysis module to obtain the number of hotspot functions and classes newly added to the application from the last compilation to the present compilation; The execution module sends a third instruction to the oat file generation module to obtain the oat file size generated from the last compilation; The execution module sends a fourth instruction to the oat file generation module to obtain the last execution compilation optimization type; The execution module sends a fifth instruction to the compilation file module to obtain the number of classes and methods included in the application APK; The execution module returns the obtained compilation parameters to the compilation parameter collection module; The big data framework sends the last compilation execution time to the compilation parameter collection module.
9. The method of claim 8, wherein, The electronic device further includes a compilation decision module, and the target compilation optimization scheme for the compilation optimization is determined based on the plurality of decision parameters, including: The compilation parameter collection module sends the plurality of decision parameters to the compilation decision module; The compilation decision module determines the target compilation optimization scheme for the compilation optimization based on the plurality of decision parameters.
10. An electronic device, comprising: The electronic device includes: one or more processors, and a memory; The memory is coupled with the one or more processors, and the memory is configured to store computer program codes, the computer program codes including computer instructions, and the one or more processors are configured to invoke the computer instructions to enable the electronic device to perform the method in any one of claims 1 to 9.
11. A chip system, characterized by The chip system is applied to an electronic device, and the chip system includes one or more processors configured to invoke computer instructions to enable the electronic device to perform the method in any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes instructions that, when executed on the electronic device, cause the electronic device to perform the method of any of claims 1-9.
13. A computer program product, characterised in that, The computer program product includes a computer program that, when executed on the electronic device, causes the electronic device to perform the method of any of claims 1-9.
Citation Information
Patent Citations
Dex file compiling control method and device
CN114996078A
Automatic incremental compiling method and system for Java development
CN119396406A