Compilation-optimized resource allocation method and electronic equipment
By dynamically adjusting the compilation resource allocation of the dex2oat process, the application lag caused by the dex2oat process's preemption of device resources in Android devices is solved, and the user experience and device performance are improved.
Patent Information
- Application Number
- CN202310859159.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-12
- Publication Date
- 2025-01-14
AI Technical Summary
In Android devices, the dex2oat process preempts device resources, causing the application running in the foreground to be stuttered, affecting the user experience, especially performance problems caused by excessive compilation resources allocation during application installation.
By determining whether the application running in the foreground is an important application or important application scenario, dynamically adjust the compilation resource allocation of the dex2oat process to reduce the preemption of device resources, such as reducing the number of compilation and optimization threads and CPU resources in important applications or scenarios, avoiding The impact of application installation on device performance.
It effectively avoids the stuttering of front-end applications during application installation, improves user experience, and optimizes equipment performance, ensuring the normal operation of important applications and scenarios.
Smart Images

Figure CN119311276A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a compilation-optimized resource allocation method and electronic device. Background Art
[0002] Compilation optimization dex2oat is an important way to improve applications on Android devices. By precompiling the code in the Android application package (apk), the code running speed can be improved. Before the dex2oat process, compilation resources need to be allocated to ensure the normal operation of the dex2oat process. Compilation resources are the compilation parameters involved in the dex2oat process, such as the number of threads used when compiling and optimizing, the CPU resources occupied, etc.
[0003] Application installation is the most common application scenario of the Android operating system. Dex2oat is the last part of the application installation process and is also a relatively time-consuming part. In order to reduce the installation time of application installation, more compilation resources are often allocated to the dex2oat process to improve the compilation optimization execution efficiency and shorten the installation time of application installation.
[0004] However, as application functions become more complex, the amount of code in a single application continues to increase, and the compilation optimization time will also increase accordingly, so more compilation resources need to be allocated to shorten the application installation time. However, the more compilation resources are allocated, the greater the consumption of device resources during the compilation process, resulting in the dex2oat process preempting device resources, affecting device performance, and causing the application running in the foreground to freeze. Summary of the invention
[0005] The present application provides a compilation-optimized resource allocation method and an electronic device, which are used to prevent the dex2oat process from preempting device resources and affecting device performance, causing the application running in the foreground to freeze, thereby improving the user experience.
[0006] In order to achieve the above objectives, this application adopts the following technical solutions:
[0007] In a first aspect, the present application provides a compilation optimized resource allocation method, the method comprising:
[0008] Determine whether the application running in the foreground is an application in the important application set. If so, reduce the compilation resources allocated to compilation optimization; if not, determine whether the application scenario running in the foreground is a scenario in the important application scenario set. When it is determined that the application scenario running in the foreground is a scenario in the important application scenario set, reduce the compilation resources allocated to compilation optimization. Among them, the important application set is a set of important applications pre-stored in the electronic device; if so, reduce the compilation resources allocated to compilation optimization; the important application scenario set is a set of important application scenarios pre-stored in the electronic device. In this way, the preemption of device resources by the dex2oat process is reduced, thereby avoiding the impact of application installation on device performance, avoiding the freeze of the application running in the foreground, and optimizing the user experience.
[0009] Optionally, it is determined whether the application is in an application installation compilation optimization scenario; if not, it is determined whether the application currently running in the foreground is an application in a set of important applications.
[0010] Optionally, if so, determine whether the application installation corresponding to the application installation compilation optimization scenario belongs to an application market installation or an update within the application market; if the application installation does not belong to an application market installation and does not belong to an update within the application market, determine whether the application running in the foreground is an application in the important application set.
[0011] Optionally, if the application installation is an installation in the application market, or an update in the application market, the compilation resources allocated to the compilation optimization are increased.
[0012] Compared with other application scenarios, such as idle compilation optimization scenarios, the application installation compilation optimization scenario involves installation in the application market, or update installation in the application market, in which case the user needs to wait for the installation to complete. Therefore, for the above situations, it is determined whether the application is in the application installation compilation optimization scenario and discussed in different situations to further improve the user experience.
[0013] Optionally, the compilation resources of the dex2oat process are increased by allocating to a super-large core for compilation optimization and / or increasing the number of threads used when executing the compilation optimization.
[0014] Optionally, when the display interface is displayed on a bright screen, it is determined whether the application is in an application installation compilation optimization scenario.
[0015] Optionally, when the display interface is in an off-screen display and the off-screen display duration is greater than a second preset duration, the compilation resources allocated to the compilation optimization are not adjusted.
[0016] When the display interface of the electronic device is in the off-screen display, and the off-screen display duration is greater than the second preset duration, it indicates that the user does not need to wait for the installation of the application to be completed. At this time, there is no need to adjust the dex2oat compilation resources. Therefore, firstly determine whether the screen is off and then make subsequent judgments to improve the resource allocation processing efficiency of compilation optimization.
[0017] Optionally, in response to receiving the current trigger condition, determine whether the current trigger condition is an installation process trigger condition; if so, determine that the application is in an application installation compilation optimization scenario; if not, determine that the application is not in an application installation compilation optimization scenario.
[0018] Optionally, in response to identifying a scene switch of an application running in the foreground during the compilation optimization process, scene switching content is obtained, where the scene switching content includes the application installation compilation optimization scene switching from foreground running to background running, or from background running to foreground running; based on the scene switching content, the compilation resources in the ongoing compilation optimization process are modified.
[0019] Optionally, the compilation optimization is limited to execution on small and medium cores.
[0020] Optionally, the applications in the important application set include: short video platform applications, instant messaging applications, and video players.
[0021] Optionally, the scenarios in the important application scenario set include: a video call scenario and an in-application sliding scenario.
[0022] In a second aspect, the present application provides an electronic device, which includes a memory and a processor, wherein the memory is coupled to the processor; the memory stores a program, and when the program is executed by the processor, the electronic device executes any one of the methods in the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A software structure diagram of a resource allocation method application compiled and optimized for the prior art;
[0024] Figure 2 A flow chart of a compilation optimized resource allocation method provided in an embodiment of the present application;
[0025] Figure 3 A schematic diagram of an application scenario of a resource allocation method for compilation optimization is provided for an embodiment of the present application;
[0026] Figure 4 A schematic diagram of an application scenario of another compilation-optimized resource allocation method provided in an embodiment of the present application;
[0027] Figure 5 A software structure diagram of an electronic device according to an embodiment of the present invention;
[0028] Figure 6 An interactive diagram of a compilation-optimized resource allocation method provided in an embodiment of the present application;
[0029] Figure 7 A schematic diagram of releasing a super-large core provided in an embodiment of the present application;
[0030] Figure 8 A schematic diagram for reducing the compilation resources of dex2oat;
[0031] Fig. 9 A schematic diagram of adjusting a CPU set value provided in an embodiment of the present application;
[0032] Fig.10 A schematic diagram of the structure of an electronic device. DETAILED DESCRIPTION
[0033] The terms "first", "second", "third", etc. in the specification, claims and drawings of this application are used to distinguish different objects rather than to limit a specific order.
[0034] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0035] In order to enable those skilled in the art to better understand the present application, professional terms are first introduced.
[0036] Android application package (apk): is an application file format used by the Android operating system to distribute and install mobile applications and middleware. If an Android application code wants to run on an Android device, it must be compiled first and then packaged into a file that can be recognized by the Android system before it can run. The file format that can be recognized and run by the Android system is "apk", which is composed of xml, resource files, and dex (binary bytecode) files.
[0037] dex2oat process: also known as compilation optimization, is used to optimize the received apk file and generate one or more compiled oat files. The oat file is an Android private elf file format, which not only contains the local machine instructions translated from the dex file, but also includes the original dex file content. For APK, the oat file is actually a packaging of the odex file.
[0038] Dex2oat is an important way to improve applications on Android devices. By precompiling the code in the apk, the code running speed can be improved. Before the dex2oat process, compilation resources need to be allocated to ensure that the dex2oat process proceeds normally.
[0039] Compilation resources are the compilation parameters involved in the dex2oat process, such as the number of threads used during compilation optimization execution and the CPU resources occupied.
[0040] The number of threads used when executing compilation optimization refers to the number of threads executed simultaneously during compilation optimization, such as starting one thread to execute compilation optimization. It can be understood that the more threads used when executing compilation optimization, the higher the compilation optimization execution efficiency.
[0041] The CPU resources occupied refer to the CPU resources occupied by the dex2oat process. It can be understood that the more CPU resources are occupied, the higher the execution efficiency of dex2oat is.
[0042] Application installation is the most common application scenario of the Android operating system. Dex2oat is the last part of the application installation process and is also a relatively time-consuming part. In order to reduce the installation time of application installation, more compilation resources are often allocated to the dex2oat process to improve the compilation optimization execution efficiency and shorten the installation time of application installation.
[0043] However, as application functions become more complex, the amount of code in a single application continues to increase, and the compilation optimization time will also increase accordingly, so more compilation resources need to be allocated to shorten the application installation time. However, the more compilation resources are allocated, the greater the consumption of device resources during the compilation process, resulting in the dex2oat process preempting device resources and affecting device performance, such as causing the application running in the foreground to freeze, affecting the user's visual experience.
[0044] First, let me introduce the causes of technical problems.
[0045] See also Figure 1 , which is a software structure block diagram of the resource allocation method application compiled with prior art optimization.
[0046] The layered architecture divides the software into several layers, each with clear roles and division of labor. The 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 Android runtime and system library, and the kernel layer.
[0047] The application layer can include a series of application packages.
[0048] like Figure 1 As shown, the application package may include application programs such as application installation compilation optimization and idle compilation optimization.
[0049] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0050] like Figure 1 As shown, the application framework layer may include a compilation initiation module, etc.
[0051] The compilation initiation module is used to initiate the compilation of the compilation task in response to the startup compilation optimization scenario, such as the application installation compilation optimization scenario or the idle compilation optimization scenario. The compilation initiation module is used to manage the installation of various software
[0052] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0053] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0054] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0055] The system library can include multiple functional modules, such as compilation optimization modules.
[0056] Compile optimization modules for dex2oat threads.
[0057] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0058] The prior art creates an application installation task for the application layer and sends the task to the compile initiation module of the application framework layer, which then performs the application installation. The compile initiation module calls the compile optimization module interface to execute dex2oat to optimize the apk file.
[0059] However, when too many resources are allocated to the dex2oat process during compilation optimization, which consumes more device resources and affects device performance, the existing technology cannot achieve less compilation resources.
[0060] In view of the above problems, an embodiment of the present application provides a compilation-optimized resource allocation method to determine whether the application running in the foreground is an application in the preset important application set, or whether the application scenario running in the foreground is a scenario in the important application scenario set. When the application running in the foreground is an application in the preset important application set, or the application scenario running in the foreground is a scenario in the important application scenario set, the compilation resources of the dex2oat process are reduced. In this way, the preemption of device resources by the dex2oat process is reduced, thereby avoiding the impact of application installation on device performance, such as problems such as freezing of the application running in the foreground and heating of the device, thereby improving the user experience.
[0061] See also Figure 2 , is a flow chart of a compilation optimized resource allocation method provided in an embodiment of the present application. The method comprises:
[0062] S21: In response to the acquired current trigger condition, the electronic device triggers the compilation optimization scenario.
[0063] In the embodiment of the present application, one or a combination of compilation optimization scenarios: preset compilation optimization scenario, first boot compilation optimization scenario, idle compilation optimization scenario, application installation compilation optimization scenario. Different compilation optimization scenarios have different compilation levels, corresponding scenarios, and triggering conditions.
[0064] See Table 1, which is a table of compilation optimization scenarios and related information provided in an embodiment of the present application.
[0065] Table 1 is a compilation optimization scenario and related information table provided in an embodiment of the present application
[0066]
[0067]
[0068] As shown in Table 1, different compilation optimization scenarios have different compilation levels. The level of the preset compilation optimization scenario, the first boot compilation optimization scenario, and the OTA compilation optimization scenario is verify, and only dex is verified during the compilation process. It can be understood that the compilation resources of the verify-level compilation optimization scenario are small, and the preemption of device resources by dex2oat basically has no impact on device performance.
[0069] The compilation level of the idle compilation optimization scenario and the application installation compilation optimization scenario is speed-profile. During the compilation process, dex needs to be verified and the code listed in the profile is AOT compiled. Therefore, the compilation optimization scenario at the speed-profile level requires more compilation resources. With more compilation resources, dex2oat's preemption of device resources affects device performance.
[0070] Different compilation optimization scenarios have different triggering conditions. If the triggering condition is triggered at the first boot, the first boot compilation optimization scenario is started. If the triggering condition is triggered during the installation process, the application compilation optimization scenario is started. The relationship between the specific triggering conditions and the compilation optimization scenario is shown in Table 1.
[0071] In addition, different compilation optimization scenarios correspond to different application installation scenarios. For example, the application installation scenario corresponding to the first boot compilation optimization scenario is the first boot scenario. The application installation compilation optimization scenario corresponds to three different types of application scenarios, namely, application market installation / update installation within the application market, non-application market installation / update installation within the non-application market, and mobile phone cloning.
[0072] If the current environment of the electronic device meets the trigger conditions shown in Table 1, the compilation optimization scenario corresponding to the trigger conditions is automatically triggered. For example, when the current environment of the electronic device meets the installation process trigger, the application layer automatically triggers the application installation compilation optimization scenario.
[0073] It is worth noting that the embodiment of the present application pre-sets a trigger condition list and a compilation optimization scenario corresponding to the trigger condition list. When the current environment of the electronic device meets the trigger condition in the trigger condition list, the compilation optimization scenario corresponding to the trigger condition will be started.
[0074] It should be noted that the trigger conditions in the embodiment of the present application can be adjusted as needed.
[0075] S22: Determine whether the application is in the application installation compilation optimization scenario. If so, execute S23, otherwise execute S25.
[0076] According to whether the trigger condition is an installation process trigger condition, it is determined whether the application is in the application installation compilation optimization scenario. If the trigger condition is an installation process trigger condition, the application is in the installation compilation optimization scenario.
[0077] If the trigger condition is not a trigger condition during installation, the application is not in the application installation compilation optimization scenario. Exemplarily, if the trigger condition is an idle or charging trigger condition, the application is in the idle compilation optimization scenario.
[0078] S23: Determine whether the application installation scenario corresponding to the application installation compilation optimization scenario is application market installation or application market update. If so, execute S24; if not, execute S25.
[0079] When the application installation compilation optimization scenario corresponds to application installation including application market installation, application market update installation, non-application market installation, non-application market update installation and mobile phone cloning. When the application is installed by the application market or the application market update installation, the user needs to wait for the installation to complete before performing the operation, that is, the compilation resources of the dex2oat process need to be increased to improve the installation speed of the application.
[0080] When the application is installed outside the App Market, updated outside the App Market, or cloned on a mobile phone, the application installation is often running in the background, and the user does not need to wait for the installation to complete. In addition, since the application installation compilation optimization scenarios corresponding to the non-App Market installation, non-App Market update installation, and mobile phone clone occupy more device resources, the device performance may be affected, so it needs to be processed.
[0081] Optionally, whether an in-app market update has occurred can be determined by whether the package name of the application installed by the application running in the foreground is consistent with the package name of the application to be installed. If the package name of the application installed by the running application is consistent with the package name of the application to be installed, it is determined that an in-app update has occurred. If the package name of the application running in the foreground is the same as the package name of the application market, then the application market is the foreground.
[0082] In another optional implementation, the embodiment of the present application can determine whether it is an application market installation or an application market update installation through the scenario parameter passed during the compilation process. For example, when the scenario parameter passed during the compilation process is install-dm, the application installation scenario is an application market installation or an application market update installation.
[0083] Table 2 provides a table of the correspondence between scenario parameters and application installation
[0084]
[0085] S24: Add compilation resources for the dex2oat process.
[0086] Increasing the compilation resources of dex2oat means increasing the resource limit of the dex2oat process to increase the compilation speed of dex2oat. The embodiment of the present application can increase the compilation resources of dex2oat by releasing the super core or increasing the number of threads used in the compilation optimization execution.
[0087] A super-large core is a CPU with a main frequency of 2.8 GHz or above, and a CPU with a main frequency less than 2.8 GHz is a small or medium core. Compared with small or medium cores, super-large cores have stronger core execution capabilities. For example, an electronic device has an eight-core CPU, specifically CPU0 to CPU7, where CPU7 has a main frequency greater than 2.8 GHz and is a super-large core, and the main frequencies of the other cores are less than 2.8 GHz and are small or medium cores.
[0088] Releasing the super-large core means executing part or all of the compiled optimization on the super-large core, taking advantage of the super-large core's stronger core execution capability to increase the installation speed of the application.
[0089] Increasing the number of threads used when executing compilation optimization means increasing the thread parameter passed to dex2oat, for example, from 1 to 4. A thread parameter of 1 means that 1 thread is involved in compilation optimization, and a thread parameter of 4 means that 4 threads are involved in compilation optimization. In this way, by increasing the number of threads, the application installation speed is increased, thereby reducing the waiting time for users.
[0090] S25: Determine whether the application currently running in the foreground is an application in the preset important application set, or determine whether the application scenario currently running in the foreground is a scenario in the important application scenario set. If yes, execute S26, otherwise, execute S27.
[0091] The applications in the preset important application set include games, short video platforms, video players and other applications that affect the user experience. The scenarios in the important application scenario set include video calls, sliding operations within the application and other scenarios that affect the user experience.
[0092] In the embodiment of the present application, the applications in the important application set are applications pre-added by the user and have an impact on the user experience. The scenarios in the important application scenario set are scenarios pre-added by the user and have an impact on the user experience.
[0093] For example, based on past experience, users store applications that may experience lag in the running interface, such as games and short video platforms, in a preset set of important applications. Based on past experience, users store applications that may experience lag in the running interface, such as video calls or sliding operations within the application, in a preset set of important application scenarios.
[0094] In the embodiments of the present application, a plurality of methods can be used to determine whether the application currently running in the foreground is an application in a preset important application set, or to determine whether the application scenario currently running in the foreground is a scenario in the important application scenario set.
[0095] Example 1: When the application is in the foreground, it will be at the top of the Running Task stack. Take out the top task process of the current application's Running Task stack and determine whether the application corresponding to the application package name is an application in the important application set.
[0096] In addition, it is also possible to determine whether the application installation is an application running in the foreground through the Running Process, or to determine through the Android accessibility function.
[0097] Example 2: Identify an application or scene in the application list of a preset important application set as "important". If a running application or a running scene is identified as "important", the running application is an application in the preset important application set, or the running scene is a scene in the important application scene set.
[0098] If the application running in the foreground is an application in the important application set, or the application scenario running in the foreground is a scenario in the important application scenario set, it is necessary to reduce the compilation resources during application installation and increase the CPU resources occupied by the application running in the foreground to avoid lag in the application running in the foreground.
[0099] S26: Reduce compilation resources of the dex2oat process.
[0100] Reducing the compilation resources of dex2oat means reducing the resource limit of the dex2oat process, so that the compilation speed of dex2oat is increased. The embodiment of the present application can reduce the current compilation resources by limiting the compilation optimization to small and medium cores, so that dex2oat runs in small and medium cores, and reducing the resource limit of the dex2oat process.
[0101] Compared with super-large cores, small and medium cores have low core execution efficiency. The embodiment of the present application limits compilation optimization to small and medium cores, and uses the low execution efficiency of small and medium cores to reduce the occupied CPU resources and avoid affecting the CPU resources occupied by the application running in the foreground, thereby avoiding the running application from freezing.
[0102] S27: Do not adjust the compilation resources of the dex2oat process.
[0103] Execute dex2oat using the compiled resources of the pre-set dex2oat process.
[0104] Furthermore, when the display interface of the electronic device is in the off-screen display, and the off-screen display duration is greater than the second preset duration, it indicates that the user does not need to wait for the installation of the application to be completed. At this time, there is no need to adjust the dex2oat compilation resources. Therefore, firstly determine whether the screen is off and then make subsequent judgments to improve the resource allocation processing efficiency of compilation optimization.
[0105] Furthermore, the compilation level of the idle compilation optimization scenario and the application installation compilation optimization scenario is speed-profile. Dex needs to be verified during the compilation process, and the AOT compilation of the code listed in the profile requires more compilation resources. Since there are many compilation resources, the preemption of device resources by dex2oat will affect the performance of the device. Therefore, the embodiment of the present application first determines whether the triggering compilation optimization scenario is the target compilation optimization scenario. If so, the compilation resource allocation adjustment is performed. The target compilation optimization scenario includes one of the idle compilation optimization scenario and the application installation compilation optimization scenario.
[0106] Furthermore, during the compilation and optimization process of dex2oat, scene switching is often encountered, such as the application installation switches from foreground operation to background operation, or from background operation to foreground operation, or the application installation switches from foreground operation to background operation, and the application running in the foreground is an application in the preset important application set, or a scene in the important application scene set, etc. Different scenes have different requirements for compilation resources, and compilation resources can be adjusted according to the detection results, such as CPUset value, or frozen threads, etc.
[0107] Determine whether the application running in the foreground is an application in the preset important application set, or whether the application scenario running in the foreground is a scenario in the important application scenario set. When the application running in the foreground is an application in the preset important application set, or the application scenario running in the foreground is a scenario in the important application scenario set, reduce the compilation resources of the dex2oat process. In this way, the preemption of device resources by the dex2oat process is reduced, thereby avoiding the impact of application installation on device performance, causing the application running in the foreground to freeze, and improving the user experience.
[0108] For ease of understanding, the following describes 3 to 4 examples with reference to the accompanying drawings. Fig. 9 A compilation optimized resource allocation method provided by the present application is introduced.
[0109] See also Figure 3 , is a schematic diagram of an application scenario of a resource allocation method for compilation optimization provided in an embodiment of the present application.
[0110] Figure 3 (a) in the figure is the process in which a user clicks on the application market and enters the application market interface. Figure 3(b) in the figure indicates that the application market is running in the foreground. At this time, select the application you want to download and install it, such as the game application installation in the figure. Figure 3 (c) in the figure shows that the user clicks the "Download" control and the download is 100%, that is, after the download is completed, a prompt box is displayed to prompt whether to execute the application installation. The user clicks "Yes" and the application installation enters the installation process. At this time, the display interface shows the application installation progress, such as Figure 4 As shown in (d) in the figure, the user waits for the application to be installed. In order to improve the user experience and reduce the waiting time of the user, more compilation resources need to be allocated for compilation optimization.
[0111] See also Figure 4 , which is a schematic diagram of an application scenario of another compilation-optimized resource allocation method provided in an embodiment of the present application.
[0112] Figure 4 (a) in the figure shows the system version update interface, which displays a system version update detected and prompts whether to update the version. The user clicks "Yes" to enter Figure 4 In the prompt box (b) of the figure, the user clicks "Yes" to enter the silent installation prompt box. Figure 4 The silent installation process shown in (c) in FIG. 1 is shown in FIG. 1 . At this time, the user opens other applications, such as short video applications, game applications, etc. Figure 4 As shown in (d) in the figure, interface freezes frequently occur.
[0113] Figure 5 It is a software structure block diagram of the electronic device according to an embodiment of the present invention.
[0114] Relative to Figure 1 In the electronic device shown, the application framework layer may include an added usage scenario judgment module, a resource configuration module, a scene switching module, etc.
[0115] The usage scenario judgment module is used to respond to the compilation task compilation initiated by the compilation initiation module and determine the usage environment of the current application installation, such as the foreground application installation, or the background application installation, and the foreground application such as TikTok, games, etc. If the usage environment of the current application installation meets the resource configuration conditions, a resource configuration instruction is initiated to the resource configuration module.
[0116] The resource configuration module is used to return resource configuration information according to the resource configuration instruction, so that the compilation optimization module performs the dex2oat process according to the resource configuration information.
[0117] The scene switching module is used to monitor whether the current scene of application installation changes, such as whether the application installation switches from the foreground to the background, or from the background to the foreground.
[0118] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0119] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0120] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0121] The system library can include multiple functional modules, such as compilation optimization module, dynamic resource configuration module, etc.
[0122] Compile optimization modules for dex2oat threads.
[0123] The dynamic resource configuration module is used to dynamically modify the compilation resources of the dex2oat process.
[0124] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0125] Below and above Figure 5 As an example, the electronic device shown in the figure is used as an example, and the compilation optimization scenario is used as an example to install the compilation optimization scenario. Figure 6 This is an interactive diagram of a compilation optimization resource allocation method provided in an embodiment of the present application, which introduces in detail the compilation optimization resource allocation method provided in an embodiment of the present application, wherein the compilation optimization resource allocation method is also applicable to idle compilation optimization scenarios, etc.
[0126] Adjust resources before compiling:
[0127] S601: The application installation compilation optimization application is started, and an installation compilation trigger instruction is sent to the compilation initiation module.
[0128] When the current trigger conditions obtained are: charging, power>60%, and application installation is interrupted when the screen is on, or idle for 31 minutes, charging and the charging power is greater than 95%, the compilation optimization scenario is the idle compilation optimization scenario.
[0129] When the current trigger condition is triggered during installation, the compilation optimization scenario is an application installation compilation optimization scenario, and the application installation compilation optimization application at the application layer is started. The application installation application sends an installation compilation trigger instruction to the compilation initiation module.
[0130] The application installation application is used to represent the application corresponding to the installation compilation optimization scenario and is located in the application layer.
[0131] The installation compilation trigger instruction is used to trigger the compilation initiation module to initiate the compilation task compilation corresponding to the installation compilation optimization scenario. Optionally, the installation compilation trigger instruction has a unique identifier, which is used to uniquely indicate that the installation compilation trigger instruction is optimized by the installation compilation.
[0132] S602: The compilation initiating module initiates the installation compilation task compilation to the usage scenario determining module.
[0133] The compilation initiation module receives the installation compilation trigger instruction sent by the application installation application program, and initiates the installation compilation task compilation to the usage scenario judgment module.
[0134] S603: Use the scene determination module to determine whether the display interface is off-screen display, and whether the off-screen display duration is greater than a second preset duration. If so, execute S611, otherwise execute S603.
[0135] After receiving the installation compilation task compilation, the usage scenario judgment module determines whether the display interface is off-screen display.
[0136] The display interface of the electronic device can be displayed with the screen on or off.
[0137] If the display interface of the electronic device is always on, it indicates that the user may need to wait for the installation of the application to be completed, or may require the smoothness of the display of the graphic display interface of the application running in the foreground.
[0138] Example description: If the application running in the foreground is a short video platform, game or other application, the display interface is a bright screen display. At this time, if the compilation optimization of the application installation is executed in the background, if the CPU resources occupied by the background are greater than the preset CPU resource threshold, it will cause the application running in the foreground to freeze.
[0139] Exemplary description: If an application is being installed in the foreground, the electronic device is in a screen-on state, and the user is waiting for the application to be installed, in order to ensure the user experience, the installation time of the application needs to be increased.
[0140] If the electronic device is in the off-screen display state, and the off-screen display duration is longer than the second preset duration, it indicates that the user does not need to wait for the application to be installed, so there is no need to adjust the compilation resources of the dex2oat process. For example, if the second preset duration is 2 minutes, and the electronic device is in the off-screen display state for longer than 2 minutes, there is no need to adjust the compilation resources of the dex2oat process.
[0141] Electronic devices may also turn off the screen in other emergencies, such as when the user clicks the screen-off button. At this time, the user still needs to wait for the installation of the application to be completed. Therefore, the compilation resources of the dex2oat process need to be adjusted.
[0142] It is worth noting that the second preset duration described in the embodiment of the present application is a duration that can be set by the technicians in this field according to the needs.
[0143] S604: Use the scenario judgment module to judge whether the application installation corresponding to the application installation compilation optimization scenario is running in the foreground and the running time is greater than the first preset time. If so, execute S605, otherwise execute S608.
[0144] When the electronic device determines that the application is installed and running in the foreground, and the running time is greater than the first preset time, it means that the user waits for the application installation to complete before performing other operations. Therefore, in order to improve the user experience, it is necessary to increase the compilation resources of the dex2oat process and reduce the installation time of the application installation.
[0145] Furthermore, when the application installed in the electronic device is an application running in the foreground in the first sub-time period, an application running in the background in the second sub-time period, and an application running in the foreground in the third sub-time period, or an application running in the background in both the second sub-time period and the third sub-time period. At this time, the user does not need to wait for the application installation to complete before performing other operations. Therefore, the electronic device can reduce the compilation resources of the dex2oat process, or may not change the compilation resources of the dex2oat process.
[0146] The first preset time length is a time period set by the user according to needs, including a first time period, a second time period and a third time period.
[0147] When the application installed by the electronic device is always running in the background, or the time it runs in the foreground is not greater than the first preset time, it indicates that the user does not need to wait for the application installation to be completed before performing other operations. Therefore, the electronic device can reduce the compilation resources of the dex2oat process, or may not change the compilation resources of the dex2oat process.
[0148] S605: Use the scenario judgment module to judge whether the application installation corresponding to the application installation compilation optimization scenario is an application market installation or an update installation in the application market. If so, execute S606; otherwise, execute S608.
[0149] S606: Using the scenario determination module, the first resource configuration instruction is sent to the resource configuration module.
[0150] The scenario judgment module is used to determine that the application installation compilation optimization scenario is application market installation, or update installation in the application market, and initiate a first resource configuration instruction to the resource configuration module.
[0151] The first resource configuration instruction includes compiling parameters for adding compiling resources of the dex2oat process, that is, compiling configuration information.
[0152] S607: The resource configuration module adds compilation resources for the dex2oat process and executes S613.
[0153] Assume that an electronic device has 8 CPU cores, namely CP0, CPU1, CPU2, CPU3, CPU4, CPU5, CPU6 and CPU7. Among them, CPU7 is a super large core, and the other CPU0 to CPU6 are small and medium cores.
[0154] For example, see Figure 7 A schematic diagram of releasing a super-large core provided in an embodiment of the present application is provided. Figure 7 When (a) is not adjusted, the compilation optimization is performed on CPU5. Figure 7 (b) is a schematic diagram of the compilation optimization being executed on the super-core CPU7 after the super-core is released.
[0155] S608: Use the scene determination module to determine whether the application currently running in the foreground is the first application and whether the currently running scene is the first scene. If yes, execute S609; if not, execute S611.
[0156] The first application is an application in the important application set.
[0157] The first scenario is a scenario in the important application scenario set.
[0158] S609: Using the scenario determination module, the second resource configuration instruction is sent to the resource configuration module.
[0159] When the scene judgment module is used to determine that the application running in the foreground is an application in the preset important application set, or the running scene is a scene in the important application scene set, a second resource configuration instruction is sent to the resource configuration sending module.
[0160] The second resource configuration instruction includes a compilation parameter for reducing compilation resources.
[0161] S610: The resource configuration module reduces the compilation resources of dex2oat and executes S613.
[0162] Assume that an electronic device has 8 CPU cores, namely CP0, CPU1, CPU2, CPU3, CPU4, CPU5, CPU6 and CPU7. Among them, CPU7 is a super large core, and the other CPU0 to CPU6 are small and medium cores.
[0163] join Figure 8 , a schematic diagram of reducing the compilation resources of dex2oat, Figure 8 (a) in the figure is the resource online of the dex2oat process when this application is not adjusted. At this time, dex2oat is executed on the super-core CPU7. Figure 8 (b) in the figure shows the compiled resources of dex2oat, and the compilation optimization is performed on the small and medium core CPU5.
[0164] S611: Using the scenario determination module, a third resource configuration instruction is sent to the resource configuration module.
[0165] S612: The resource configuration module does not adjust the compilation resources of the dex2oat process.
[0166] S613: The resource configuration module returns the compilation resources to the compilation initiation module.
[0167] The compilation resources configured by the resource configuration module are returned to the compilation initiation module, and the compilation initiation module initiates compilation, so that the compilation optimization module performs dex2oat compilation.
[0168] Additionally, during compilation:
[0169] Step A: The scene switching detection module identifies the scene switching of the application running in the foreground, and sends the scene switching content to the dynamic resource configuration module.
[0170] During the compilation process, the scene switching content refers to the two situations in which the application installation switches from the foreground to the background, or from the background to the foreground.
[0171] The embodiment of the present application can identify whether the application scenario running in the foreground is switched in the following manner.
[0172] Step 1: The electronic device recognizes that the application scene running in the foreground is switched and determines the scene switching content.
[0173] The scene switching content is that the application installation switches from foreground running to background running, or from background running to foreground running.
[0174] Step 2: Adjust the CPU set value according to the switching content, or adjust the number of threads used during compilation optimization execution.
[0175] If the switching content is that the application installation is switched from the foreground to the background, adjust the CPU set value to the CPU set value corresponding to the small and medium cores, or reduce the number of threads used. If the switching content is that the application installation is switched from the background to the foreground, adjust the CPU set value to the CPU set value corresponding to the super large core, or increase the number of threads used during compilation optimization execution.
[0176] Step B: The dynamic resource configuration module adjusts the CPU set value or freezes the thread.
[0177] The dynamic resource configuration module receives the switching content sent by the scene switching module, adjusts the CPU set value, or adjusts the number of threads used when the compilation optimization is executed, so that the compilation resources of the compilation optimization can optimize the user experience in the current scene.
[0178] Optionally, in addition to compiling all threads, add a thread pool and correct the cpu set value in the ongoing dex2oat process by calling the SetCpuAffinity interface.
[0179] Example description: See Fig. 9 , which is a schematic diagram of adjusting the CPU set value provided in an embodiment of the present application. At t0, when the application is installed as an application running in the foreground, the CPU set value in the dex2oat process is the super-large core CPU7. At t1, the electronic device recognizes the application scene switching of the application running in the foreground, that is, the application is installed from the application running in the foreground to the application running in the background, and the CPU set value in the dex2oat process is corrected to the small and medium cores CPU0, CPU1 and CPU2. At t2, the electronic device once again recognizes the application scene switching of the application running in the foreground. At this time, the application installation is switched from the application running in the background to the application running in the foreground. At this time, the CPU set value in the dex2oat process is corrected to the small and medium cores CPU4, CPU5 and CPU6.
[0180] Optionally, the dynamic resource configuration module can change the number of threads used when compiling and optimizing execution. If the application installation switches from the foreground to the background, reduce the number of threads used to avoid CPU resources occupied by the background application installation causing other foreground applications to freeze. If the application installation switches from the background to the foreground, increase the number of threads used to increase the installation speed and avoid waiting time.
[0181] The dynamic resource configuration module adjusts the CPU set value, or the frozen thread sends the resource configuration to the compilation optimization module to perform compilation optimization.
[0182] The electronic device to which the compiled optimized resource allocation method provided in the embodiment of the present application is applied can be a mobile phone that executes the application installation function, a laptop computer, a wearable electronic device (such as a smart watch), a tablet computer, an augmented reality (AR) device, a virtual reality (VR) device, and a vehicle-mounted device, etc.
[0183] See also Fig.10 , which is a schematic diagram of the structure of an electronic device.
[0184] The electronic device may include a processor 110, an internal memory 121, a power management module 141, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, a touch sensor 180K, a button 190, an indicator 192, a display screen 194, etc.
[0185] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0186] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0187] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0188] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0189] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, etc.
[0190] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0191] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0192] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0193] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0194] The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the internal memory 121, and / or instructions stored in a memory provided in the processor.
[0195] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass 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 the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0196] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0197] The software system of the electronic device may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device.
[0198] The technical solution of this embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment. The aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, magnetic disk or optical disk, etc., various media that can store program codes.
[0199] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A resource allocation method for compilation optimization, characterized in that: The method comprises: Determine whether the application currently running in the foreground is an application in an important application set, where the important application set is a collection of important applications pre-stored in the electronic device; If so, reduce the compilation resources allocated to compilation optimization; If not, determine whether the application scenario running in the foreground is a scenario in the important application scenario set. When it is determined that the application scenario running in the foreground is a scenario in the important application scenario set, reduce the compilation resources allocated to the compilation optimization; the important application scenario set is a collection of important application scenarios pre-stored in the electronic device.
2. The method according to claim 1, characterized in that: The determining whether the application currently running in the foreground is an application in the important application set includes: Determine whether the application is in the application installation compilation optimization scenario; If not, determine whether the application currently running in the foreground is an application in the important application set.
3. The method according to claim 2, characterized in that: The method further comprises: If so, determine whether the application installation corresponding to the application installation compilation optimization scenario belongs to the application market installation, or the update in the application market; If the application installation is not an installation in the application market and is not an update in the application market, it is determined whether the application currently running in the foreground is an application in the important application set.
4. The method according to claim 1, characterized in that: The method further comprises: If the application installation is installed in the application market, or is updated in the application market, the compilation resources allocated to the compilation optimization are increased.
5. The method according to claim 4, characterized in that: The increasing of compilation resources allocated to compilation optimization includes: Allocate to the compilation optimization super core, and / or increase the number of threads used when executing the compilation optimization.
6. The method according to any one of claims 2 to 5, characterized in that: The determining whether the application is in the application installation compilation optimization scenario includes: When the display interface is displayed on a bright screen, it is determined whether the application is in the application installation compilation optimization scenario.
7. The method according to claim 6, characterized in that: The method further comprises: When the display interface is in an off-screen display and the off-screen display duration is greater than a second preset duration, the compilation resources allocated to the compilation optimization are not adjusted.
8. The method according to any one of claims 2 to 7, characterized in that: The determining whether the application is in the application installation compilation optimization scenario includes: In response to receiving a current trigger condition, determining whether the current trigger condition is an installation process trigger condition; If so, determining that the application is in the application installation compilation optimization scenario; If not, it is determined that the application is not in the application installation compilation optimization scenario.
9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: In response to identifying a scene switch of an application running in the foreground during the compilation and optimization process, obtaining scene switch content, the scene switch content including that the application installation compilation and optimization scene is switched from the foreground running to the background running, or from the background running to the foreground running; According to the scene switching content, the compilation resources in the ongoing compilation optimization process are modified.
10. The method according to any one of claims 1 to 9, characterized in that: The reducing the compilation resources allocated to the compilation optimization includes: The compilation optimization is limited to execution in small and medium cores.
11. The method according to any one of claims 1 to 10, characterized in that: The applications in the important application set include: short video platform applications, instant messaging applications, and video players.
12. The method according to any one of claims 1 to 11, characterized in that: The scenarios in the important application scenario set include: video call scenario and in-application sliding scenario.
13. An electronic device, characterized in that: The electronic device comprises a memory and a processor, wherein the memory is coupled to the processor; The memory stores a program, and when the program is executed by the processor, the electronic device executes the method according to any one of claims 1 to 12.