[go: up one dir, main page]

CN116932078A - Plug-in first cold start optimization method and device - Google Patents

Plug-in first cold start optimization method and device Download PDF

Info

Publication number
CN116932078A
CN116932078A CN202310882480.8A CN202310882480A CN116932078A CN 116932078 A CN116932078 A CN 116932078A CN 202310882480 A CN202310882480 A CN 202310882480A CN 116932078 A CN116932078 A CN 116932078A
Authority
CN
China
Prior art keywords
plug
dex file
loading
mode
dex
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310882480.8A
Other languages
Chinese (zh)
Inventor
陈碧锋
刘广宾
赵文娴
李尧彦
邓晓天
柏平平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hunan MgtvCom Interactive Entertainment Media Co Ltd
Original Assignee
Hunan MgtvCom Interactive Entertainment Media Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hunan MgtvCom Interactive Entertainment Media Co Ltd filed Critical Hunan MgtvCom Interactive Entertainment Media Co Ltd
Priority to CN202310882480.8A priority Critical patent/CN116932078A/en
Publication of CN116932078A publication Critical patent/CN116932078A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application discloses a first cold start optimization method and device for plug-ins, comprising the following steps: responding to the first cold start of a plug-in of an application program, and obtaining a byte code dex file corresponding to the plug-in; determining whether a compiled file corresponding to the dex file exists or not, and if not, obtaining version information of a current operating system; determining a target mode for loading the dex file based on version information of a current operating system; loading a dex file based on a target mode to realize the starting of the plug-in; each target mode is a mode of skipping a dex file compiler and directly loading the dex file. According to the method and the device, by skipping compiling, the virtual machine directly uses the dex file to run, so that the first starting acceleration is achieved, and the user experience effect is improved.

Description

Plug-in first cold start optimization method and device
Technical Field
The application relates to the technical field of computers, in particular to a first cold start optimization method and device for plug-ins.
Background
Android (Android) systems are virtual machine-based operating systems, and the development of virtual machines has undergone a process from Dalvik to ART. Taking an Android intelligent device as an example, in order to meet various requirements, an APK (Android Package) as a main application program may be installed in a system platform, and when certain functions are required, the program installed in the system platform may be opened to implement the certain functions. In order to enable APKs to run on all virtual machines without modification, the virtual machines may be enabled to more efficiently execute various APKs by optimizing Dex (byte code) before running the virtual machines. The Dex optimization optimizes the byte code of the Dex file into a machine code which can be directly recognized by a machine (the machine code refers to a serial number formed by encrypting and hashing a hardware serial number), and the Dex loading speed and the code running speed are improved, so that the running speed and the smoothness in the application and use processes are improved.
However, a plug-in is long from the plug-in resource file to the completion of the plug-in startup, and especially, the first startup of the plug-in can take a long time, resulting in poor user experience.
Disclosure of Invention
Aiming at the problems, the application provides a first cold start optimization method and device for plug-ins, which can effectively reduce the time consumption required by the process of first starting the plug-ins and improve the user experience effect.
In order to achieve the above object, the present application provides the following technical solutions:
a method for optimizing a first cold start of a plug-in, the method comprising:
responding to the first cold start of a plug-in of an application program, and obtaining a byte code dex file corresponding to the plug-in;
determining whether a compiled file corresponding to the dex file exists or not, and if not, obtaining version information of a current operating system;
determining a target mode for loading the dex file based on the version information of the current operating system;
loading the dex file based on the target mode to realize the starting of the plug-in;
each target mode is a mode of skipping the dex file compiling program and directly loading the dex file.
Optionally, the method further comprises:
and if the compiled file corresponding to the dex file exists, loading the compiled file to start the plug-in.
Optionally, the determining, based on the version information of the current operating system, a target manner of loading the dex file includes:
if the version number corresponding to the version information of the current operating system is smaller than a first threshold, determining that the dex file is loaded as a first mode, wherein the first mode represents a mode of loading the dex file through an array corresponding to the content of the dex file;
the loading the dex file based on the target mode to realize the starting of the plug-in includes:
acquiring byte codes of an original dex file from an installation package of the plug-in;
loading the byte code to generate the dex file;
and adding the dex file into a loader for loading the dex file through reflection, and operating the dex file to realize the starting of the plug-in.
Optionally, the determining, based on the version information of the current operating system, a target manner of loading the dex file includes:
if the version number corresponding to the version information of the current operating system is larger than a first threshold and smaller than a second threshold, determining that the dex file is loaded in a second mode, wherein the second mode represents a compiling product path which is not available through transmission, so that a compiling program of the dex file is skipped in a compiling failure mode.
Optionally, the determining, based on the version information of the current operating system, a target manner of loading the dex file includes:
if the version number corresponding to the version information of the current operating system is larger than a second threshold, determining that the dex file is loaded as a third mode, wherein the third mode represents that a compiling program of the dex file is skipped through the dex loading mode in a memory.
Optionally, the method further comprises:
in response to the plug-in being started, controlling a subprocess to trigger a compiler to compile the dex file to obtain a compiled file;
and storing the digital abstract code corresponding to the dex file and the storage path of the compiling file.
Optionally, the method further comprises:
and responding to the starting of a host application program for loading the plug-in, and determining a target loading mode corresponding to the plug-in, so that the plug-in is loaded based on the target loading mode to finish the starting of the plug-in.
Optionally, the determining, in response to the starting of the host application program for loading the plugin, a target loading mode corresponding to the plugin includes:
generating a plug-in information table according to the service type of the plug-in and the characteristic information of the plug-in;
traversing the plug-in information table to determine whether the plug-in is of a preloading type;
if yes, responding to the completion of downloading the plug-in, executing a plug-in loading mode matched with the preloading type, and triggering a compiling program to compile the dex file to obtain a compiling file;
if the plug-in is not of a pre-loading type, determining whether the plug-in is started for the first time and loads the dex file in a target mode, and recording the target mode of loading the dex file corresponding to the plug-in;
and if the plug-in does not specify the starting type, executing a default loading mode on the plug-in.
A plug-in first cold start optimization device, the device comprising:
the obtaining unit is used for responding to the first cold start of the plug-in of the application program and obtaining a byte code dex file corresponding to the plug-in;
a first determining unit, configured to determine whether a compiled file corresponding to the dex file exists, and if not, obtain version information of a current operating system;
the second determining unit is used for determining a target mode for loading the dex file based on the version information of the current operating system;
the loading unit is used for loading the dex file based on the target mode to realize the starting of the plug-in;
each target mode is a mode of skipping the dex file compiling program and directly loading the dex file.
An electronic device, comprising:
a memory for storing a program;
and the processor is used for executing the program, and the program is particularly used for realizing the plug-in first cold start optimization method according to any one of the above.
Compared with the prior art, the application provides a first cold start optimization method and device for plug-ins, comprising the following steps: responding to the first cold start of a plug-in of an application program, and obtaining a byte code dex file corresponding to the plug-in; determining whether a compiled file corresponding to the dex file exists or not, and if not, obtaining version information of a current operating system; determining a target mode for loading the dex file based on version information of a current operating system; loading a dex file based on a target mode to realize the starting of the plug-in; each target mode is a mode of skipping a dex file compiler and directly loading the dex file. According to the method and the device, by skipping compiling, the virtual machine directly uses the dex file to run, so that the first starting acceleration is achieved, and the user experience effect is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present application, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of a preferred method for first cold start of an add-in according to an embodiment of the present application;
FIG. 2 is a flowchart illustrating a method for loading plug-ins based on different operating system versions according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a process flow of a plurality of boot loading modes of a plug-in unit according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a preferred device for first cold start of an insert according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms first and second and the like in the description and in the claims and in the above-described figures are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order. Furthermore, the terms "comprise" and "have," as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to the listed steps or elements but may include steps or elements not expressly listed.
For convenience in describing embodiments of the present application, description will be made of related terms applied in the embodiments of the present application.
DexClassLoader: android is a dex entity used to load jar and apk. But also to run non-installed program code as part of the application. This class requires a file directory of program private rights to store optimized class files at the loader.
dex2oat: the method is a program for compiling and optimizing the dex file by a pointer, and improves the dex loading speed and the code running speed by performing a series of operations such as instruction optimization and compiling machine codes on the dex, so that the running speed and the smoothness in the application use process are improved, and finally the daily use experience of a user is improved.
InMemoryDexClassLoader: the new InMemoryDexClassLoader is added after android8.0, the general flow is almost similar to that of the DexClassLoader, and the main difference is that an oat file is not generated in the InMemoryDexClassLoader process.
The plugin technology stems from the need to install-free running apks, which can be understood as plugins. The plug-in apk comprises one or more dex files, res resource files, assert, android file xml, signature and other files like the apk which is normally required to be installed, except that the plug-in apk is generally installed and started by a user and then downloaded and loaded from the cloud for operation, and the loading operation stage can be operated without installation. The loading operation of the plug-in is that the dex file in the plug-in is loaded and operated through the DexClassLoader provided by the Android.
The dex2oat is a program for compiling and optimizing the dex file by a pointer, and the dex loading speed and the code running speed are improved by performing a series of operations such as instruction optimization and compiling machine code on the dex, so that the running speed and the smoothness in the application using process are improved, and the daily use experience of a user is finally improved.
Android 5.0: anroind runs apk using Dalvik virtual machine, it optimizes the file before loading the run execution dex file, generating executable file odex, dex2ota, which can take a long time. After Android5.0, loading and running a dex file in a plugin apk on the Art virtual machine, and performing dex2oat operation on the plugin dex file by an application triggering system.
The plug-in apk of the complex service may include N Dex files (class. Dex, class2. Dex-class N. Dex), where class. Dex is called primary Dex, class2. Dex-class N. Dex is collectively called Secondary Dex, a scenario of multiple Dex is applied to first load operation, in order to ensure normal operation, the application needs to perform a multiple Dex instrument operation, which is mainly two steps:
decompression & compression: decompressing the dex except the main dex in the apk, and compressing the dex into a zip format;
reflection filling: and loading the dex except the main dex, and filling the loaded content into the original ClassLoader in a reflection mode. And the loading of the plug-in dex file basically triggers dex2oat from android4.0 to android9.0 to generate the dex file for the next direct loading operation. This process may be time consuming, so the multiple dex plug-in apk may be time consuming when it is first loaded to run, or after an upgrade (again, a new dex file) is first loaded to run. When the load run open plug-in is in the main process, ANR (application overrun unresponsive error) is prone to occur on poorly performing devices.
Therefore, in the method for optimizing the first cold start of the plugin, in the scheme of plugin application based on the Android operating system, the plugin apk of the multi-dex file is directly started by the dex file, the dex2oat process is skipped over from the system to the dex file in the starting process, the time consumption required by the first starting process is effectively reduced, the effect of optimizing the starting is achieved, the ANR rate of the plugin apk for the first time loaded and operated on equipment is reduced, user experience is improved, loss of users is reduced, and the application retention rate of the plugin is improved; meanwhile, the capability of remote modification of the first loading operation of the plug-in apk is provided, diversified first loading operation modes of the plug-in are provided, different devices and different types of plug-in apks can be selected according to own conditions, and therefore flexibility of plug-in apk application is improved.
Referring to fig. 1, a flow diagram of a first cold start optimization method for a plug-in unit according to an embodiment of the present application may include the following steps:
s101, responding to the first cold start of a plug-in of an application program, and obtaining a byte code dex file corresponding to the plug-in.
S102, determining whether a compiled file corresponding to the dex file exists, and if not, executing step S103.
S103, obtaining version information of the current operating system.
S104, determining a target mode for loading the dex file based on version information of the current operating system.
S105, loading a dex file based on a target mode, and starting the plug-in.
Each target mode is a mode of skipping the dex file compiling program and directly loading the dex file. In the embodiment of the application, the dex file compiler is skipped to skip the dex2oat stage. The version information of the current operating system mainly refers to the version corresponding to the operating system when the operating system is an Android system. There are two types of Android load virtual machines that execute dex files, one is Dalvik, which is mainly used in Android4.4 and previous devices. One is the Art virtual machine, which is used primarily on android5.0 devices. Since the virtual machines loading the dex file are different, selection is required according to the version. In addition, on Android 5-9 of the large version of the Android system, the loading and execution dex strategy of the virtual machine is modified somewhat, so that adaptation is required for each large version to achieve a consistent effect.
At the first start, if there is no compiled file corresponding to the dex file, the processing may be performed in other ways to skip the compiled program, but if there is a compiled file, the compiled file may be directly loaded to realize the start of the plug-in. Based on each target mode of loading dex files, plug-ins in different modes can be started quickly for the first time. The method specifically comprises the following steps: the plug-in can directly run through the dex file, skip the dex2oat stage and finish plug-in starting and accelerating; the method can also be a background silent preloading operation plug-in, so that the aim of speeding up in use is fulfilled, namely, after the host program is started, the plug-in apk is silently downloaded, the operation plug-in apk is normally loaded, the dex file is preloaded in advance, the compiling process is triggered in advance, a compiling product (dex file) is generated, and when the plug-in is used by a user next time, the plug-in is started to run by directly using the compiling product, so that the time consumption for starting the plug-in is reduced. The method can also be implemented by directly loading and running without performing preloading and using dex, and the plug-in is loaded for the first time in a common mode, and it is noted that the background preloading consumes the memory of the app in the mode, if the user does not need to use the function, the preloading also occupies the user to store in advance, and based on the condition, some small plug-ins apk can be used in the loading mode on the device with relatively high performance under the condition that the dex file is not large.
The following describes a target manner of loading the dex file when the operating system is in different versions. Referring to fig. 2, when a plug-in is operated by using a dex file for the first time, firstly searching whether a compiled file (odex file) exists according to the dex file in the plug-in, and if so, loading the odex file to operate the plug-in apk; if not, the subsequent processing is performed based on the version of the operating system.
If the version number corresponding to the version information of the current operating system is smaller than a first threshold, determining that the dex file is loaded as a first mode, wherein the first mode represents a mode of loading the dex file through an array corresponding to the content of the dex file; the loading the dex file based on the target mode to realize the starting of the plug-in includes: acquiring byte codes of an original dex file from an installation package of the plug-in; loading the byte code to generate the dex file; and adding the dex file into a loader for loading the dex file through reflection, and operating the dex file to realize the starting of the plug-in. If the version number corresponding to the version information of the current operating system is larger than a first threshold and smaller than a second threshold, determining that the dex file is loaded in a second mode, wherein the second mode represents a compiling product path which is not available through transmission, so that a compiling program of the dex file is skipped in a compiling failure mode. If the version number corresponding to the version information of the current operating system is larger than a second threshold, determining that the dex file is loaded as a third mode, wherein the third mode represents that a compiling program of the dex file is skipped through the dex loading mode in a memory.
For example, when the operating system is an Android operating system, the first threshold may be Android4.4, the second threshold may be Android7, at this time, the operating system version corresponding to the first mode is smaller than Android4.4, the operating system version corresponding to the second mode is Android5 to Android7, and the operating system version corresponding to the third mode is Android8 to Android9. When the version of the operating system is smaller than android4.4, the DEX content can be taken as a byte array, then the DEX is loaded by using the byte array, and specifically, the byte code of the original second DEX file is obtained from the plug-in APK in a decompression mode; the original DEX byte codes can be directly loaded by adopting the existing api, openDexFile_byte function in the source codes on the 4.X system to generate a DexFile file, and skipping over the DEX2oat; the DexFile file object is added into a DexClassLoader of the loading plug-in through reflection, so that the second dex is implemented to run as a dex file; and the plug-in apk is loaded by a single subprocess, and the dex2oat is triggered to generate the odex file, so that the plug-in is conveniently loaded for use next time.
When the operating system is Android5 to Android7, when a DexClassLoader is created, an input unusable compiling product path is needed, namely new DexClassLoader (String dexPath, string optimizedDirectory, string librarySearchPath, classLoaderparent), and the input optimizedDirector is an unusable path, so that compiling is failed, a fallback flow of the virtual machine is carried out, and therefore, dex2Oat on Android5 to 7 is skipped.
When the operating system is Android8 to Android9, inMemoryClassLoader newly added by Android is used on Android 8.x to Android9 to replace DexClassLoader to load a dex file, and because InMemoryClassLoader is a special mode for loading dex in a memory, compiling of dex2oat is not triggered, and a compiling scheme of the dex2oat can be skipped on the Android8 to Android9 by the method.
The embodiment of the application further comprises the following steps: in response to the plug-in being started, controlling a subprocess to trigger a compiler to compile the dex file to obtain a compiled file; and storing the digital abstract code corresponding to the dex file and the storage path of the compiling file. In the first cold start process of the plug-in, in order to realize the first start acceleration, a compiling program for the dex file can be skipped first, and then the plug-in is started in a mode of directly loading the dex file. Further, in order to start the plug-in unit next time, after the plug-in unit is started for the first time, the control subprogram triggers the compiling program to compile the dex file, so as to obtain the compiled file for the next time. Specifically, after the first cold start of the plug-in unit is completed, the direct control subroutine may trigger the compiler to compile the dex file, or may trigger the compiler to compile the dex file when the current processing resource is relatively idle, so as to obtain a compiling optimization product (i.e. a compiling file) for the next start of the plug-in unit.
The embodiment of the application also provides a remote modification plug-in apk first loading operation capability, provides diversified plug-in first loading operation modes, and can select different first loading operation modes according to own conditions by different devices and different types of plug-in apks, so that the flexibility of plug-in apk application is improved. The method further comprises the steps of: and responding to the starting of a host application program for loading the plug-in, and determining a target loading mode corresponding to the plug-in, so that the plug-in is loaded based on the target loading mode to finish the starting of the plug-in. Specifically, a plug-in information table is generated according to the service type of the plug-in and the characteristic information of the plug-in; traversing the plug-in information table to determine whether the plug-in is of a preloading type; if yes, responding to the completion of downloading the plug-in, executing a plug-in loading mode matched with the preloading type, and triggering a compiling program to compile the dex file to obtain a compiling file; if the plug-in is not of a pre-loading type, determining whether the plug-in is started for the first time and loads the dex file in a target mode, and recording the target mode of loading the dex file corresponding to the plug-in; and if the plug-in does not specify the starting type, executing a default loading mode on the plug-in. The plug-in framework can support various strategies to load and run plug-ins, so that the plug-in loading is optimized. The pre-loading type is that after plug-in information is acquired from the background, plug-ins are downloaded, and the plug-ins are loaded after the downloading is completed, so that compiling optimization of dex files in the plug-ins is triggered to generate compiling products, and then the next plug-in can be directly loaded for compiling the optimizing products to operate without dex2oat, thereby achieving the purpose of accelerating the starting. And the method is that the starting optimization is achieved by directly loading the dex file, but not all the plug-ins need to be loaded and operated in the mode, and the framework accelerates the starting of the plug-ins in the mode only if plug-in list information issued by the background indicates that the plug-in loading needs to use the scheme. Correspondingly, if the starting type of the plug-in is not specified, the plug-in can be loaded in a default loading mode, and the default loading mode can be specified by a developer based on an actual application scene; or the general loading mode is used as a default loading mode, namely, a compiling file of the dex file is generated first, and then the compiling file is loaded to realize loading of the plug-in.
Referring to fig. 3, when the Android application is remotely deployed in a plug-in mode, a plug-in first starting mode is set according to the type of the service of the plug-in and the size of the plug-in apk. After the host is started, a plug-in information interface is requested to a server, a plug-in downloading list and strategy information are obtained, and the obtained plug-in list is traversed. If the current plug-in is of a preloading type, downloading the plug-in, and executing preloading after finishing, so as to trigger the dex file compiling optimization in advance, and the next time can be directly performed by using a compiling optimization product; if the current plug-in is not of a pre-loading type and the current plug-in is of a dex acceleration starting type for the first time, storing the dex acceleration starting state information required to be used by the current plug-in for the plug-in loading framework. The current plug-in does not specify the start type, does no additional processing, and the framework executes normal loading logic.
Specifically, the plug-in apk of the starting type is preloaded and directly downloaded, after the plug-in apk is downloaded, a dex file in the apk is loaded, when a user opens the plug-in apk, the plug-in apk is firstly judged by a plug-in frame whether the plug-in apk is installed or not, if the plug-in apk is of the installed type, the plug-in frame finishes plug-in apk loading, and at the moment, the plug-in is directly opened to finish plug-in starting acceleration. When traversing the plug-in list, the plug-in apk which is currently configured to load and run by using the dex file is found, and information and test of the plug-in are saved. When a user opens the plug-in apk, the plug-in framework returns to the current plug-in which is not installed, and whether the plug-in apk mode of directly operating the plug-in by adopting the dex file for the first time is firstly judged. When the plug-in framework loads the plug-in apk, if the imported loading strategy is to start the plug-in apk by using the direct-use dex file acceleration, whether the dex in the current plug-in apk already generates the optimized dex file is judged first, and if yes, the plug-in application is completed by directly adopting the dex file. When a plug-in frame loads a plug-in apk, if the imported loading strategy is to use direct use of a dex file to accelerate starting of the plug-in, and a dex in the current plug-in apk does not have a compiling optimization product odex file, the current android operating environment is firstly judged, and different implementation modes are used according to the version of an android platform.
Further, when the operating system is below android4.4, a DexClassLoader object is created, and a main dex file in the plug-in apk is loaded. The byte codes of the original second DEX file are obtained through decompression in the APK, and a dvm_davik_system_DexFile array is obtained through dlsym (the function of dlsym function is that a dynamic library (so library) obtains a symbol global variable and a function symbol address); inquiring the array to obtain a Dalvik_Dalvik_system_DexFile_OPENDexFile_Bytearray function; invoking the function, and gradually inputting the DEX byte codes acquired from the APK before completing the DEX loading to obtain legal DexFile objects; dexFile objects are added to the pathList of the created DexClassLoader. And after the steps are finished, the plug-in is operated by using the dex file, dex2oat is skipped, namely, the sub-process is started to asynchronously load the plug-in apk, the dex2oat is triggered, and the plug-in can be operated by using the odex for the next application.
When the operating system is Android 5-7, a plug-in dex file is loaded when a DexClassLoader object is created, but when a DexClassLoader is built, an unavailable compiling product path is transmitted, namely new DexClassLoader (String dexPath, string optimizedDirectory, string librarySearchPath, classLoaderparent), an optimizedDirector is transmitted to a file which can be read and written under a private directory of the current host application, but is not a directory, so that dex2oat fails, a fallback flow is finally triggered, the original dex is loaded by the fallback flow of the system, so that the dex2oat on Android 5-7 is skipped, and the apk is operated by using the dex file.
When the operating system is Android 8-9, inMemoryClassLoader newly added by Android is used on Android 8.x-9 to replace DexClassLoader to load a dex file, and because InMemoryClassLoader is a special mode for loading dex in a memory, compiling of dex2oat is not triggered, and a compiling scheme of the dex2oat can be skipped on the Android 8-9 by the method.
According to the first cold start optimizing method of the plug-in, the dex2oat process is skipped, dex start is adopted, so that the dex2oat is skipped in the first start, the time consumption of performing dex2oat on dex files in the start process is reduced, the start time consumption is effectively reduced, the plug-in of the type is downloaded, installed and operated in use, the waiting time of a user can be effectively reduced, the probability of ANR (a plug-in page is opened, a poor performance device consumes cpu and memory because of the process of dex2 ota), ANR is easily caused in a main process, user experience is improved, and the application retention rate is improved. The plug-in supports a plurality of first starting loading modes and can be modified remotely, which means that the plug-in can be adjusted at any time when the plug-in is deployed, and when one loading mode is not as expected or abnormal occurs, the plug-in can be modified remotely and adjusted dynamically.
Referring to fig. 4, in an embodiment of the present application, there is further provided a first cold start optimizing apparatus for a plug-in unit, where the apparatus includes:
an obtaining unit 201, configured to obtain a byte code dex file corresponding to a plug-in of an application program in response to a first cold start of the plug-in;
a first determining unit 202, configured to determine whether a compiled file corresponding to the dex file exists, and if not, obtain version information of a current operating system;
a second determining unit 203, configured to determine, based on version information of the current operating system, a target manner of loading the dex file;
the loading unit 204 is configured to load the dex file based on the target manner, so as to implement starting of the plugin;
each target mode is a mode of skipping the dex file compiling program and directly loading the dex file.
Optionally, the loading unit is further configured to:
and if the compiled file corresponding to the dex file exists, loading the compiled file to start the plug-in.
Optionally, the second determining unit includes:
the first determining unit is used for determining that the dex file is loaded in a first mode if the version number corresponding to the version information of the current operating system is smaller than a first threshold value, wherein the first mode represents a mode of loading the dex file through an array corresponding to the content of the dex file;
wherein, the loading unit is specifically configured to: acquiring byte codes of an original dex file from an installation package of the plug-in; loading the byte code to generate the dex file; and adding the dex file into a loader for loading the dex file through reflection, and operating the dex file to realize the starting of the plug-in.
Optionally, the second determining unit includes:
and the second determining subunit is configured to determine that loading the dex file is a second mode if the version number corresponding to the version information of the current operating system is greater than the first threshold and less than the second threshold, where the second mode characterizes a compiling product path that is not available through input, so that a compiling program for the dex file is skipped in a compiling failure mode.
Optionally, the second determining unit includes:
and the third determining subunit is configured to determine that loading the dex file is a third mode if the version number corresponding to the version information of the current operating system is greater than a second threshold, where the third mode indicates that the compiling program of the dex file is skipped by loading the dex in the memory.
Optionally, the apparatus further comprises:
the triggering unit is used for responding to the completion of starting the plug-in, controlling a subprocess to trigger a compiler to compile the dex file, and obtaining a compiled file;
and the storage unit is used for storing the digital abstract code corresponding to the dex file and the storage path of the compiling file.
Optionally, the apparatus further comprises:
and the third determining unit is used for determining a target loading mode corresponding to the plug-in response to the starting of the host application program for loading the plug-in, so that the plug-in is loaded based on the target loading mode to finish the starting of the plug-in.
Optionally, the third determining subunit is specifically configured to:
generating a plug-in information table according to the service type of the plug-in and the characteristic information of the plug-in;
traversing the plug-in information table to determine whether the plug-in is of a preloading type;
if yes, responding to the completion of downloading the plug-in, executing a plug-in loading mode matched with the preloading type, and triggering a compiling program to compile the dex file to obtain a compiling file;
if the plug-in is not of a pre-loading type, determining whether the plug-in is started for the first time and loads the dex file in a target mode, and recording the target mode of loading the dex file corresponding to the plug-in;
and if the plug-in does not specify the starting type, executing a default loading mode on the plug-in.
Based on the foregoing embodiments, embodiments of the present application provide a computer-readable storage medium storing one or more programs executable by one or more processors to implement the plug-in first cold start optimization method as in any of the above.
The embodiment of the application also provides electronic equipment, which comprises:
a memory for storing a program;
and the processor is used for executing the program, and the program is particularly used for realizing the plug-in first cold start optimization method according to any one of the above.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any person skilled in the art will readily recognize that variations or substitutions are within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
In the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, and identical and similar parts between the embodiments are all enough to refer to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method for optimizing first cold start of a plug-in, the method comprising:
responding to the first cold start of a plug-in of an application program, and obtaining a byte code dex file corresponding to the plug-in;
determining whether a compiled file corresponding to the dex file exists or not, and if not, obtaining version information of a current operating system;
determining a target mode for loading the dex file based on the version information of the current operating system;
loading the dex file based on the target mode to realize the starting of the plug-in;
each target mode is a mode of skipping the dex file compiling program and directly loading the dex file.
2. The method according to claim 1, wherein the method further comprises:
and if the compiled file corresponding to the dex file exists, loading the compiled file to start the plug-in.
3. The method of claim 1, wherein determining the target manner of loading the dex file based on version information of the current operating system comprises:
if the version number corresponding to the version information of the current operating system is smaller than a first threshold, determining that the dex file is loaded as a first mode, wherein the first mode represents a mode of loading the dex file through an array corresponding to the content of the dex file;
the loading the dex file based on the target mode to realize the starting of the plug-in includes:
acquiring byte codes of an original dex file from an installation package of the plug-in;
loading the byte code to generate the dex file;
and adding the dex file into a loader for loading the dex file through reflection, and operating the dex file to realize the starting of the plug-in.
4. The method of claim 1, wherein determining the target manner of loading the dex file based on version information of the current operating system comprises:
if the version number corresponding to the version information of the current operating system is larger than a first threshold and smaller than a second threshold, determining that the dex file is loaded in a second mode, wherein the second mode represents a compiling product path which is not available through transmission, so that a compiling program of the dex file is skipped in a compiling failure mode.
5. The method of claim 1, wherein determining the target manner of loading the dex file based on version information of the current operating system comprises:
if the version number corresponding to the version information of the current operating system is larger than a second threshold, determining that the dex file is loaded as a third mode, wherein the third mode represents that a compiling program of the dex file is skipped through the dex loading mode in a memory.
6. The method according to claim 1, wherein the method further comprises:
in response to the plug-in being started, controlling a subprocess to trigger a compiler to compile the dex file to obtain a compiled file;
and storing the digital abstract code corresponding to the dex file and the storage path of the compiling file.
7. The method according to claim 1, wherein the method further comprises:
and responding to the starting of a host application program for loading the plug-in, and determining a target loading mode corresponding to the plug-in, so that the plug-in is loaded based on the target loading mode to finish the starting of the plug-in.
8. The method of claim 7, wherein the determining, in response to a host application launch that loads a plug-in, a target loading manner corresponding to the plug-in comprises:
generating a plug-in information table according to the service type of the plug-in and the characteristic information of the plug-in;
traversing the plug-in information table to determine whether the plug-in is of a preloading type;
if yes, responding to the completion of downloading the plug-in, executing a plug-in loading mode matched with the preloading type, and triggering a compiling program to compile the dex file to obtain a compiling file;
if the plug-in is not of a pre-loading type, determining whether the plug-in is started for the first time and loads the dex file in a target mode, and recording the target mode of loading the dex file corresponding to the plug-in;
and if the plug-in does not specify the starting type, executing a default loading mode on the plug-in.
9. A plug-in first cold start optimization device, the device comprising:
the obtaining unit is used for responding to the first cold start of the plug-in of the application program and obtaining a byte code dex file corresponding to the plug-in;
a first determining unit, configured to determine whether a compiled file corresponding to the dex file exists, and if not, obtain version information of a current operating system;
the second determining unit is used for determining a target mode for loading the dex file based on the version information of the current operating system;
the loading unit is used for loading the dex file based on the target mode to realize the starting of the plug-in;
each target mode is a mode of skipping the dex file compiling program and directly loading the dex file.
10. An electronic device, comprising:
a memory for storing a program;
a processor for executing the program, in particular for implementing a first cold start optimization method of a plug-in according to any of claims 1-8.
CN202310882480.8A 2023-07-18 2023-07-18 Plug-in first cold start optimization method and device Pending CN116932078A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310882480.8A CN116932078A (en) 2023-07-18 2023-07-18 Plug-in first cold start optimization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310882480.8A CN116932078A (en) 2023-07-18 2023-07-18 Plug-in first cold start optimization method and device

Publications (1)

Publication Number Publication Date
CN116932078A true CN116932078A (en) 2023-10-24

Family

ID=88393615

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310882480.8A Pending CN116932078A (en) 2023-07-18 2023-07-18 Plug-in first cold start optimization method and device

Country Status (1)

Country Link
CN (1) CN116932078A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119473438A (en) * 2025-01-16 2025-02-18 荣耀终端股份有限公司 Application startup method, electronic device and chip system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119473438A (en) * 2025-01-16 2025-02-18 荣耀终端股份有限公司 Application startup method, electronic device and chip system
CN119473438B (en) * 2025-01-16 2025-07-01 荣耀终端股份有限公司 Application starting method, electronic equipment and chip system

Similar Documents

Publication Publication Date Title
JP5658283B2 (en) Application operating method, apparatus and system
US10635432B2 (en) Systems and methods for incremental software deployment
CN102279765B (en) Pre-compiling hosted managed code
JP7297769B2 (en) Shader distribution among client machines for pre-caching
US9928059B1 (en) Automated deployment of a multi-version application in a network-based computing environment
US8677329B2 (en) Methods and apparatuses for a compiler server
CN109614165B (en) Multi-version parallel operation method and device for COM (component object model) component
KR100952251B1 (en) A method of updating a software product by a service package, a computer-implemented method, a computer readable storage medium, and a service package
US8701104B2 (en) System and method for user agent code patch management
CN111078318A (en) Configuration file processing method, device, system and storage medium
JP2021002317A (en) Method, apparatus, device and storage medium for upgrading application
CN101937356B (en) Method for compiling WebKit browser and device thereof
CN109597631B (en) Process upgrading method and device and electronic equipment
CN111399860B (en) Light application deployment method, light application deployment device, computer equipment and storage medium
US20160378452A1 (en) Policy-Based Compression of Machine Code Generated by a Virtual Machine
CN111400256B (en) Method and device for calling resource file by application program
WO2019157891A1 (en) Application installation method and application installer generating method
CN116932078A (en) Plug-in first cold start optimization method and device
US8190587B1 (en) In-place image promotion
CN114661321B (en) Data processing system, data processing method and electronic equipment
CN113641389B (en) Software upgrading method, device and equipment based on OpenCPU
CN113032045A (en) Application program starting method, related device and equipment
CN113010172A (en) Method, device and system for processing configuration file and storage medium
CN120144162A (en) Upgrading method, device, electronic device and storage medium
CN113391852A (en) Platform software extension method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination