Optimization method and device for cold start, electronic device and storage medium
By constructing a class structure and class reference relationship graph, and filtering and packaging high-frequency classes into the main dex file, the problem of slow cold start of applications on low-version Android devices is solved, improving startup speed and user experience.
Patent Information
- Application Number
- CN202411832784.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2044-12-12
AI Technical Summary
On older Android devices, the initial cold start time for applications is too long, resulting in a poor user experience.
The class structure and class reference relationship graph are built based on the application configuration file. High-frequency classes are selected and packaged into the main dex file, while low-frequency classes are packaged into secondary dex files. Only the main dex file is loaded during cold start.
It speeds up application cold starts, reduces loading time, and improves user experience.
Smart Images

Figure CN119621191B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the computer technical field, and particularly relates to an optimization method and device for application cold start, electronic equipment and storage medium. BACKGROUND
[0002] With the development of science and technology, intelligent terminal products are becoming more and more popular, and a large number of intelligent terminals use the Android system.
[0003] For the device with a low version of the Android system, the Java runtime environment used is the Dalvik virtual machine. The biggest problem of the Dalvik virtual machine is that after the application is installed or updated, the time consumption of the first cold start of the application is very long, and it takes tens of seconds or even minutes. The user needs to face a period of black screen before the APP can be normally used, which seriously affects the user experience. SUMMARY
[0004] Therefore, the present application provides an optimization method and device for application cold start, electronic equipment and storage medium to solve the problem of slow first cold start of the application in the prior art.
[0005] To achieve the above object, the present application provides the following technical solutions.
[0006] The first aspect of the present application discloses an optimization method for application cold start, comprising:
[0007] constructing a first relationship graph and a second relationship graph based on a configuration file of an application; wherein the first relationship graph is used to represent class structure information corresponding to components of the application configuration file; and the second relationship graph is used to represent class reference information corresponding to the components of the application configuration file;
[0008] filtering high-frequency classes of the application according to the access frequency of the classes based on the first relationship graph and the second relationship graph, and packing the high-frequency classes into a main dex file;
[0009] packing non-high-frequency classes into a secondary dex file; wherein the non-high-frequency classes are classes other than the high-frequency classes in the application;
[0010] when the application is cold started, the main dex file is loaded, and after the cold start of the application is completed, the secondary dex file is loaded.
[0011] Optionally, the method described above, wherein the constructing a first relationship graph and a second relationship graph based on a configuration file of an application comprises:
[0012] obtaining component information of a preset component based on the configuration file;
[0013] Based on the component information, the class structure in the preset component is parsed, and the index and dependency of the class are established according to the class structure to generate the first relationship graph;
[0014] Based on the component information, the class reference in the preset component is parsed, and the index and dependency of the class are established according to the class reference to generate the second relationship graph.
[0015] Optionally, the method described above, based on the first relationship graph and the second relationship graph, filters out high-frequency classes of the application according to the access frequency of the classes, and packs the high-frequency classes into a main dex file, comprising:
[0016] The first relationship graph and the second relationship graph are traversed respectively to obtain the access frequency of each class in the first relationship graph and the access frequency of each class in the second relationship graph;
[0017] Each class in the first relationship graph is placed in a first queue in order of access frequency from high to low;
[0018] Each class in the second relationship graph is placed in a second queue in order of access frequency from high to low;
[0019] Based on the first queue and the second queue, classes with access frequencies meeting preset conditions are filtered out, and the filtered classes are packed into the main dex file.
[0020] Optionally, the method described above, based on the first queue and the second queue, filters out classes meeting preset conditions, and packs the filtered classes into the main dex file, comprising:
[0021] Depth traversal is performed on the first queue, if the number of methods of the classes that have been traversed is equal to a preset threshold value and the first queue has not completed traversal, the traversal is stopped, and the classes that have been traversed in the first queue are packed into the main dex file; wherein the threshold value is the maximum number of methods that the main dex file can accommodate;
[0022] If the number of methods of the classes that have completed traversal is less than the threshold value and the first queue has completed traversal, depth traversal is performed on the second queue, and the difference between the threshold value and the number of methods of the classes of the first queue is calculated;
[0023] If the number of methods of the classes that have been traversed in the second queue is equal to the difference value and the second queue has not completed traversal, the traversal is stopped, and the classes that have been traversed in the first queue and the classes that have been traversed in the second queue are packed into the main dex file;
[0024] If the number of methods of the class that the second queue has traversed is less than the difference value and the second queue has completed the traversal, the traversal is stopped, and the classes that have been traversed in the first queue and the classes that have been traversed in the second queue are packed into the main dex file.
[0025] The second aspect of the application discloses an optimization device for cold start of an application, comprising:
[0026] A construction unit is configured to construct a first relationship graph and a second relationship graph based on a configuration file of the application; wherein the first relationship graph is configured to represent class structure information corresponding to components of the application configuration file; and the second relationship graph is configured to represent class reference information corresponding to the components of the application configuration file.
[0027] A screening unit is configured to screen high-frequency classes of the application according to access frequencies of the classes based on the first relationship graph and the second relationship graph, and pack the high-frequency classes into a main dex file.
[0028] A packing unit is configured to pack non-high-frequency classes into a secondary dex file; wherein the non-high-frequency classes are classes other than the high-frequency classes in the application.
[0029] A loading unit is configured to load the main dex file when the application is cold started, and load the secondary dex file after the cold start of the application is completed.
[0030] Optionally, the construction unit of the device comprises:
[0031] An acquisition subunit is configured to acquire component information of a preset component based on the configuration file.
[0032] A first generation subunit is configured to analyze class structures in the preset component based on the component information, and establish indexes and dependencies of the classes according to the class structures, and generate the first relationship graph.
[0033] A second generation subunit is configured to analyze class references in the preset component based on the component information, and establish indexes and dependencies of the classes according to the class references, and generate the second relationship graph.
[0034] Optionally, the screening unit of the device comprises:
[0035] A first traversal subunit is configured to traverse the first relationship graph and the second relationship graph respectively, and acquire access frequencies of each class in the first relationship graph and access frequencies of each class in the second relationship graph.
[0036] A first queue construction subunit is configured to put each class in the first relationship graph into a first queue in order from high to low according to the access frequencies.
[0037] a second queue construction sub-unit, configured to put each class in the second relationship graph into a second queue in order from high to low according to the access frequency;
[0038] a screening sub-unit, configured to screen out classes with access frequencies meeting preset conditions based on the first queue and the second queue, and pack the screened classes into the main dex file.
[0039] Optionally, the apparatus described above, the screening sub-unit comprises:
[0040] a second traversal sub-unit, configured to perform deep traversal on the first queue, stop the traversal if the number of methods of the classes that have been traversed is equal to a preset threshold and the first queue has not been completely traversed, and pack the classes that have been traversed in the first queue into the main dex file, wherein the threshold is the maximum number of methods that the main dex file can accommodate;
[0041] a third traversal sub-unit, configured to perform deep traversal on the second queue and calculate a difference between the threshold and the number of methods of the classes in the first queue if the number of methods of the classes that have been completely traversed is less than the threshold and the first queue has been completely traversed;
[0042] a fourth traversal sub-unit, configured to stop the traversal if the number of methods of the classes that have been traversed in the second queue is equal to the difference and the second queue has not been completely traversed, and pack the classes that have been traversed in the first queue and the classes that have been traversed in the second queue into the main dex file;
[0043] a fifth traversal sub-unit, configured to stop the traversal if the number of methods of the classes that have been traversed in the second queue is less than the difference and the second queue has been completely traversed, and pack the classes that have been traversed in the first queue and the classes that have been traversed in the second queue into the main dex file.
[0044] A third aspect of the present application discloses an electronic device, comprising:
[0045] one or more processors;
[0046] a storage device having one or more programs stored thereon;
[0047] When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of the first aspect of the present application.
[0048] The fourth aspect of the present application discloses a computer storage medium, which stores a computer program, wherein the computer program is executed by a processor to implement the method of any one of the first aspect of the present application.
[0049] From the above technical solution, it can be seen that in the optimization method for application cold start provided by the present application, first, a first relationship graph and a second relationship graph are constructed based on the configuration file of the application; wherein the first relationship graph is used to represent the class structure information corresponding to the components of the application configuration file; the second relationship graph is used to represent the class reference information corresponding to the components of the application configuration file. Then, based on the first relationship graph and the second relationship graph, high-frequency classes of the application are screened out according to the access frequency of the classes, and the high-frequency classes are packed into the main dex file. And the non-high-frequency classes are packed into the secondary dex file. Finally, when the application cold start is performed, the main dex file is loaded, and after the application cold start is completed, the other secondary dex files are loaded in sequence. Therefore, it can be seen that by using the method of the present application, the high-frequency classes are packed into the main dex file, so that the business scenarios commonly used by the user during cold start can be covered in the main dex file, and only the main dex file is loaded during the application start stage, thereby reducing the loading time and accelerating the speed of application cold start. The problem of slow first cold start of the application in the prior art is solved. BRIEF DESCRIPTION OF DRAWINGS
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of the provided drawings.
[0051] Figure 1 A flowchart of an optimization method for application cold start disclosed by an embodiment of the present application;
[0052] Figure 2 A flowchart of an embodiment of step S101 disclosed by another embodiment of the present application;
[0053] Figure 3 An example diagram of the first relationship graph disclosed by another embodiment of the present application;
[0054] Figure 4 An example diagram of the second relationship graph disclosed by another embodiment of the present application;
[0055] Figure 5 A flowchart of an embodiment of step S102 disclosed by another embodiment of the present application;
[0056] Figure 6 An example diagram of the first queue disclosed by another embodiment of the present application;
[0057] Figure 7 A schematic diagram of an optimization device for cold start is disclosed for another embodiment of the present application.
[0058] Figure 8 A schematic diagram of an electronic device is disclosed for another embodiment of the present application. DETAILED DESCRIPTION
[0059] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0060] In the present application, the term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or further includes elements inherent to such a process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.
[0061] Also, in this document, the relational terms such as first and second and the like are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations.
[0062] As known from the background, for a device with a low version of the Android system, the Java runtime environment adopted is the Dalvik virtual machine. The biggest problem of it is that after the application is installed or updated, the time consumption of the first cold start of the application is very long, which needs to spend tens of seconds or even minutes, and the user needs to face a period of black screen before the APP can be normally used, which seriously affects the user experience.
[0063] In view of this, the present application provides an optimization method and device for cold start, an electronic device and a storage medium, to solve the problem of slow application cold start in the prior art.
[0064] The embodiments of the present application disclose an optimization method for cold start, as shown in Figure 1 specifically comprising:
[0065] S101, construct a first relationship graph and a second relationship graph based on the configuration file of the application; wherein the first relationship graph is used to represent the class structure information corresponding to the components of the application configuration file; and the second relationship graph is used to represent the class reference information corresponding to the components of the application configuration file.
[0066] It should be noted that, first, the application configuration manifest file of the application is acquired, which contains information such as the name, version, permission, and components of the application. Then, the first relationship graph and the second relationship graph are constructed based on the component information of the application configuration manifest file; wherein the first relationship graph is used to represent the class structure information corresponding to the components of the application configuration manifest file; and the second relationship graph is used to represent the class reference information corresponding to the components of the application configuration manifest file.
[0067] Optionally, in another embodiment of the present application, an implementation of step S101 can include: Figure 2
[0068] S201, based on the configuration file, acquire the component information of the preset component.
[0069] Among them, the preset component includes Activity component, service component, Provider component and Receiver component.
[0070] It should be noted that, based on the manifest configuration file of the application, the component information of the four components such as Activity component, service component, Provider component and Receiver component is acquired.
[0071] Among them, the Activity component is the most basic and most commonly used component in Android, which provides a screen that users can use to interact to complete a task. Each Activity is implemented as an independent class and inherits from the Activity base class. Activities communicate through Intent.
[0072] The Service component is a solution for implementing program background running in Android, which is usually used to perform tasks that do not require user interaction. Service has two states: Started and Bound. Started state is started by other components, and Bound state is bound by other components. The running of Service does not depend on the user interface, and even if the program switches to the background, Service can still run.
[0073] The Receive component is used to handle system broadcasts, such as detecting changes in phone battery level. It can receive broadcast messages sent by the system or applications and perform corresponding operations.
[0074] The Provider component is used to implement data sharing between different applications. Each application has its own data space, and other applications can access and manipulate shared data.
[0075] S202, based on component information, the class structure in the preset component is parsed, and the index and dependency of the class are established according to the class structure, and the first relationship diagram is generated.
[0076] It should be noted that the four component entries related to the application configuration manifest file are traversed, the class structure in the preset component is parsed according to the parent class, extension, and static relationship, and the index and dependency of the class are established according to the class structure, and the first relationship diagram is generated, as shown in Figure 3 Each node in the first relationship diagram should have at least the following information:
[0077] Dictionary table of signature characters to Class, Field, and Method structure;
[0078] The Class structure contains a list of all inherited and implemented parent Class structures;
[0079] The Class structure contains a list of all referenced String constants;
[0080] The Class structure contains a list of all referenced constant Method lists.
[0081] S203, based on component information, the class reference in the preset component is parsed, and the index and dependency of the class are established according to the class reference, and the second relationship diagram is generated.
[0082] It should be noted that based on the four component entries related to the application configuration manifest file, only the class reference in the preset component is parsed, and the index and dependency of the class are established according to the class reference, and the second relationship diagram is generated, as shown in Figure 4 Each node in the second relationship diagram has at least the following information:
[0083] Dictionary table of signature characters to Class, Field, and Method structure;
[0084] The Class structure contains a list of all referenced Type structures, Type being PrimitiveType and Class.
[0085] S102, based on the first relationship graph and the second relationship graph, filtering out high-frequency classes of the application according to the access frequency of the class, and packing the high-frequency classes into the main dex file.
[0086] It should be noted that based on the constructed first relationship graph and the second relationship graph, the high-frequency classes of the application are filtered out according to the access frequency of the class, that is, the classes with high access frequency. And the filtered high-frequency classes are packed into the main dex file. The dex file is a special executable file format of the Android system, mainly used to carry the core instructions and data of the application. It is not only the core component of the Android application, but also carries the key instructions and data of the program running time. The dex file provides strong support for the efficient running of Android application through its unique file format and optimization technology. Generally, an application will contain multiple dex files, such as classes1.dex (main dex), classes2.dex, classes3.dex, classes4.dex, among which the first dex file is the main dex file, and classes2.dex, classes3.dex, classes4.dex, etc. are secondary dex files. Among them, there is only one main dex file, and there can be one or more secondary dex files.
[0087] Optionally, in another embodiment of the present application, an embodiment of step S102 can include: Figure 5 as shown in the figure, which can include:
[0088] S501, respectively traversing the first relationship graph and the second relationship graph to obtain the access frequency of each class in the first relationship graph and the access frequency of each class in the second relationship graph.
[0089] It should be noted that the first relationship graph and the second relationship graph are traversed according to the breadth-first algorithm to obtain the access frequency of each class in the first relationship graph and the access frequency of each class in the second relationship graph. For example, the Activity class has classes activity_1 to activity_n, the Service class has classes service_1 to service_n, and the Provider class has classes provider_1 to provider_n, and the Receiver class has classes receiver_1 to receiver_n, respectively. The access frequency of each class is obtained.
[0090] S502, arranging each class in the first relationship graph in the first queue in descending order of access frequency.
[0091] It should be noted that a first queue is constructed, and each class in the first relationship graph is placed in the first queue in order of access frequency from high to low. In the queue, the higher the access frequency, the higher the ranking, for example Figure 6
[0092] S503, each class in the second relationship graph is placed in the second queue in order of access frequency from high to low.
[0093] It should be noted that a second queue is constructed, and each class in the second relationship graph is placed in the second queue in order of access frequency from high to low. In the queue, the higher the access frequency, the higher the ranking.
[0094] S504, based on the first queue and the second queue, classes with access frequencies meeting preset conditions are screened out, and the screened classes are packaged into the main dex file.
[0095] It should be noted that the first queue and the second queue are traversed, and classes with top k access frequencies are screened out, and the screened classes are packaged into the main dex file. Wherein, k can be set according to actual conditions, for example, the maximum number of methods that the main dex file can accommodate.
[0096] Optionally, in another embodiment of the present application, an embodiment of step S504 can include;
[0097] The first queue is traversed in depth, if the number of methods of the classes that have been traversed is equal to the preset threshold value and the first queue has not completed traversal, the traversal is stopped, and the classes that have been traversed in the first queue are packaged into the main dex file; wherein, the threshold value is the maximum number of methods that the main dex file can accommodate.
[0098] If the number of methods of the classes that have completed traversal is less than the threshold value and the first queue has completed traversal, the second queue is traversed in depth, and a difference value between the threshold value and the number of methods of the classes of the first queue is calculated.
[0099] If the number of methods of the classes that have been traversed in the second queue is equal to the difference value and the second queue has not completed traversal, the traversal is stopped, and the classes that have been traversed in the first queue and the classes that have been traversed in the second queue are packaged into the main dex file.
[0100] If the number of methods of the classes that have been traversed in the second queue is less than the difference value and the second queue has completed traversal, the traversal is stopped, and the classes that have been traversed in the first queue and the classes that have been traversed in the second queue are packaged into the main dex file.
[0101] It should be noted that the depth-first traversal of the first queue must cover all dependencies from level one to level n. If the number of methods of the traversed classes equals a preset threshold and the first queue has not been fully traversed, the traversal stops, the remaining classes are no longer traversed, and the traversed classes in the first queue are packaged into the main dex file. This threshold sets the maximum number of methods the main dex file can hold. If the number of methods of the traversed classes is less than the threshold and the first queue has been fully traversed, the depth-first traversal of the second queue continues, and the difference between the threshold and the number of methods in the first queue is calculated. If the number of methods of the traversed classes in the second queue equals the difference and the second queue has not been fully traversed, the traversal stops, the remaining classes are no longer traversed, and the traversed classes in both the first and second queues are packaged into the main dex file. If the number of methods of the classes traversed in the second queue is less than the difference and the second queue has been traversed, then stop traversing and pack the classes traversed in the first queue and the classes traversed in the second queue into the main dex file.
[0102] S103. Package the non-high-frequency classes into the secondary dex file; where the non-high-frequency classes are classes other than the high-frequency classes in the application.
[0103] It should be noted that when high-frequency classes are packaged into the main dex file, the remaining low-frequency classes are packaged into secondary dex files. Low-frequency classes are those classes in the application other than the high-frequency classes, and secondary dex files are dex files other than the main dex file, such as classes2.dex, classes3.dex, classes4.dex, etc.
[0104] S104. When the application is cold-started, the main dex file is loaded, and the secondary dex file is loaded only after the application has finished cold-starting.
[0105] It's important to note that during application cold starts, only the main dex file is loaded, not the secondary dex files. The secondary dex files are loaded only after the application cold start is complete. By packaging frequently used classes into the main dex file, it ensures that commonly used business scenarios during cold starts are covered in the main dex file. Furthermore, by loading only the main dex file during application startup, loading time is reduced, thus speeding up the application cold start process.
[0106] The application provides an optimization method for application cold start, first, a first relationship graph and a second relationship graph are constructed based on an application configuration file; the first relationship graph is used to represent class structure information corresponding to components of the application configuration file; and the second relationship graph is used to represent class reference information corresponding to the components of the application configuration file. Then, based on the first relationship graph and the second relationship graph, high-frequency classes of the application are screened out according to the access frequency of the first cold start scene class counted by the online version, and the high-frequency classes are packed into a main dex file. And non-high-frequency classes are packed into a secondary dex file. Finally, when the application cold start is performed, only the main dex file needs to be loaded, and after the application cold start is completed, the secondary dex file is loaded. Therefore, by using the method, the high-frequency classes are packed into the main dex file, so that the business scenarios commonly used by users during the cold start can be covered in the main dex file, and only the main dex file is loaded during the application start stage, so that the loading time is reduced and the speed of the application cold start is accelerated. The problem of slow application cold start in the prior art is solved.
[0107] Another embodiment of the application also provides an optimization device for application cold start, as shown in the Figure 7 application cold start is performed, only the main dex file needs to be loaded, and after the application cold start is completed, the secondary dex file is loaded. Therefore, by using the method, the high-frequency classes are packed into the main dex file, so that the business scenarios commonly used by users during the cold start can be covered in the main dex file, and only the main dex file is loaded during the application start stage, so that the loading time is reduced and the speed of the application cold start is accelerated. The problem of slow application cold start in the prior art is solved.
[0108] The construction unit 701 is configured to construct a first relationship graph and a second relationship graph based on an application configuration file; the first relationship graph is used to represent class structure information corresponding to components of the application configuration file; and the second relationship graph is used to represent class reference information corresponding to the components of the application configuration file.
[0109] The screening unit 702 is configured to screen out high-frequency classes of the application according to the access frequency of the classes based on the first relationship graph and the second relationship graph, and pack the high-frequency classes into a main dex file.
[0110] The packing unit 703 is configured to pack non-high-frequency classes into a secondary dex file; the non-high-frequency classes are classes other than the high-frequency classes in the application.
[0111] The loading unit 704 is configured to load the main dex file when the application cold start is performed, and load the secondary dex file after the application cold start is completed.
[0112] In the embodiment, the specific execution process of the construction unit 701, the screening unit 702, the packing unit 703 and the loading unit 704 can be referred to the method embodiment content of the corresponding Figure 1 application cold start is performed, only the main dex file needs to be loaded, and after the application cold start is completed, the secondary dex file is loaded. Therefore, by using the method, the high-frequency classes are packed into the main dex file, so that the business scenarios commonly used by users during the cold start can be covered in the main dex file, and only the main dex file is loaded during the application start stage, so that the loading time is reduced and the speed of the application cold start is accelerated. The problem of slow application cold start in the prior art is solved.
[0113] The application provides an optimization device for cold start, which comprises a first constructing unit 701, a screening unit 702, a packaging unit 703 and a loading unit 704. The first constructing unit 701 is used for constructing a first relationship graph and a second relationship graph based on the configuration file of the application. The first relationship graph is used for representing the class structure information corresponding to the components of the application configuration file. The second relationship graph is used for representing the class reference information corresponding to the components of the application configuration file. The screening unit 702 is used for screening the high-frequency classes of the application according to the access frequency of the first cold start scene class counted by the online version based on the first relationship graph and the second relationship graph, and packing the high-frequency classes into a main dex file. The packaging unit 703 is used for packing the non-high-frequency classes into a secondary dex file. The loading unit 704 is used for loading the main dex file when the application is cold started, and loading the secondary dex file after the cold start of the application is completed. Therefore, by packing the high-frequency classes into the main dex file, the method of the application ensures that the business scenes commonly used by the user during the cold start can be covered in the main dex file, and only the main dex file is loaded during the application start stage, thereby reducing the loading time and accelerating the speed of the cold start of the application. The problem of slow application cold start in the prior art is solved.
[0114] Optionally, in another embodiment of the application, an embodiment of the above-mentioned constructing unit 701 can comprise:
[0115] The obtaining sub-unit is configured to obtain component information of preset components based on the configuration file, wherein the preset components comprise Activity components, service components, Provider components and Receiver components.
[0116] The first generating sub-unit is configured to analyze the class structure in the preset components based on the component information, and establish the index and dependency of the classes according to the class structure, and generate the first relationship graph.
[0117] The second generating sub-unit is configured to analyze the class reference in the preset components based on the component information, and establish the index and dependency of the classes according to the class reference, and generate the second relationship graph.
[0118] In the embodiment, the specific execution process of the obtaining sub-unit, the first generating sub-unit and the second generating sub-unit can be referred to the corresponding above-mentioned Figure 2 embodiment, which will not be described here.
[0119] Optionally, in another embodiment of the application, an embodiment of the above-mentioned screening unit 702 can comprise:
[0120] The first traversing sub-unit is configured to traverse the first relationship graph and the second relationship graph respectively, and obtain the access frequency of each class in the first relationship graph and the access frequency of each class in the second relationship graph.
[0121] The first queue construction subunit is configured to put each class in the first relationship graph into a first queue in order of frequency of access in the cold start scenario from high to low.
[0122] The second queue construction subunit is configured to put each class in the second relationship graph into a second queue in order of frequency of access in the cold start scenario from high to low.
[0123] The screening subunit is configured to screen classes with frequency of access meeting preset conditions based on the first queue and the second queue, and pack the screened classes into the main dex file.
[0124] In this embodiment, the specific execution processes of the first traversal subunit, the first queue construction subunit, the second queue construction subunit, and the screening subunit can be referred to the corresponding method embodiments described above, and will not be described herein again. Figure 5
[0125] Optionally, in another embodiment of the present application, one implementation of the screening subunit can include:
[0126] The second traversal subunit is configured to perform deep traversal on the first queue, stop the traversal if the number of methods of the classes that have been traversed is equal to a preset threshold value and the first queue has not been completely traversed, and pack the classes that have been traversed in the first queue into the main dex file; wherein the threshold value is the maximum number of methods that can be accommodated by the main dex file.
[0127] The third traversal subunit is configured to perform deep traversal on the second queue and calculate a difference value between the threshold value and the number of methods of the classes in the first queue if the number of methods of the classes that have been completely traversed is less than the threshold value and the first queue has been completely traversed.
[0128] The fourth traversal subunit is configured to stop the traversal if the number of methods of the classes that have been traversed in the second queue is equal to the difference value and the second queue has not been completely traversed, and pack the classes that have been traversed in the first queue and the classes that have been traversed in the second queue into the main dex file.
[0129] The fifth traversal subunit is configured to stop the traversal if the number of methods of the classes that have been traversed in the second queue is less than the difference value and the second queue has been completely traversed, and pack the classes that have been traversed in the first queue and the classes that have been traversed in the second queue into the main dex file.
[0130] In this embodiment, the specific execution processes of the second traversal subunit, the third traversal subunit, the fourth traversal subunit, and the fifth traversal subunit can be referred to the corresponding method embodiments described above, and will not be described herein again.
[0131] Another embodiment of the present application further provides an electronic device, as shown in the accompanying drawings, specifically comprising: Figure 8
[0132] one or more processors 801.
[0133] a storage device 802 having stored thereon one or more programs.
[0134] The one or more programs, when executed by the one or more processors 801, cause the one or more processors 801 to implement a method as any of the above embodiments.
[0135] Another embodiment of the present application provides a computer storage medium having stored thereon a computer program, wherein the computer program is executed by a processor to implement a method as any of the above embodiments.
[0136] Each of the above-described embodiments is described in progressive manner, and the same or similar parts among the embodiments can be mutually referred to, and each of the embodiments focuses on the difference from other embodiments. In particular, for the system or system embodiments, since they are basically similar to the method embodiments, they are described more simply, and the relevant parts can be referred to the part of the method embodiments. The above-described system and system embodiments are merely illustrative, and the units described as separate components can be or can not be physically separated, and the components shown as units can be or can not be physical units, i.e., they can be located at one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment according to the actual needs. Those skilled in the art can understand and implement it without creative labor.
[0137] The skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized in electronic hardware, computer software or combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general in the above description. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0138] The above description of the disclosed embodiments enables a person skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. An optimization method for applying cold start, characterized in that, include: A first relationship graph and a second relationship graph are constructed based on the application's configuration file; wherein, the first relationship graph is used to represent the class structure information corresponding to the components of the application configuration file; and the second relationship graph is used to represent the class reference information corresponding to the components of the application configuration file. Based on the first relationship graph and the second relationship graph, the high-frequency classes of the application are selected according to the access frequency of the classes, and the high-frequency classes are packaged into the main dex file; Non-high-frequency classes are packaged into a secondary DEX file; wherein, the non-high-frequency classes are classes in the application other than the high-frequency classes; During a cold start of the application, the main dex file is loaded, and the secondary dex file is loaded only after the application has completed its cold start.
2. The method according to claim 1, characterized in that, The construction of the first and second relationship graphs based on the application configuration files includes: Based on the configuration file, obtain the component information of the preset components; Based on the component information, the class structure in the preset component is parsed, and the class index and dependencies are established according to the class structure to generate the first relationship graph; Based on the component information, the class references in the preset components are parsed, and the class indexes and dependencies are established according to the class references to generate the second relationship graph.
3. The method according to claim 1, characterized in that, Based on the first and second relationship graphs, the high-frequency classes of the application are selected according to their access frequency, and these high-frequency classes are packaged into the main dex file, including: The first relationship graph and the second relationship graph are traversed respectively to obtain the access frequency of each class in the first relationship graph and the access frequency of each class in the second relationship graph. Place each class in the first relationship graph into the first queue in descending order of access frequency; Place each class in the second relationship graph into the second queue in descending order of access frequency; Based on the first queue and the second queue, classes whose access frequency meets preset conditions are selected, and the selected classes are packaged into the main dex file.
4. The method according to claim 3, characterized in that, The step of filtering classes that meet preset conditions based on the first queue and the second queue, and packaging the filtered classes into the main dex file, includes: A depth-first traversal is performed on the first queue. If the number of methods of the traversed classes is equal to a preset threshold and the first queue has not been traversed, the traversal is stopped, and the traversed classes in the first queue are packaged into the main dex file. The threshold is the maximum number of methods that the main dex file can hold. If the number of methods of the class that has been traversed is less than the threshold and the first queue has been traversed, then a depth-first traversal is performed on the second queue, and the difference between the threshold and the number of methods of the class in the first queue is calculated. If the number of methods of the classes traversed in the second queue is equal to the difference and the second queue has not been traversed, then the traversal is stopped, and the classes traversed in the first queue and the classes traversed in the second queue are packaged into the main dex file. If the number of methods of the classes traversed in the second queue is less than the difference and the second queue has been traversed, then the traversal stops, and the classes traversed in the first queue and the classes traversed in the second queue are packaged into the main dex file.
5. An optimized device for cold start, characterized in that, include: A construction unit is used to construct a first relationship graph and a second relationship graph based on the application's configuration file; wherein, the first relationship graph is used to represent the class structure information corresponding to the components of the application configuration file; and the second relationship graph is used to represent the class reference information corresponding to the components of the application configuration file. The filtering unit is used to filter out the high-frequency classes of the application based on the access frequency of the classes according to the first relationship graph and the second relationship graph, and package the high-frequency classes into the main dex file; A packaging unit is used to package non-high-frequency classes into a secondary DEX file; wherein, the non-high-frequency classes are classes other than the high-frequency classes in the application; The loading unit is used to load the main dex file when the application is cold-started, and to load the secondary dex file after the application has completed the cold start.
6. The apparatus according to claim 5, characterized in that, The building unit includes: The sub-unit is used to obtain component information of a preset component based on the configuration file. The first generation subunit is used to parse the class structure in the preset component based on the component information, and to establish class indexes and dependencies according to the class structure to generate the first relationship graph. The second generation subunit is used to parse the class references in the preset component based on the component information, and to establish class indexes and dependencies based on the class references to generate the second relationship graph.
7. The apparatus according to claim 5, characterized in that, The filtering unit includes: The first traversal subunit is used to traverse the first relational graph and the second relational graph respectively, and obtain the access frequency of each class in the first relational graph and the access frequency of each class in the second relational graph. The first queue construction subunit is used to put each class in the first relationship graph into the first queue in descending order of access frequency; The second queue construction subunit is used to put each class in the second relationship graph into the second queue in descending order of access frequency; The filtering subunit is used to filter out classes whose access frequency meets preset conditions based on the first queue and the second queue, and package the filtered classes into the main dex file.
8. The apparatus according to claim 7, characterized in that, The filtering subunit includes: The second traversal subunit is used to perform a depth traversal of the first queue. If the number of methods of the traversed classes is equal to a preset threshold and the first queue has not been traversed, the traversal is stopped and the traversed classes in the first queue are packaged into the main dex file. The threshold is the maximum number of methods that the main dex file can hold. The third traversal subunit is used to perform a depth traversal of the second queue if the number of methods of the class that has been traversed is less than the threshold and the first queue has been traversed, and to calculate the difference between the threshold and the number of methods of the class in the first queue. The fourth traversal subunit is used to stop traversing if the number of methods of the classes traversed in the second queue is equal to the difference and the second queue has not been traversed, and to package the classes traversed in the first queue and the classes traversed in the second queue into the main dex file. The fifth traversal subunit is used to stop traversing if the number of methods of the classes traversed in the second queue is less than the difference and the second queue has been traversed, and to package the classes traversed in the first queue and the classes traversed in the second queue into the main dex file.
9. An electronic device, characterized in that, include: One or more processors; A storage device on which one or more programs are stored; When the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the method as described in any one of claims 1 to 4.
10. A computer storage medium, characterized in that, It stores a computer program thereon, wherein the computer program, when executed by a processor, implements the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Streaming micro-service loading verification method based on DEX file class
CN114924809A
Real time information feed processing
US20110029636A1