Program code optimization method, device, electronic device and storage medium

By code division of program code files and using file call identifiers to obtain pre-stored optimization files, the problem of long-term optimization of program code in the prior art is solved, and a more efficient optimization process is achieved.

CN114637512BActive Publication Date: 2025-02-25BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210241750.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-11
Publication Date
2025-02-25
Estimated Expiration
2042-03-11

AI Technical Summary

Technical Problem

Existing program code optimization methods take a long time, mainly because they need to traverse and analyze all classes contained in the program file.

Method used

By dividing the code in the program code file into cache type code and non-cache type code, and determining the file call identity based on the call relationship between the object code in the non-cache type code and the cache type code, thereby obtaining the pre-stored optimization file , reduce the scope of traversal analysis.

Benefits of technology

It shortens the optimization time of program code files, improves optimization efficiency, and avoids the need to traverse, analyze and mark all program codes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114637512B_ABST
    Figure CN114637512B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a program code optimization method, device, electronic device and storage medium. It includes: obtaining a program code file to be optimized; dividing the program code in the program code file to obtain cache type code and non-cache type code; determining a file call identifier according to the calling relationship between the target code in the non-cache type code and the cache type code, and obtaining a pre-stored first program optimization file corresponding to the file call identifier as the optimization file corresponding to the cache type code; obtaining an optimized program code file according to the first program optimization file and the second program optimization file obtained according to the target code in the non-cache type code. The present method improves the efficiency of program code optimization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a program code optimization method, device, electronic device and storage medium. Background Art

[0002] With the development of computer technology, when using the Android compilation system for code development and compilation, it is necessary to optimize the program code (for example, Java program code) file, and convert the optimized program code (for example, Java bytecode) into dex bytecode to generate a Dex file (Dex file is an executable file extracted from the application apk on Android, that is, the optimized program code file).

[0003] The current program code optimization method generally adopts the tree shaking optimization method, which first finds the program entry point (or program root node), and then traverses and analyzes the classes, methods, and fields contained in the program code from the program entry point, marking the necessary target classes, target methods, and target fields. Then, the computer device identifies the unnecessary classes in the program code based on the markings and deletes them to achieve the optimization of the program code.

[0004] However, in the current program code optimization method, since it is necessary to traverse and analyze all classes contained in the program file, as the amount of program code continues to increase, the program code optimization method takes a long time. Summary of the invention

[0005] The present disclosure provides a program code optimization method, device, electronic device and storage medium to at least solve the problem that the program code optimization method in the related art takes a long time. The technical solution of the present disclosure is as follows:

[0006] According to a first aspect of an embodiment of the present disclosure, a program code optimization method is provided, comprising:

[0007] Obtaining the program code file to be optimized;

[0008] Dividing the program code in the program code file to obtain cache type code and non-cache type code;

[0009] Determine a file call identifier according to a calling relationship between the target code in the non-cache type code and the cache type code, and obtain a pre-stored first program optimization file corresponding to the file call identifier as an optimization file corresponding to the cache type code;

[0010] An optimized program code file is obtained according to the first program optimization file and a second program optimization file obtained according to the target code in the non-cache type code.

[0011] In one embodiment, the program code file includes a plurality of program modules; dividing the program code in the program code file to obtain cache type code and non-cache type code includes:

[0012] According to the program module attribute information, the program modules contained in the program code file are divided to obtain target type program modules and non-target type program modules;

[0013] The program code included in the target type program module is determined as a cache type code, and the program code included in the non-target type program module is determined as a non-cache type code.

[0014] In one embodiment, before determining the file call identifier according to the calling relationship between the target code in the non-cache type code and the cache type code, the method further includes:

[0015] According to the program optimization algorithm, identifying the target code in the non-cache type code and the calling relationship corresponding to the target code; the calling relationship includes a passive calling relationship between the target code and the cache type code;

[0016] Determining, according to the passive calling relationship, a reclassification code passively called in the cache type code;

[0017] A program entry rule is configured for the reclassified code, and the reclassified code is reclassified into target code in the non-cache type code according to the program entry rule.

[0018] In one embodiment, obtaining the pre-stored first program optimization file corresponding to the file call identifier includes:

[0019] Based on the file call identifier, searching a database for a file carrying the file call identifier;

[0020] If a file carrying the file call identifier is found, the file is used as the first program optimization file.

[0021] In one embodiment, the method further comprises:

[0022] If no file carrying the file call identifier is found, the cache type code is optimized according to a program optimization algorithm to generate a first program optimization file;

[0023] The file calling identifier is added to the first program optimization file, and the first program optimization file after the file calling identifier is added is uploaded to the database.

[0024] In one embodiment, the step of optimizing the cache type code according to a program optimization algorithm to generate a first program optimization file includes:

[0025] Analyze and mark the target code contained in the cache type code according to the program optimization algorithm, and delete the unmarked program code in the cache type code;

[0026] A first program optimization file is constructed based on the target code included in the cache type code.

[0027] According to a second aspect of an embodiment of the present disclosure, there is provided a program code optimization device, comprising:

[0028] An acquisition unit, configured to execute acquisition of a program code file to be optimized;

[0029] A classification unit is configured to divide the program code in the program code file to obtain cache type code and non-cache type code;

[0030] A processing unit is configured to determine a file call identifier according to a calling relationship between the target code in the non-cache type code and the cache type code, and obtain a first program optimization file corresponding to the file call identifier from a database as an optimization file corresponding to the cache type code;

[0031] The generating unit is configured to execute a second program optimization file obtained according to the first program optimization file and the target code in the non-cache type code to obtain an optimized program code file.

[0032] In one embodiment, the program code file includes a plurality of program modules; the classification unit includes:

[0033] The classification subunit is configured to divide the program modules contained in the program code file according to the program module attribute information to obtain target type program modules and non-target type program modules;

[0034] The determination subunit is configured to determine the program code included in the target type program module as a cache type code, and determine the program code included in the non-target type program module as a non-cache type code.

[0035] In one embodiment, the program code optimization device further comprises:

[0036] an identification unit configured to execute, according to a program optimization algorithm, identification of a target code in the non-cache type code and a call relationship corresponding to the target code; the call relationship includes a passive call relationship between the target code and the cache type code;

[0037] A first determining unit is configured to determine, according to the passive calling relationship, a reclassification code passively called in the cache type code;

[0038] The second determining unit is configured to configure a program entry rule for the reclassified code, and reclassify the reclassified code into a target code in the non-cache type code according to the program entry rule.

[0039] In one embodiment, the processing unit includes:

[0040] A query subunit is configured to perform a query in a database for a file carrying the file call identifier based on the file call identifier;

[0041] The determination subunit is configured to execute, if a file carrying the file call identifier is found in the search, using the file as the first program optimization file.

[0042] In one embodiment, the program code optimization device further comprises:

[0043] a generating unit configured to optimize the cache type code according to a program optimization algorithm to generate a first program optimization file if no file carrying the file call identifier is found;

[0044] The uploading unit is configured to add the file calling identifier to the first program optimization file, and upload the first program optimization file after the file calling identifier is added to the database.

[0045] In one embodiment, the processing unit includes:

[0046] an optimization subunit, configured to execute according to a program optimization algorithm, analyze and mark the target code contained in the cache type code, and delete the unmarked program code in the cache type code;

[0047] The construction subunit is configured to execute the target code contained in the cache type code to construct a first program optimization file.

[0048] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising:

[0049] processor;

[0050] a memory for storing instructions executable by the processor;

[0051] The processor is configured to execute the instructions to implement the program code optimization method described in the first aspect above.

[0052] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the program code optimization method as described in the first aspect above.

[0053] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided. When the instructions are executed by a processor of an electronic device, the electronic device is enabled to execute the program code optimization method as described in the first aspect above.

[0054] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: by adopting this method, cache type code and non-cache type code are obtained by dividing the program code, and then, according to the calling relationship between the target code in the non-cache type code and the cache type code, the file call identifier is determined, and based on the determined file call identifier, the optimized first program optimization file corresponding to the cache type code can be directly obtained, so that there is no need to traverse, analyze and mark all the program codes contained in the program code file, thereby shortening the optimization time of the program code file and thus improving the optimization efficiency of the program code file.

[0055] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0057] Figure 1 The figure is a flowchart of a method for optimizing program codes according to an exemplary embodiment.

[0058] Figure 2 is a flowchart showing steps of dividing program codes according to an exemplary embodiment.

[0059] Figure 3 The figure is a schematic diagram of program codes and calling relationships in a program code file according to an exemplary embodiment.

[0060] Figure 4 The present invention is a flowchart showing the steps of determining target code in non-cache type code according to an exemplary embodiment.

[0061] Figure 5 The diagram is a schematic diagram of determining all target codes in a non-cache type code according to an exemplary embodiment.

[0062] Figure 6 The figure is a flowchart showing the steps of obtaining a first program optimization file according to an exemplary embodiment.

[0063] Figure 7 The diagram is a schematic diagram showing the relationship between non-cache type and cache type code calls according to an exemplary embodiment.

[0064] Figure 8 The figure is a flowchart showing the steps of generating and uploading a first program optimization file according to an exemplary embodiment.

[0065] Fig. 9 The figure is a flowchart showing the steps of optimizing and constructing a first program optimization file according to an exemplary embodiment.

[0066] Fig.10 The diagram is a schematic diagram showing optimization of cache type and non-cache type codes according to an exemplary embodiment.

[0067] Fig.11 The figure is a flowchart of a method for optimizing program codes according to an exemplary embodiment.

[0068] Fig.12 The figure is a block diagram of a program code optimization device according to an exemplary embodiment.

[0069] Fig.13 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0070] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0071] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0072] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.

[0073] The program code optimization method provided by the present disclosure can be applied to an electronic device. The electronic device includes a processor and a memory for storing instructions executable by the processor. The processor is configured to execute the program code optimization instructions to implement the program code optimization method.

[0074] Figure 1 is a flowchart of a program code optimization method according to an exemplary embodiment. Figure 1 As shown, the program code optimization method is used in an electronic device and includes the following steps.

[0075] In step S110, a program code file to be optimized is obtained.

[0076] In implementation, the electronic device obtains a program code file to be optimized, wherein the program code file includes all program classes, methods and fields developed and compiled in the Android compilation system. Generally, the file format of the program code file is a jar format or a class format.

[0077] In step S120, the program code in the program code file is divided into cache type codes and non-cache type codes.

[0078] In implementation, the non-cache type code obtained after the program code file is divided is the program code with a high correlation with the business to be executed by the program code file, and the cache type code is the program code with a low correlation with the business to be executed by the program code file. For example, the non-cache type code may be the bottom layer program code, and the cache type code may be the upper layer program code.

[0079] Specifically, the electronic device identifies the attribute information of each program module contained in the program code file to be optimized, and divides all the program modules contained in the program code file based on the attribute information of the program modules to obtain the division result corresponding to the attribute information of the program modules, in which all the program codes are divided into two categories: the program code contained in the target type program module is the cache type code, and the program code contained in the non-target type program module is the non-cache type code.

[0080] In step S130, the file call identifier is determined according to the calling relationship between the target code in the non-cache type code and the cache type code, and the pre-stored first program optimization file corresponding to the file call identifier is obtained as the optimization file corresponding to the cache type code.

[0081] In implementation, the electronic device can identify and mark the target code in the non-cache type code, and determine the file call identifier based on the calling relationship between the target code and the cache type code. The generated file call identifier contains the calling relationship information between the target code and the cache type code, and is used to uniquely represent the first program optimization file (represented by dex1) corresponding to the cache type code. Based on the file call identifier, the electronic device can obtain the first program file carrying the file call identifier from the database and use it as an optimized file constructed by the target code in the cache type code.

[0082] In one example, the electronic device can traverse and analyze all the bytecode instructions (i.e., call relationship instructions) between non-cache type codes through method call instructions, field access instructions, etc., and determine the call relationship between the target code in the non-cache type code and the cache type code, wherein the call relationship includes active call relationship and passive call relationship, the active call relationship is the call relationship between the non-cache type code and the cache type code; the passive call relationship is the call relationship between the cache type code and the non-cache type code. Each call relationship can be represented by a string, then the electronic device can obtain the active call relationship between the target code in the non-cache type code and the cache type code, determine the call relationship string corresponding to each active call relationship, and then the electronic device can sort and calculate all the call relationship strings according to the md5 and other summary calculation methods to obtain the file call identification (ID) corresponding to the cache type code.

[0083] Optionally, in addition to the summary calculation methods such as md5, the file call identifier can also be determined by the sha1 method, or by directly storing the call relationship string, which is not limited in the embodiments of the present disclosure.

[0084] In step S140, an optimized program code file is obtained according to the first program optimization file and the second program optimization file obtained according to the target code in the non-cache type code.

[0085] Specifically, based on the program optimization algorithm, the electronic device, after identifying and marking the target code in the non-cache type code, deletes the target code except the mark in the non-cache type code to obtain a second program optimization file (dex2) consisting only of the target code. Then, the electronic device obtains an optimized program code file based on the second program optimization file and the acquired first program optimization file.

[0086] In the above-mentioned program code optimization method, by dividing the program code, cache type code and non-cache type code are obtained, and then, according to the calling relationship between the target code in the non-cache type code and the cache type code, the file call identifier is determined. Based on the determined file call identifier, the optimized first program optimization file corresponding to the cache type code can be directly obtained, so that there is no need to traverse, analyze and mark all the program codes contained in the program code file, thereby shortening the optimization time of the program code file and improving the optimization efficiency of the program code file.

[0087] In an exemplary embodiment, if Figure 2 As shown, the program code file includes multiple program modules. For the multiple program modules included in the program code file, step S120 can be specifically implemented by the following steps:

[0088] In step S121, the program modules included in the program code file are divided according to the program module attribute information to obtain target type program modules and non-target type program modules.

[0089] The program code file includes program modules of different attribute types, and each program module includes a collection of multiple program classes, methods, and fields.

[0090] Specifically, the electronic device divides the program modules contained in the program code file according to the program module attribute information to obtain target type program modules and non-target type program modules. For example, the electronic device can determine the underlying modules that are irrelevant to the business (such as: network library, image library, tool library, etc.) as target type program modules, and determine other program modules related to the business as non-target type program modules.

[0091] In step S122, the program code included in the target type program module is determined as a cache type code, and the program code included in the non-target type program module is determined as a non-cache type code.

[0092] Specifically, the electronic device can obtain the division result of the program code contained in the program module based on the division of the program module, that is, determine the program code contained in the target type program module as the cache type code, and determine the program code contained in the non-target type program module as the non-cache type code. Figure 3 As shown, Figure 3 The circles in the upper half of the dividing line represent non-cache type codes contained in the non-target type program module, and the circles in the lower half of the dividing line represent cache type codes contained in the target type program module. Figure 3The circle in the figure represents a program class, method or field (also called a program code input point), and the arrows represent the calling relationship between the program code input points. For example, point a is a method, and the return value type is the program class represented by point c. Then the calling relationship between points a and c is represented by an arrow pointing from point a to point c.

[0093] In this embodiment, the program codes in the program code file are classified so that only non-cache type codes are optimized, thereby reducing the program code processing amount and improving the program code optimization efficiency.

[0094] In an exemplary embodiment, if Figure 4 As shown, before step 130, the method further includes:

[0095] Step S401 , identifying the target code in the non-cache type code and the calling relationship corresponding to the target code according to the program optimization algorithm.

[0096] Among them, the calling relationship includes the passive calling relationship between the target code and the cache type code

[0097] Specifically, the electronic device identifies the target code in the non-cache type code and the calling relationship corresponding to the target code according to the program optimization algorithm. Since all program entry points are divided in the non-cache type code, the active and passive judgment criteria of the calling relationship are based on the non-cache type code. If the target code in the non-cache type code calls the cache type code, then the calling relationship is an active calling relationship; if the code in the non-cache type code is called by the target code in the cache type code, then the calling relationship is a passive calling relationship. Figure 3 As shown in the figure, points a and b in the non-cache type code are program entry points, and the calling relationship represented by points a and b (arrows) pointing to points d and f is an active calling relationship. The calling relationship represented by point e (arrow) in the cache type code pointing to point g in the non-cache type code is a passive calling relationship.

[0098] Step S402, determining the reclassification code passively called in the cache type code according to the passive calling relationship.

[0099] Specifically, when the electronic device optimizes the program, based on the pre-classification of the program code in the program code file, the two types of classified program codes are analyzed and processed independently. Therefore, when the second type of program code is optimized separately, if only the active calling relationship of the non-cache type code to the cache type code is considered, such as Figure 5As shown in the figure, there will be point g in the non-cache type code, which is the target code called by point e (class, method or field) in the cache type code and is lost (i.e., not marked and deleted). Therefore, when the electronic device performs optimization analysis based on the call relationship, according to this passive call relationship, the code under the passive call relationship in the cache type code is determined as the reclassified code (i.e., point e in the figure).

[0100] Step S403, configuring a program entry rule for the reclassified code, and reclassifying the reclassified code into a target code in a non-cache type code according to the program entry rule.

[0101] Specifically, the electronic device configures a program entry rule for the determined reclassified code, that is, in the Android compilation environment, the electronic device configures a keep rule for the reclassified code in the obfuscation file. Then, based on the program entry rule (keep rule), the electronic device determines the reclassified code as a program entry point, so that the reclassified code is reclassified into the target code in the non-cache type code (the program entry point is included in the non-cache type code).

[0102] In this embodiment, the reclassification code in the program code divided into program modules is reconfigured and converted into a program entry point (target code) in a non-cache type code, thereby realizing the re-division of the reclassification code and avoiding the deletion of target code that may exist due to code classification deviation.

[0103] In an exemplary embodiment, if Figure 6 As shown, in step 130, obtaining the first program optimization file corresponding to the file call identifier from the database can be achieved by the following steps:

[0104] Step S131, based on the file call identifier, searching the database for files carrying the file call identifier.

[0105] Among them, Figure 7 As shown, since the file call identifier is determined based on the calling relationship between the target code in the non-cache type code and the cache type code, the electronic device can determine the corresponding code in the cache type code (i.e., determine the target code in the cache type code) according to the calling relationship between each target code in the non-cache type code and the cache type code. Therefore, no matter how many program code input points are included in the cache type code, the final code optimization result is determined based on the target code in the non-cache type code. Therefore, the file call identifier can uniquely identify the program optimization result of the cache type code.

[0106] Specifically, the electronic device may query the database for a file carrying the file call identifier based on the file call identifier to determine whether there is a program optimization file after cache type code optimization in the database.

[0107] Step S132: If a file carrying a file call identifier is found, the file is used as the first program optimization file.

[0108] Specifically, if a file carrying a file call identifier is found, the electronic device uses the file as the first program optimization file corresponding to the cache type code, wherein the first program optimization file is a file uploaded to the database for storage after the cache type code is optimized.

[0109] In this embodiment, the file carrying the file call identifier is directly queried in the database through the unique calling relationship of the file call identifier. Then, the file determined based on the file call identifier is the first program optimization file corresponding to the cache type code. There is no need to perform optimization analysis and processing on the cache type code. The optimized first program optimization file can be obtained through query, thereby reducing the amount of program code processing in the program code file and improving the efficiency of program optimization processing.

[0110] In an exemplary embodiment, if Figure 8 As shown, the query result of querying the file in the database based on the file call identifier also includes another situation, and the specific processing process includes:

[0111] Step S801: If no file carrying the file call identifier is found, the cache type code is optimized according to the program optimization algorithm to generate a first program optimization file.

[0112] Specifically, if no file carrying a file call identifier is found in the database, indicating that the cache type code based on the current call relationship has not been optimized, the electronic device traverses and analyzes the cache type code according to a preset program optimization algorithm (e.g., a tree shaking optimization algorithm) and marks the target code therein. Then, the electronic device optimizes the cache type code, converts it into a dex format bytecode, and generates a first program optimization file (dex file) constructed with only the marked target code.

[0113] Step S802: adding a file call identifier to the first program optimization file, and uploading the first program optimization file after adding the file call identifier to the database.

[0114] Specifically, the electronic device adds a file call identifier to the first program optimization file after optimization processing, and uniquely represents the first program optimization file through the file call identifier. Then, the electronic device uploads the first program optimization file with the file call identifier added to the database, so that other users can reuse the first program optimization file based on the file call identifier during the program code optimization process.

[0115] In this embodiment, when no file carrying a file call identifier is found, program optimization processing is performed on the cache type code, the file call identifier is added to the first program optimization file obtained by the program optimization processing, and the first program optimization file is uploaded to the database, which not only completes the program optimization process but also allows the first program optimization file to be reused.

[0116] In an exemplary embodiment, if Fig. 9 As shown, in step 801, the cache type code is optimized according to the program optimization algorithm, and the generation of the first program optimization file specifically includes the following steps:

[0117] Step S8011, analyzing and marking the target code contained in the cache type code according to the program optimization algorithm, and deleting the unmarked program code in the cache type code.

[0118] Specifically, since no existing first program optimization file is found, the electronic device needs to analyze and mark the target code contained in the cache type code according to the program optimization algorithm and the calling relationship between the target code in the non-cache type code and the cache type code. Fig.10 As shown, Fig.10 The circles below the middle dividing line represent all the input points of the first type of program code. The electronic device identifies the target code, i.e., point d and point f (point e does not exist, as point e has been reclassified as non-cache type code) based on the calling relationship between the target code and the cache type code in the non-cache type code: the passive calling relationship between point d and point c (i.e., the active calling relationship between point c and point d), and the passive calling relationship between point f and point b (i.e., the active calling relationship between point b and point f). Then, the electronic device deletes the other program code input points in the cache type code except the marked target code through the R8 tool.

[0119] Step S8012: construct a first program optimization file according to the target code included in the cache type code.

[0120] Specifically, the electronic device converts the target code points (for example, in java bytecode format) contained in the cache type code into dex bytecode format through the R8 tool, and constructs a first program optimization file (dex file format). Fig.10As shown, the electronic device constructs a first program optimization file after the cache type code program is optimized based on analyzing the marked target code points d and f.

[0121] In this embodiment, by means of tree shaking optimization processing such as analysis marks, cache type codes for which no program optimization file is found are optimized, and a reusable first program optimization file is generated.

[0122] In an exemplary embodiment, R8 is pre-installed in the electronic device. R8 is a compilation tool of the Android compilation system, which can be used to delete, optimize, and obfuscate Java bytecodes, and convert Java bytecodes into dex bytecodes. Fig.11 As shown, an example of a program code optimization method is provided, and the example method can optimize the program code based on the R8 compilation tool, and the example method includes:

[0123] Step S1101, obtaining a program code file to be optimized, and inputting the program code file into R8 to perform program optimization processing.

[0124] Step S1102, according to the program module attribute information, the program modules contained in the program code file are divided to obtain target type program modules and non-target type program modules, the program code contained in the target type program module is determined as cache type code, and the program code contained in the non-target type program module is determined as non-cache type code.

[0125] Step S1103, according to the program optimization algorithm, identify the target code in the non-cache type code and the calling relationship corresponding to the target code; the calling relationship includes the passive calling relationship between the target code in the non-cache type code and the cache type code, and the active calling relationship between the cache type code and the target code in the non-cache type code.

[0126] Step S1104, determining the reclassification code passively called in the cache type code according to the passive calling relationship.

[0127] Step S1105, configuring a program entry rule for the reclassified code, and reclassifying the reclassified code into a target code in a non-cache type code according to the program entry rule.

[0128] Step S1106, determining a file call identifier according to the active call relationship between the target code in the non-cache type code and the cache type code.

[0129] Step S1107, query whether there is a file carrying the file call identifier in the pre-stored program optimization file, if there is a file carrying the file call identifier, execute step S1108, if there is no file carrying the file call identifier, execute step S1109.

[0130] Step S1108: Use the queried file carrying the file call identifier as the first program optimization file.

[0131] Step S1109, optimizing the cache type code according to the program optimization algorithm, generating a first program optimization file, adding a file call identifier to the first program optimization file, and uploading the first program optimization file with the added file call identifier to the database.

[0132] Step S1110, obtaining an optimized program code file according to the first program optimization file and the second program optimization file.

[0133] It should be understood that although Figures 1 to 4 , Figure 6 , Figures 8 to 9 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figures 1 to 4 , Figure 6 , Figures 8 to 9 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.

[0134] It can be understood that the same / similar parts between the various embodiments of the above method in this specification can refer to each other, and each embodiment focuses on the differences from other embodiments. For related points, please refer to the description of other method embodiments.

[0135] Fig.12 is a block diagram of a program code optimization device according to an exemplary embodiment. Fig.12 The device 1200 includes an acquisition unit 1202, a classification unit 1204, a processing unit 1206 and a generation unit 1208.

[0136] The acquisition unit 1202 is configured to execute acquisition of a program code file to be optimized.

[0137] The classification unit 1204 is configured to divide the program code in the program code file into cache type codes and non-cache type codes.

[0138] The processing unit 1206 is configured to determine the file call identifier based on the calling relationship between the target code in the non-cache type code and the cache type code, and obtain the first program optimization file corresponding to the file call identifier from the database as the optimization file corresponding to the cache type code.

[0139] The generating unit 1208 is configured to execute a second program optimization file obtained according to the first program optimization file and the target code in the non-cache type code to obtain an optimized program code file.

[0140] In an exemplary embodiment, the program code file includes multiple program modules; the classification unit 1204 includes: a classification sub-unit, configured to execute the division of the program modules included in the program code file according to the program module attribute information to obtain target type program modules and non-target type program modules.

[0141] The determination subunit is configured to determine the program code included in the target type program module as the cache type code and determine the program code included in the non-target type program module as the non-cache type code.

[0142] In an exemplary embodiment, the apparatus 1200 further includes:

[0143] The identification unit is configured to execute a program optimization algorithm to identify the target code in the non-cache type code and the calling relationship corresponding to the target code; the calling relationship includes a passive calling relationship between the target code and the cache type code.

[0144] The first determining unit is configured to determine the reclassification code that is passively called in the cache type code according to the passive calling relationship.

[0145] The second determining unit is configured to configure a program entry rule for the reclassified code, and reclassify the reclassified code into a target code in the non-cache type code according to the program entry rule.

[0146] In an exemplary embodiment, the processing unit 1206 includes:

[0147] A query subunit is configured to perform a query in a database for a file carrying a file call identifier based on the file call identifier;

[0148] The determination subunit is configured to execute, if a file carrying a file call identifier is found in the search, the file is used as the first program optimization file.

[0149] In an exemplary embodiment, the apparatus 1200 further includes:

[0150] The generating unit is configured to optimize the cache type code according to the program optimization algorithm to generate a first program optimization file if no file carrying the file call identifier is found.

[0151] The uploading unit is configured to add a file calling identifier to the first program optimization file, and upload the first program optimization file after the file calling identifier is added to the database.

[0152] In an exemplary embodiment, the processing unit 1206 includes:

[0153] The optimization subunit is configured to execute according to the program optimization algorithm, analyze and mark the target code contained in the cache type code, and delete the unmarked program code in the cache type code;

[0154] The construction subunit is configured to execute the target code contained in the cache type code to construct a first program optimization file.

[0155] Regarding the device 1200 in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0156] Fig.13 1 is a block diagram of an electronic device 1300 for program code optimization according to an exemplary embodiment. For example, the electronic device 1300 may be a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0157] Reference Fig.13 , the electronic device 1300 may include one or more of the following components: a processing component 1302 , a memory 1304 , a power component 1306 , a multimedia component 1308 , an audio component 1310 , an input / output (I / O) interface 1313 , a sensor component 1311 , and a communication component 1316 .

[0158] The processing component 1302 generally controls the overall operation of the electronic device 1300, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 1302 may include one or more processors 1320 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 1302 may include one or more modules to facilitate the interaction between the processing component 1302 and other components. For example, the processing component 1302 may include a multimedia module to facilitate the interaction between the multimedia component 1308 and the processing component 1302.

[0159] The memory 1304 is configured to store various types of data to support operations on the electronic device 1300. Examples of such data include instructions for any application or method operating on the electronic device 1300, contact data, phone book data, messages, pictures, videos, etc. The memory 1304 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk, an optical disk, or a graphene memory.

[0160] The power supply component 1306 provides power to the various components of the electronic device 1300. The power supply component 1306 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 1300.

[0161] The multimedia component 1308 includes a screen that provides an output interface between the electronic device 1300 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1308 includes a front camera and / or a rear camera. When the electronic device 1300 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0162] The audio component 1310 is configured to output and / or input audio signals. For example, the audio component 1310 includes a microphone (MIC), and when the electronic device 1300 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 1304 or sent via the communication component 1316. In some embodiments, the audio component 1310 also includes a speaker for outputting an audio signal.

[0163] I / O interface 1313 provides an interface between processing component 1302 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0164] The sensor assembly 1311 includes one or more sensors for providing various aspects of status assessment for the electronic device 1300. For example, the sensor assembly 1311 can detect the open / closed state of the electronic device 1300, the relative positioning of the components, such as the display and keypad of the electronic device 1300, and the sensor assembly 1311 can also detect the position change of the electronic device 1300 or the components of the electronic device 1300, the presence or absence of contact between the user and the electronic device 1300, the orientation or acceleration / deceleration of the device 1300, and the temperature change of the electronic device 1300. The sensor assembly 1311 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1311 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1311 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0165] The communication component 1316 is configured to facilitate wired or wireless communication between the electronic device 1300 and other devices. The electronic device 1300 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 1316 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1316 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0166] In an exemplary embodiment, the electronic device 1300 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above methods.

[0167] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 1304 including instructions, and the above instructions can be executed by the processor 1320 of the electronic device 1300 to perform the above method. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0168] In an exemplary embodiment, a computer program product is further provided. The computer program product includes instructions. The instructions can be executed by the processor 1320 of the electronic device 1300 to complete the above method.

[0169] It should be noted that the above-mentioned devices, electronic devices, computer-readable storage media, computer program products, etc. may also include other implementation methods according to the description of the method embodiments. The specific implementation methods can refer to the description of the relevant method embodiments, which will not be described one by one here.

[0170] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the claims.

[0171] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A program code optimization method, characterized in that: include: Obtaining the program code file to be optimized; Dividing the program code in the program code file to obtain cache type code and non-cache type code; Determine a file call identifier according to a calling relationship between the target code in the non-cache type code and the cache type code, and obtain a pre-stored first program optimization file corresponding to the file call identifier as an optimization file corresponding to the cache type code; Obtaining an optimized program code file according to the first program optimization file and a second program optimization file obtained according to the target code in the non-cache type code; The step of obtaining an optimized program code file according to the first program optimization file and the second program optimization file obtained according to the target code in the non-cache type code comprises: Based on the program optimization algorithm, after the target code in the non-cache type code is identified and marked, the target code except the mark in the non-cache type code is deleted to obtain a second program optimization file composed of the target code; An optimized program code file is obtained according to the second program optimization file and the obtained first program optimization file.

2. The method according to claim 1, characterized in that The program code file includes a plurality of program modules; the program code in the program code file is divided to obtain cache type code and non-cache type code, including: According to the program module attribute information, the program modules contained in the program code file are divided to obtain target type program modules and non-target type program modules; The program code included in the target type program module is determined as a cache type code, and the program code included in the non-target type program module is determined as a non-cache type code.

3. The method according to claim 1 or 2, characterized in that: Before determining the file call identifier according to the calling relationship between the target code in the non-cache type code and the cache type code, the method further includes: According to the program optimization algorithm, identifying the target code in the non-cache type code and the calling relationship corresponding to the target code; the calling relationship includes a passive calling relationship between the target code and the cache type code; Determining, according to the passive calling relationship, a reclassification code passively called in the cache type code; A program entry rule is configured for the reclassified code, and the reclassified code is reclassified into target code in the non-cache type code according to the program entry rule.

4. The method according to claim 1, characterized in that The obtaining of the pre-stored first program optimization file corresponding to the file calling identifier includes: Based on the file call identifier, searching a database for a file carrying the file call identifier; If a file carrying the file call identifier is found, the file is used as the first program optimization file.

5. The method according to claim 4, characterized in that The method further comprises: If no file carrying the file call identifier is found, the cache type code is optimized according to a program optimization algorithm to generate a first program optimization file; The file calling identifier is added to the first program optimization file, and the first program optimization file after the file calling identifier is added is uploaded to the database.

6. The method according to claim 5, characterized in that The step of optimizing the cache type code according to a program optimization algorithm to generate a first program optimization file includes: Analyze and mark the target code contained in the cache type code according to the program optimization algorithm, and delete the unmarked program code in the cache type code; A first program optimization file is constructed based on the target code included in the cache type code.

7. A program code optimization device, characterized in that: include: An acquisition unit, configured to execute acquisition of a program code file to be optimized; A classification unit is configured to divide the program code in the program code file to obtain cache type code and non-cache type code; A processing unit is configured to determine a file call identifier according to a calling relationship between the target code in the non-cache type code and the cache type code, and obtain a first program optimization file corresponding to the file call identifier from a database as an optimization file corresponding to the cache type code; A generating unit is configured to execute a second program optimization file obtained according to the first program optimization file and the target code in the non-cache type code to obtain an optimized program code file; The generating unit is specifically used to delete the marked target code in the non-cache type code after identifying and marking the target code in the non-cache type code based on the program optimization algorithm, so as to obtain a second program optimization file composed of the target code; An optimized program code file is obtained according to the second program optimization file and the obtained first program optimization file.

8. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the program code optimization method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the program code optimization method according to any one of claims 1 to 6.

10. A computer program product, comprising instructions, characterized in that: When the instruction is executed by a processor of an electronic device, the electronic device is enabled to execute the program code optimization method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Software construction method and system based on Flutter

    CN112631600A

  • Code library design method and detection method for rapid whole network code traceability detection

    CN112988217A