Code optimization method and device, equipment and storage medium

By identifying and refactoring duplicate code groups in front-end code and generating code optimization reports, the challenges of front-end code maintenance and management are solved, the maintenance and scalability of the code is improved, maintenance costs are reduced, and development efficiency is improved.

CN119621141APending Publication Date: 2025-03-14CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411503554.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

With the expansion of project scale and the shortening of development cycle, the maintenance and management of front-end code has become a serious challenge, especially due to the problem of duplicate code, which increases the project size, reduces the running efficiency, and affects the maintainability and scalability of the code.

Method used

A code optimization method is proposed, by obtaining the source code file, identifying duplicate code groups, performing code reconstruction, and determining the scope of influence of the refactored code, and finally generating a code optimization report. This method uses abstract syntax tree (AST) and non-whitelisting methods to re-code identification and reconstruction to improve the maintainability and scalability of the code.

Benefits of technology

By identifying and eliminating duplicate code, optimizing code structure, significantly improving code quality, reducing code maintenance costs, improving development efficiency, and enhancing code readability and testability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621141A_ABST
    Figure CN119621141A_ABST
Patent Text Reader

Abstract

The invention discloses a code optimization method and device, equipment and a storage medium, and relates to the technical field of data processing, and the code optimization method comprises the following steps: obtaining a plurality of first source code files; performing duplicated code identification on each first source code file to obtain a plurality of duplicated code groups; performing code reconstruction on each first source code file on the basis of each duplicated code group, and determining a reconstruction code influence range corresponding to each duplicated code group after code reconstruction; and generating a code optimization report based on each duplicate code group and the reconstructed code influence range. According to the method, the duplicated codes are reduced by reconstructing the duplicated codes, and a new code influence range and a new code optimization report are formed, so that the code quality is effectively improved, data decision support is provided for developers, the code maintenance cost is reduced, the development efficiency is improved, and the maintainability and expandability of the codes are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a code optimization method, device, equipment and storage medium. Background Art

[0002] With the rapid development of information technology, front-end development, as an important part of software development, is facing increasing business needs and system complexity. With the expansion of project scale and the shortening of development cycle, the maintenance and management of front-end code has become a severe challenge. In the actual development process, developers often encounter the problem of duplicate code, which not only increases the size of the project and reduces the operating efficiency, but also seriously affects the maintainability and scalability of the code. Summary of the invention

[0003] The main purpose of this application is to provide a code optimization method, device, equipment and storage medium, aiming to solve the maintenance and management problems of front-end code as the project scale expands and the development cycle shortens.

[0004] To achieve the above objectives, the present application proposes a code optimization method, which comprises:

[0005] Obtain several first source code files;

[0006] Performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups;

[0007] Based on each of the repeated code groups, code refactoring is performed on each of the first source code files, and a refactoring code impact range corresponding to each of the repeated code groups after code refactoring is determined;

[0008] A code optimization report is generated based on each of the repeated code groups and the impact scope of the refactored code.

[0009] In one embodiment, the repeated code identification is performed on each of the first source code files to obtain a plurality of repeated code groups, including:

[0010] Parse the source code in each of the first source code files to generate an abstract syntax tree, and obtain a preset number of non-whitelist methods in the second source code file;

[0011] Determine a file duplication rate between each of the first source code files based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file;

[0012] Based on the file repetition rate between the first source code files, a number of repetitive code groups are determined.

[0013] In one embodiment, determining the file duplication rate between the first source code files based on the abstract syntax trees and the non-whitelist methods in the second source code files includes:

[0014] Determine the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determine the source code method corresponding to the non-whitelist method position in each of the first source code files;

[0015] Performing a fuzzy comparison between each of the non-whitelist methods and each of the source code methods to determine whether each of the first source code files contains each of the non-whitelist methods;

[0016] If so, a full comparison is performed between the abstract syntax tree of the second source code file and the abstract syntax tree of the first source code file having each of the non-whitelist methods to determine the file duplication rate of the first source code file.

[0017] In one embodiment, the code refactoring of each of the first source code files based on each of the repeated code groups includes:

[0018] identifying extractable content in each of the repeated code groups;

[0019] Determining a content extraction component corresponding to the extractable content, and loading the content extraction component;

[0020] The extractable content in each of the repeated code groups in each of the first source code files is extracted by the content extraction component, and code reconstruction is performed on each of the first source code files.

[0021] In one embodiment, the extracting the extractable content in each of the repeated code groups in each of the first source code files by the content extraction component and reconstructing the code of each of the first source code files further includes:

[0022] Get the second source code file after code refactoring;

[0023] Performing performance testing and evaluation on the second source code file to obtain a performance evaluation result;

[0024] The performance evaluation results are pushed to the security management personnel for verification.

[0025] In one embodiment, the determining of the refactored code impact range corresponding to each of the repeated code groups after the code refactoring includes:

[0026] Obtaining code call links and code call attributes corresponding to each of the repeated code groups after code refactoring;

[0027] Analyze the call link to obtain a first impact scope, and generate a second impact scope based on the code call attribute;

[0028] The first impact range and the second impact range are associated and combined to generate a reconstructed code impact range corresponding to each of the repeated code groups after code reconstructing.

[0029] In one embodiment, the generating of a code optimization report based on each of the repeated code groups and the impact range of the refactored code includes:

[0030] Obtaining code engineering information corresponding to a plurality of first source code files;

[0031] Based on each of the repeated code groups and the code engineering information, calculate the overall code repetition rate, the code reduction amount and the code engineering load rate, and visualize the overall code repetition rate, the code reduction amount and the code engineering load rate;

[0032] The code engineering information, the visualized overall code repetition rate, the code reduction amount, and the code engineering load rate are associated and combined to generate a code optimization report.

[0033] In addition, to achieve the above purpose, the present application also proposes a code optimization device, which includes:

[0034] An acquisition module, used for acquiring a plurality of first source code files;

[0035] An identification module, used for performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups;

[0036] A reconstruction module, configured to perform code reconstruction on each of the first source code files based on each of the repeated code groups, and determine a reconstructed code impact range corresponding to each of the repeated code groups after code reconstruction;

[0037] A generation module is used to generate a code optimization report based on each of the repeated code groups and the impact range of the refactored code.

[0038] In addition, to achieve the above objectives, the present application also proposes a code optimization device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the code optimization method described above.

[0039] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the code optimization method described above are implemented.

[0040] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the code optimization method described above are implemented.

[0041] The present application provides a code optimization method, apparatus, device and storage medium. The code optimization method obtains a plurality of first source code files, and then identifies duplicate codes for each of the first source code files to obtain a plurality of duplicate code groups. Based on each of the duplicate code groups, code reconstruction is performed on each of the first source code files, and the reconstructed code impact range corresponding to each of the duplicate code groups after code reconstruction is determined. Based on each of the duplicate code groups and the reconstructed code impact range, a code optimization report is generated, thereby effectively improving code quality and providing data decision support for developers, thereby reducing code maintenance costs, improving development efficiency, and effectively improving code maintainability and scalability. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0044] Figure 1 A flowchart of the first embodiment of the code optimization method of this application is provided;

[0045] Figure 2 An example diagram of the code file parsing process provided for the code optimization method of this application;

[0046] Figure 3 An example diagram of merging and removing duplicate file groups provided by the code optimization method of this application;

[0047] Figure 4 An example diagram of the refactoring code flow provided for the code optimization method of this application;

[0048] Figure 5 An example diagram of the visual impact analysis process provided for the code optimization method of this application;

[0049] Figure 6 A brief flowchart of the code optimization method provided for this application.

[0050] Figure 7This is a schematic diagram of the module structure of the code optimization device according to the embodiment of the present application;

[0051] Figure 8 A schematic diagram of the device structure of the hardware operating environment involved in the code optimization method in the embodiment of the present application.

[0052] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0053] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0054] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0055] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a big data service platform, a code optimization system, etc. The following takes the code optimization system as an example to illustrate this embodiment and the following embodiments.

[0056] Based on this, the embodiment of the present application provides a code optimization method, referring to Figure 1 , Figure 1 A flowchart of the first embodiment of the code optimization method of this application is provided.

[0057] In this embodiment, the code optimization method includes steps S11 to S14:

[0058] Step S11, obtaining a plurality of first source code files;

[0059] It should be noted that the first source code file refers to the original source code file involved in the duplicate code identification and reconstruction process, which can be the code files of multiple modules or components in a code engineering project, and is not limited here.

[0060] Step S12, performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups;

[0061] It should be noted that the repeated code group refers to a group of code fragments that are similar or completely the same in structure or function and are found during the repeated code identification process. The repeated code group can be distributed in different source code files, but they are logically repeated and can be optimized through refactoring.

[0062] Specifically, the code source code in each of the first source code files is parsed to generate an abstract syntax tree, and a preset number of non-whitelist methods in the second source code file are obtained, and then based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file, the file repetition rate between each of the first source code files is determined, and thus based on the file repetition rate between each of the first source code files, a number of repeated code groups are determined.

[0063] Step S13, based on each of the repeated code groups, performing code refactoring on each of the first source code files, and determining a refactored code impact range corresponding to each of the repeated code groups after code refactoring;

[0064] It should be noted that the refactored code impact scope refers to the code scope that may be affected after the code is refactored. During the refactoring process, modifying a code snippet may have an impact on other code that depends on the snippet. The purpose of impact scope analysis is to identify all code parts that may be affected, to ensure that potential impacts are fully considered during the refactoring process, and to take corresponding testing and verification measures.

[0065] Specifically, the extractable content in each of the repeated code groups is identified, and then the content extraction component corresponding to the extractable content is determined, and the content extraction component is loaded, so that the extractable content in each of the repeated code groups in each of the first source code files is extracted through the content extraction component, and the code of each of the first source code files is reconstructed.

[0066] Furthermore, the code call links and code call attributes corresponding to each of the repeated code groups after code refactoring are obtained, and then the call links are analyzed to obtain a first impact range, and based on the code call attributes, a second impact range is generated, so that the first impact range and the second impact range are associated and combined to generate a reconstructed code impact range corresponding to each of the repeated code groups after code refactoring.

[0067] Step S14: Generate a code optimization report based on each of the repeated code groups and the impact range of the refactored code.

[0068] It should be noted that the code optimization report refers to a detailed report after optimizing the duplicate code, including the location of the duplicate code in the original source code file, the type of reconstruction, the impact of the reconstruction, and the comparison of code quality before and after optimization, such as performance improvement, reduction in the number of lines of code, etc. There is no restriction here and it can be set according to actual conditions.

[0069] Specifically, code engineering information corresponding to a number of first source code files is obtained, and then based on each of the repeated code groups and the code engineering information, the overall code repetition rate, the code reduction amount, and the code engineering load rate are calculated, and the overall code repetition rate, the code reduction amount, and the code engineering load rate are visualized, so as to associate and combine the code engineering information, the visualized overall code repetition rate, the code reduction amount, and the code engineering load rate to generate a code optimization report.

[0070] This embodiment obtains a number of first source code files, and then identifies duplicate codes for each of the first source code files to obtain a number of duplicate code groups, and then reconstructs the codes of each of the first source code files based on the duplicate code groups, and determines the reconstructed code impact range corresponding to each of the duplicate code groups after code reconstruction, and then generates a code optimization report based on each of the duplicate code groups and the reconstructed code impact range, thereby effectively improving code quality and providing data decision support for developers, thereby reducing code maintenance costs, improving development efficiency, and effectively improving code maintainability and scalability.

[0071] In a feasible implementation manner, the performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups includes:

[0072] Step S21, parsing the source code in each of the first source code files, generating an abstract syntax tree, and obtaining a preset number of non-whitelist methods in the second source code file;

[0073] It should be noted that the code source refers to the original programming language code, that is, the source code written by the developer, which usually contains the program logic, function definition, variable declaration, etc. The Abstract Syntax Tree (AST) is a tree structure used to represent the structure of the source code, where each node of the AST represents a grammatical element in the source code, such as an expression, statement or declaration, thereby capturing the syntax of the code in a structured manner so that it can be analyzed and processed by the program.

[0074] It should be further explained that the second source code file refers to a comparison file randomly selected from each of the first source code files, which is used to extract non-whitelist methods for comparison with the methods in the first source code file to detect repeated or similar code patterns. The preset number refers to a pre-set value for specifying how many non-whitelist methods are extracted from the second source code file for subsequent comparison, which can be set based on experience, project requirements or performance considerations, and is not limited here.

[0075] Furthermore, in code analysis, a whitelist usually refers to code sections that are explicitly marked as allowed to be repeated or do not need to be checked. In contrast, non-whitelist methods are those that are not on the whitelist and need to be checked for duplicate or similar implementations. These methods may appear multiple times in the code base due to business logic or functional requirements.

[0076] Specifically, the code parser is dynamically loaded to parse the code source code in each of the first source code files. At the same time, in order to support multiple file libraries, the tool will dynamically load the corresponding code parser according to different parameters. For example, vue will load vueParsePlugin, react will load reactParsePlugin, and there is no restriction here. In addition, no matter which framework code is used, js and ts parsing plug-ins need to be loaded. For reference, Figure 2 , Figure 2 An example diagram of the code file parsing process provided for the code optimization method of this application.

[0077] Furthermore, the traditional file duplication comparison method is based on comparing the entire file line by line. In-line comments or spaces are often considered non-duplicates, which will cause errors. Therefore, the file comparison plug-in is dynamically loaded to efficiently and accurately identify duplicate code. Based on AST technology, the source code is parsed into an AST tree and then organized into a custom JSON format, thereby greatly improving the accuracy by comparing each field of JSON.

[0078] Step S22, determining a file duplication rate between each of the first source code files based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file;

[0079] It should be noted that the file duplication rate is used to indicate the proportion of duplicate code in two or more source code files, reflecting the degree of code duplication in the code base. A high duplication rate may mean that there is a large amount of duplicate logic in the code base, that is, refactoring is needed to improve the efficiency and maintainability of the code.

[0080] Specifically, the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file is determined, and the source code method corresponding to the non-whitelist method position in each of the first source code files is determined, and then each of the non-whitelist methods is fuzzily compared with each of the source code methods to determine whether each of the first source code files has each of the non-whitelist methods. If so, the abstract syntax tree of the second source code file is fully compared with the abstract syntax tree of the first source code file where each of the non-whitelist methods exists to determine the file repetition rate of the first source code file.

[0081] Step S23: determining a number of repeated code groups based on the file repetition rate between the first source code files.

[0082] Specifically, the file repetition rate between each of the first source code files is compared with a preset repetition threshold range. If the file repetition rate is within the preset repetition threshold range, it is determined that there is a repeated code group in the first source code file corresponding to the file repetition rate, and then the repeated code group existing in the first source code file is determined according to the comparison result of the abstract syntax tree. In one embodiment, the repeated code group is quickly found based on the Union-Find algorithm. In the first step, the node data corresponding to the abstract syntax tree below the preset repetition threshold range is eliminated; in the second step, the same node tree is merged; in the third step, the repeated nodes in the tree are eliminated. For reference, Figure 3 , Figure 3 An example diagram for merging and eliminating duplicate file groups provided for the code optimization method of the present application, specifically, after eliminating the node data corresponding to the abstract syntax tree below the preset repetition threshold range, only the first source code file with a high repetition rate after comparison remains, and there are 4 files A, B, C, and D after the first comparison, and 4 files B, A, E, and F after the first comparison, and 2 files C and D after the first comparison. There are 3 files A, E, and F after the first comparison, and there are 3 files B, E, and F after the first comparison, and then after all the files are merged and the duplicate files are eliminated to improve the analysis efficiency and facilitate code migration and reconstruction. The source code files that ultimately need to be reconstructed are determined by merging the results of multiple comparisons, thereby avoiding the reconstruction complexity caused by reconstructing the code according to the comparison results each time.

[0083] This embodiment parses the source code in each of the first source code files to generate an abstract syntax tree, and obtains a preset number of non-whitelist methods in the second source code file, and then determines the file repetition rate between each of the first source code files based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file, and then determines a number of repeated code groups based on the file repetition rate between each of the first source code files, and then by identifying the repeated code groups, redundancy in the code can be eliminated, making the code base more concise and consistent, thereby helping to improve the readability and maintainability of the code, optimize the development process, and reduce maintenance costs.

[0084] In a feasible implementation manner, the determining the file duplication rate between the first source code files based on the abstract syntax trees and the non-whitelist methods in the second source code files includes:

[0085] Step S31, determining the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determining the source code method corresponding to the non-whitelist method position in each of the first source code files;

[0086] It should be noted that since there are too many code files and the amount of code in code files in general code project projects, full comparison will cause performance problems. Therefore, an optimistic comparison algorithm is used for comparison to shorten the comparison time and improve the comparison efficiency.

[0087] It should be further explained that the non-whitelist method location refers to the starting and ending positions of a specific method (such as a function or class method) in the source code file. In programming, each method has its specific location in the code, which can be determined by the line number, column number or mark in the code. The non-whitelist method location can be used to quickly navigate to a specific part of the code, or to identify a specific code segment when performing code analysis. The source code method refers to the actual method defined in the source code, which includes the method name, parameters, method body and return value, etc. The source code method is a logical unit in a program that can be called to perform a specific function.

[0088] Specifically, determine the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determine the source code method corresponding to the non-whitelist method position in each of the first source code files, for example, traverse the AST of the first source code file, find the method node with the same name and parameter list as the non-whitelist method, and then for each found method, record its non-whitelist method position in the first source code file,

[0089] Step S32, performing fuzzy comparison between each of the non-whitelist methods and each of the source code methods to determine whether each of the first source code files contains each of the non-whitelist methods;

[0090] Specifically, the non-whitelist method position of the non-whitelist method in the second source code file is fuzzily compared with the position of the corresponding method found in the first source code file, that is, the fuzzy algorithm is used to determine whether there is a non-whitelist method. If the position information and the method information match, this indicates that the same or similar methods exist in the two files, which means that there is a high possibility of duplication between the two files.

[0091] Step S33: If yes, then perform a full comparison of the abstract syntax tree of the second source code file with the abstract syntax tree of the first source code file having each of the non-whitelist methods to determine the file duplication rate of the first source code file.

[0092] Specifically, if so, a full comparison is performed on the abstract syntax tree of the second source code file and the abstract syntax tree of the first source code file in which each of the non-whitelist methods exists to determine the file repetition rate of the first source code file. For example, a detailed comparison is performed on the AST nodes of each method in the second source code file and the AST nodes of the corresponding method in the first source code file to check whether the structure, logic and code pattern of the corresponding methods in the two files are similar or identical, and then a specific algorithm (such as edit distance, tree structure similarity algorithm, etc.) is used to quantify the similarity between the two AST nodes, so as to aggregate the similarity scores of all compared nodes to calculate the repetition rate at the entire file level, such as calculating the ratio of the total number of similar node pairs to the total number of all node pairs, or calculating the ratio of the total code amount of similar code blocks to the total code amount of the file, etc., without limitation here, and then the file repetition rate of the first source code file is determined based on the aggregation result.

[0093] Additionally, if each of the first source code files does not have each of the non-whitelist methods, it is determined that the file repetition rate is lower than an expected value, indicating that the file repetition rate between the two methods is low.

[0094] This embodiment determines the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determines the source code method corresponding to the non-whitelist method position in each of the first source code files, and then fuzzily compares each of the non-whitelist methods with each of the source code methods to determine whether each of the first source code files contains each of the non-whitelist methods. If so, a full comparison is performed on the abstract syntax tree of the second source code file and the abstract syntax tree of the first source code file containing each of the non-whitelist methods to determine the file repetition rate of the first source code file. Through fuzzy comparison, logically similar code fragments can be identified when the variable name changes or the code format is slightly different, thereby shortening the comparison time, and further improving development efficiency and reducing resource waste.

[0095] In a feasible implementation manner, the code reconstruction of each of the first source code files based on each of the repeated code groups includes:

[0096] Step S41, identifying extractable content in each of the repeated code groups;

[0097] It should be noted that the extractable content refers to code snippets that appear repeatedly in the source code and are similar in logic or structure. These codes can be identified and extracted and converted into reusable code modules or functions.

[0098] Specifically, to reconstruct and reduce the code repetition rate, it is necessary to identify the extractable content in each of the repeated code groups, wherein the identification and determination can be performed through the comparison results of AST, which is not limited here.

[0099] Step S42, determining a content extraction component corresponding to the extractable content, and loading the content extraction component;

[0100] It should be noted that the content extraction component refers to a tool, library or framework for identifying and extracting reusable code snippets.

[0101] Specifically, determine the content extraction component corresponding to the extractable content, and load the content extraction component, that is, determine the corresponding content extraction component according to the content type of the extractable content. Different front-end frameworks also have different code extraction contents, for example: vue extracts mixin components and common components, reacthooks extracts hooks components and common components, reactclass extracts high-order components and common components, etc. According to different system frameworks, dynamically load file comparison plug-ins and file generation plug-ins. Through code adapters, you can switch between different frameworks without perception, so that subsequent code extraction and code reference can be performed.

[0102] Step S43: extracting extractable content from each of the repeated code groups in each of the first source code files through the content extraction component, and performing code reconstruction on each of the first source code files.

[0103] Specifically, the content extraction component extracts the extractable content in each of the repeated code groups in each of the first source code files, and reconstructs the code of each of the first source code files, such as extracting them into common modules and then referencing them. Figure 4 , Figure 4 An example diagram of the refactored code flow provided for the code optimization method of this application. Figure 4 It demonstrates a refactoring and optimization process for duplicate files in front-end code. First, the system identifies duplicate file groups of different types (such as Vue, React, JS, etc.), and extracts internal and external public methods and properties through file comparison. Then, this information is recorded in a JSON description file to guide the dynamic loading of the corresponding file comparison plug-in. Subsequently, the system generates repaired code based on this data, including business components, high-order components, hooks public methods, static methods and properties, etc., and finally outputs it as an optimized code file, thereby improving the reusability and maintainability of the code.

[0104] In addition, the system can also list repeated code groups, public method attributes obtained after automatic extraction, and optimized code examples, and visualize them. For example, red marks represent attributes with the same name, and the word "same" marks represent that the code is exactly the same. At the same time, clicking on the method name can see how the method is implemented in different files, etc. There is no restriction here, and it can be set according to actual conditions, so that developers can see the amount of code that can be reduced after optimization, the proportion of repeated attributes in each file, which attributes can support extraction, etc., for easy viewing.

[0105] This embodiment identifies the extractable content in each of the repeated code groups, determines the content extraction component corresponding to the extractable content, and loads the content extraction component, thereby extracting the extractable content in each of the repeated code groups in each of the first source code files through the content extraction component, and refactoring the code of each of the first source code files, thereby significantly reducing the repeated code in the code base, so that the codes can be reused in different places, thereby reducing the redundancy of the code, improving the reusability and quality of the code, reducing maintenance costs, and enhancing the readability of the code. At the same time, removing repeated code can reduce the size of the code base, which helps to increase the loading and execution speed of the code, and the refactored code is usually more modular, which is convenient for writing unit tests and improves the test coverage and reliability of the code.

[0106] In a feasible implementation manner, extracting the extractable content in each of the repeated code groups in each of the first source code files by the content extraction component and reconstructing the code of each of the first source code files further includes:

[0107] Step S51, obtaining a second source code file after code reconstruction;

[0108] Step S52, performing performance testing and evaluation on the second source code file to obtain a performance evaluation result;

[0109] It should be noted that the performance evaluation results refer to a series of quantitative data and analysis conclusions obtained after performance testing of the reconstructed source code files, which are used to evaluate the impact of code reconstructing on application performance and ensure that the reconstructing does not introduce negative performance issues. Performance evaluation results usually include the following aspects: Response time: the time required for an application to perform a specific operation, including page loading time, API response time, etc. Processing speed: the speed at which an application processes requests, such as the number of transactions or requests processed per second Resource utilization: the use of system resources when the application is running, including CPU usage, memory usage, disk I / O, and network bandwidth Throughput: the number of requests or data that the system can handle per unit time Concurrency performance: the performance of the system under high concurrency conditions, such as stability and responsiveness when multiple users access the system at the same time Scalability: the performance of the system when the load is increased, and the ability to improve performance by adding resources Stability and reliability: the performance of the system when it is running for a long time or under stress testing, including whether there are crashes, error rates, etc. User experience: from the user's perspective, evaluate whether the performance of the application meets the user's expectations and needs Performance bottlenecks: identify possible performance bottlenecks in the system, such as delays in specific modules or database queries Comparative analysis: compare the performance data before and after reconstruction to show the specific values ​​of performance improvement or decline.

[0110] Specifically, select appropriate performance testing tools according to test requirements, such as JMeter, LoadRunner, Gatling, etc., and then design test scenarios that simulate real user behaviors, including different user loads, usage patterns and test cases, and prepare the test environment to perform performance testing, run the designed test scenarios, collect performance data of the application under different loads, and monitor the application's performance indicators in real time, such as CPU, memory, network and disk usage, analyze the collected performance data, and obtain performance evaluation results.

[0111] Step S53: Push the performance evaluation result to the security management personnel for verification.

[0112] Specifically, the performance evaluation results are pushed to security management personnel for verification, wherein the results can be pushed via electronic display screens, APP pushes, and code editing tools, etc., without limitation herein.

[0113] This embodiment obtains a second source code file after code reconstruction, and then performs performance testing and evaluation on the second source code file to obtain a performance evaluation result, which is then pushed to a security manager for verification, thereby verifying whether the reconstructed code meets the expected performance standards and whether new problems are introduced during the reconstruction process, such as memory leaks, increased response time, etc., so that timely adjustments can be made to improve code quality and ensure the stability and practicality of the reconstructed code.

[0114] In a feasible implementation manner, the determining the reconstructed code impact range corresponding to each of the repeated code groups after the code reconstructing includes:

[0115] Step S61, obtaining the code call links and code call attributes corresponding to each of the repeated code groups after code refactoring;

[0116] It should be noted that the code call link refers to the path of calling another function or method from one function or method during program execution, including all called functions and methods, and the order of their calls. The call link can reveal the dependencies and interaction methods between different components in the program. The code call attributes refer to various attributes related to code calls, such as parameter values, etc.

[0117] Specifically, there are many ways to reference components in the front end: relative path reference, absolute path reference, reference through alias, etc. Due to the influence of different packaging tools and different front-end frameworks, the alias configuration is slightly different. Therefore, in order to smooth out these differences, based on the enhanced-resolve parsing idea, a set of file call relationship parsers is referenced to obtain the code call links corresponding to each repeated code group after code refactoring. First, according to the name of the introduced module, the current file directory is searched first. If it cannot be found, it will continue to search the parent directory one by one until it reaches the node_modules directory under the project root directory. If it cannot be found again, an error is thrown. Then, if the path points to a file, after the path is successfully parsed, the resolver will check whether the path points to a file or directory. If the path has a file extension, it will be used directly, otherwise the extensions option will be used as the file extension to parse. In addition, if the path points to a directory, if the folder contains a package.json file, the fields specified in the mainFields configuration option are searched in order, and the first such field in package.json determines the file path. If the package.json file does not exist or the main field in the package.json file does not return a valid path, the file names specified in the mainFields configuration option are searched in order to see if an existing file name can be matched in the import / require directory. The file extension is parsed in a similar way through the extensions option, so as to obtain the code call links corresponding to the repeated code groups after code refactoring according to this setting.

[0118] Step S62, analyzing the call link to obtain a first impact scope, and generating a second impact scope based on the code call attribute;

[0119] It should be noted that the first impact scope refers to the code impact scope obtained according to the call link, and the second impact scope refers to the code impact scope obtained by analyzing the code call attributes.

[0120] Specifically, the call link is analyzed, that is, the modification path of the reconstructed code is analyzed from the menu to the route, and the first impact range is obtained. The code call attributes, that is, the scene regression of different attributes, are generated to generate the second impact range. Figure 5 , Figure 5 An example diagram of the visual impact analysis process provided for this application code optimization method. Figure 5A process of code refactoring and impact analysis is shown. First, the refactoring modification group files (such as a1.jsx, a2.jsx, etc.) are parsed through the file call relationship parsing plug-in to determine the calling relationship between files. Then, the parsed files are classified into top-level files (such as router.jsx, app.jsx) and non-top-level files (such as pComp.jsx, uComp.jsx). Next, by analyzing the call links and properties of these files, the impact scope of the refactored code is determined, including menu entries, button entries, external links, etc., to evaluate the specific impact of the refactoring on the system, aiming to ensure the safety and effectiveness of code refactoring and reduce the risks brought by refactoring.

[0121] Step S63: Associatively combine the first impact scope and the second impact scope to generate a reconstructed code impact scope corresponding to each of the repeated code groups after code reconstructing.

[0122] This embodiment obtains the code call links and code call attributes corresponding to each of the repeated code groups after code refactoring, and then analyzes the call links to obtain a first impact range, and generates a second impact range based on the code call attributes, thereby associating and combining the first impact range and the second impact range to generate a reconstructed code impact range corresponding to each of the repeated code groups after code refactoring, and then comprehensively analyzes the impact of code refactoring on the entire system, thereby reducing regression errors introduced by refactoring by accurately identifying and testing the impact range, thereby effectively improving the stability of the software, ensuring that the reconstructed code is more robust, and improving the quality of reconstruction.

[0123] In a feasible implementation manner, generating a code optimization report based on each of the repeated code groups and the impact scope of the refactored code includes:

[0124] Step S71, obtaining code engineering information corresponding to a plurality of first source code files;

[0125] It should be noted that the code engineering information refers to detailed information about the entire code base or project, including the project name, version and description, the size and complexity indicators of the code base, such as the number of lines of code (LOC), the organizational structure of different modules or components in the code base, the programming language and technology stack of the code base, etc.

[0126] Specifically, the code engineering information corresponding to several first source code files is obtained, which can be obtained through the data collection method that is not sensed by the host application, such as integrating data collection slots in file comparison, auxiliary optimization and other plug-ins, and then executing the git remote-v command through the node's exec method during the data collection process, and trying to obtain the Git project name as the project number, and the git log command to obtain the last commitId as the code version number, and then data cleaning and analysis based on data isolation: In the process of reporting data, the last commitId obtained by git log will be compared with the previous commitId, and the same commitId data will be cleaned. In addition, the data submitted by different branches will be processed in isolation.

[0127] Step S72, based on each of the repeated code groups and the code engineering information, calculating the overall code repetition rate, the code reduction amount and the code engineering load rate, and visualizing the overall code repetition rate, the code reduction amount and the code engineering load rate;

[0128] It should be noted that the overall code duplication rate refers to the proportion of repeated code in the entire code base. The code reduction refers to the reduction in the code base volume after refactoring and optimizing the code. The code engineering load rate refers to an indicator that measures the difficulty and complexity of code base maintenance, including multiple aspects, such as: code complexity, such as cyclomatic complexity; code dependencies and coupling; the proportion of legacy code or technical debt in the code base, etc.

[0129] Specifically, the code engineering information and data of repeated code groups are collected, and then the overall code repetition rate, code reduction, code engineering load rate and other data are calculated, without limitation, and then the data is visualized, such as using charts, graphs and dashboards to visualize the repetition rate, reduction and load rate, and generate a single project liability behavior trend chart, a single project code load rate trend effect chart, etc.

[0130] Step S73, the code engineering information, the visualized overall code repetition rate, the code reduction amount and the code engineering load rate are associated and combined to generate a code optimization report.

[0131] Specifically, according to a preset report template, the code engineering information, the visualized overall code repetition rate, the code reduction amount and the code engineering load rate are associated and combined and then adapted to the preset report template to generate a code optimization report.

[0132] This embodiment obtains code engineering information corresponding to a number of first source code files, and then calculates the overall code repetition rate, code reduction amount, and code engineering load rate based on each of the repeated code groups and the code engineering information, and visualizes the overall code repetition rate, the code reduction amount, and the code engineering load rate, thereby associating and combining the code engineering information, the visualized overall code repetition rate, the code reduction amount, and the code engineering load rate to generate a code optimization report, thereby providing intuitive data support, helping the team to understand the efficiency of project resource allocation, optimize development resources, and increase the readability and maintainability of the overall code after code optimization through analysis reports.

[0133] For example, to help understand the implementation process of the code optimization method, please refer to Figure 6 , Figure 6 A brief flowchart of the code optimization method provided for this application.

[0134] It should be noted that the examples in the figure are only used to understand the present application and do not constitute a limitation on the code optimization method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0135] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0136] This application also provides a code optimization device, please refer to Figure 7 , the code optimization device comprises:

[0137] An acquisition module 71, used to acquire a plurality of first source code files;

[0138] An identification module 72, used for performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups;

[0139] A reconstruction module 73, configured to perform code reconstruction on each of the first source code files based on each of the repeated code groups, and determine a reconstructed code impact range corresponding to each of the repeated code groups after code reconstruction;

[0140] The generating module 74 is used to generate a code optimization report based on each of the repeated code groups and the impact scope of the refactored code.

[0141] The code optimization device is also used for:

[0142] Parse the source code in each of the first source code files to generate an abstract syntax tree, and obtain a preset number of non-whitelist methods in the second source code file;

[0143] Determine a file duplication rate between each of the first source code files based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file;

[0144] Based on the file repetition rate between the first source code files, a number of repetitive code groups are determined.

[0145] The code optimization device is also used for:

[0146] Determine the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determine the source code method corresponding to the non-whitelist method position in each of the first source code files;

[0147] Performing a fuzzy comparison between each of the non-whitelist methods and each of the source code methods to determine whether each of the first source code files contains each of the non-whitelist methods;

[0148] If so, a full comparison is performed between the abstract syntax tree of the second source code file and the abstract syntax tree of the first source code file having each of the non-whitelist methods to determine the file duplication rate of the first source code file.

[0149] The code optimization device is also used for:

[0150] identifying extractable content in each of the repeated code groups;

[0151] Determining a content extraction component corresponding to the extractable content, and loading the content extraction component;

[0152] The extractable content in each of the repeated code groups in each of the first source code files is extracted by the content extraction component, and code reconstruction is performed on each of the first source code files.

[0153] The code optimization device is also used for:

[0154] Get the second source code file after code refactoring;

[0155] Performing performance testing and evaluation on the second source code file to obtain a performance evaluation result;

[0156] The performance evaluation results are pushed to the security management personnel for verification.

[0157] The code optimization device is also used for:

[0158] Obtaining code call links and code call attributes corresponding to each of the repeated code groups after code refactoring;

[0159] Analyze the call link to obtain a first impact scope, and generate a second impact scope based on the code call attribute;

[0160] The first impact range and the second impact range are associated and combined to generate a reconstructed code impact range corresponding to each of the repeated code groups after code reconstructing.

[0161] The code optimization device is also used for:

[0162] Obtaining code engineering information corresponding to a plurality of first source code files;

[0163] Based on each of the repeated code groups and the code engineering information, calculate the overall code repetition rate, the code reduction amount and the code engineering load rate, and visualize the overall code repetition rate, the code reduction amount and the code engineering load rate;

[0164] The code engineering information, the visualized overall code repetition rate, the code reduction amount, and the code engineering load rate are associated and combined to generate a code optimization report.

[0165] The code optimization device provided by the present application adopts the code optimization method in the above embodiment, and can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the code optimization device provided by the present application are the same as the beneficial effects of the code optimization method provided by the above embodiment, and the other technical features in the code optimization device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0166] The present application provides a code optimization device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code optimization method in the above-mentioned embodiment 1.

[0167] Reference below Figure 8 , which shows a schematic diagram of the structure of a code optimization device suitable for implementing an embodiment of the present application. The code optimization device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 8 The code optimization device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0168] like Figure 8 As shown, the code optimization device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the code optimization device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the code optimization device to communicate with other devices wirelessly or by wire to exchange data. Although the code optimization device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0169] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0170] The code optimization device provided by the present application adopts the code optimization method in the above embodiment to solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the code optimization device provided by the present application are the same as the beneficial effects of the code optimization method provided by the above embodiment, and the other technical features in the code optimization device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0171] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0172] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0173] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the code optimization method in the above-mentioned embodiment.

[0174] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0175] The computer-readable storage medium may be included in the code optimization device; or may exist independently without being assembled into the code optimization device.

[0176] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the code optimization device, the code optimization device:

[0177] Obtain several first source code files;

[0178] Performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups;

[0179] Based on each of the repeated code groups, code refactoring is performed on each of the first source code files, and a refactoring code impact range corresponding to each of the repeated code groups after code refactoring is determined;

[0180] A code optimization report is generated based on each of the repeated code groups and the impact scope of the refactored code.

[0181] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0182] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0183] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0184] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned code optimization method, and can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the code optimization method provided in the above-mentioned embodiment, and will not be repeated here.

[0185] An embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the above-mentioned code optimization method when executed by a processor.

[0186] The computer program product provided in this application can solve the technical problems in the background technology. Compared with the prior art, the beneficial effects of the computer program product provided in the embodiment of this application are the same as the beneficial effects of the code optimization method provided in the above embodiment, which will not be repeated here.

[0187] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A code optimization method, characterized in that: include: Obtain several first source code files; Performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups; Based on each of the repeated code groups, code refactoring is performed on each of the first source code files, and an impact range of the refactored code corresponding to each of the repeated code groups after code refactoring is determined; A code optimization report is generated based on each of the repeated code groups and the impact scope of the refactored code.

2. The code optimization method according to claim 1, characterized in that: The step of performing duplicate code identification on each of the first source code files to obtain a plurality of duplicate code groups includes: Parse the source code in each of the first source code files to generate an abstract syntax tree, and obtain a preset number of non-whitelist methods in the second source code file; Determine a file duplication rate between each of the first source code files based on each of the abstract syntax trees and each of the non-whitelist methods in the second source code file; Based on the file repetition rate between the first source code files, a number of repetitive code groups are determined.

3. The code optimization method according to claim 2, characterized in that: The determining the file duplication rate between the first source code files based on the abstract syntax trees and the non-whitelist methods in the second source code files includes: Determine the non-whitelist method position corresponding to each of the non-whitelist methods in the second source code file, and determine the source code method corresponding to the non-whitelist method position in each of the first source code files; Performing a fuzzy comparison between each of the non-whitelist methods and each of the source code methods to determine whether each of the first source code files contains each of the non-whitelist methods; If so, a full comparison is performed between the abstract syntax tree of the second source code file and the abstract syntax tree of the first source code file having each of the non-whitelist methods to determine the file duplication rate of the first source code file.

4. The code optimization method according to claim 1, characterized in that: The refactoring of each of the first source code files based on each of the repeated code groups includes: identifying extractable content in each of the repeated code groups; Determining a content extraction component corresponding to the extractable content, and loading the content extraction component; The extractable content in each of the repeated code groups in each of the first source code files is extracted by the content extraction component, and code reconstruction is performed on each of the first source code files.

5. The code optimization method according to claim 4, characterized in that: After extracting the extractable content in each of the repeated code groups in each of the first source code files by the content extraction component and reconstructing the code of each of the first source code files, the method further includes: Get the second source code file after code refactoring; Performing performance testing and evaluation on the second source code file to obtain a performance evaluation result; The performance evaluation results are pushed to the security management personnel for verification.

6. The code optimization method according to claim 1, characterized in that: The determining of the reconstructed code impact scope corresponding to each of the repeated code groups after the code reconstructing includes: Obtaining code call links and code call attributes corresponding to each of the repeated code groups after code refactoring; Analyze the call link to obtain a first impact scope, and generate a second impact scope based on the code call attribute; The first impact range and the second impact range are associated and combined to generate a reconstructed code impact range corresponding to each of the repeated code groups after code reconstructing.

7. The code optimization method according to claim 1, characterized in that: The generating of a code optimization report based on each of the repeated code groups and the impact scope of the refactored code includes: Obtain code engineering information corresponding to a plurality of first source code files; Based on each of the repeated code groups and the code engineering information, calculate the overall code repetition rate, the code reduction amount and the code engineering load rate, and visualize the overall code repetition rate, the code reduction amount and the code engineering load rate; The code engineering information, the visualized overall code repetition rate, the code reduction amount, and the code engineering load rate are associated and combined to generate a code optimization report.

8. A code optimization device, characterized in that: include: An acquisition module, used for acquiring a plurality of first source code files; An identification module, used for performing repeated code identification on each of the first source code files to obtain a plurality of repeated code groups; A refactoring module, configured to refactor the first source code files based on the repeated code groups, and determine a refactored code impact range corresponding to the repeated code groups after code refactoring; A generation module is used to generate a code optimization report based on each of the repeated code groups and the impact range of the refactored code.

9. A code optimization device, characterized in that: The code optimization device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the code optimization method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the code optimization method according to any one of claims 1 to 7 are implemented.