Artificial intelligence-based code performance optimization method, device and system

By using an AI-driven analysis and coding agent generation optimization scheme, combined with a self-evolving experience base, the problem of poor code performance optimization in existing technologies is solved, achieving more efficient and accurate code optimization.

CN122220201APending Publication Date: 2026-06-16BEIJING BAIDU NETCOM SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING BAIDU NETCOM SCI & TECH CO LTD
Filing Date
2026-02-02
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Existing technologies have limited effectiveness in code performance optimization and struggle to achieve comprehensive and accurate optimization solutions.

Method used

An artificial intelligence-based approach is adopted. By analyzing the source code information and historical experience knowledge of the target optimization object, the intelligent agent generates optimization scheme description information, and the coding intelligent agent generates code patches. The performance verification engine is used for verification, and finally the historical experience knowledge is updated through a self-evolving experience base.

Benefits of technology

It improves the comprehensiveness and accuracy of code performance optimization, simplifies the optimization process, reduces manpower input, and ensures the effectiveness of optimization solutions in real-world environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122220201A_ABST
    Figure CN122220201A_ABST
Patent Text Reader

Abstract

The present disclosure provides an artificial intelligence-based code performance optimization method, device, system, equipment, medium and product, relating to the technical field of artificial intelligence, and in particular to the technical field of large models, agents, cloud computing and the like. The artificial intelligence-based code performance optimization method comprises: analyzing the running performance data of a target service to determine a target optimization object; using an analysis agent to obtain source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and the historical experience knowledge; using a coding agent to generate a code patch based on the optimization scheme description information; verifying based on the code patch to obtain a verification result; obtaining current experience knowledge based on the verification result, and updating the historical experience knowledge based on the current experience knowledge. The present disclosure can improve the code performance optimization effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of artificial intelligence technology, particularly to the fields of large models, intelligent agents, and cloud computing, and specifically to a method, apparatus, system, device, medium, and product for optimizing code performance based on artificial intelligence. Background Technology

[0002] Code performance optimization refers to the process of improving the operational efficiency of a service and reducing resource consumption, while ensuring the correctness, readability, and maintainability of the code, so that the service can complete its intended tasks in a better state. Summary of the Invention

[0003] This disclosure provides a method, apparatus, system, device, medium, and product for optimizing code performance based on artificial intelligence.

[0004] According to one aspect of this disclosure, an artificial intelligence-based code performance optimization method is provided, comprising: analyzing the runtime performance data of a target service to determine a target optimization object; employing an analytical agent to obtain source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and historical experience knowledge; employing a coding agent to generate code patches based on the optimization scheme description information; verifying the code patches to obtain verification results; obtaining current experience knowledge based on the verification results, and updating the historical experience knowledge based on the current experience knowledge.

[0005] According to another aspect of this disclosure, an artificial intelligence-based code performance optimization apparatus is provided, comprising: an analysis module for analyzing the runtime performance data of a target service to determine a target optimization object; a first generation module for using an analysis agent to obtain source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and historical experience knowledge; a second generation module for using a coding agent to generate a code patch based on the optimization scheme description information; a verification module for verifying the code patch to obtain a verification result; and an update module for obtaining current experience knowledge based on the verification result, and updating the historical experience knowledge based on the current experience knowledge.

[0006] According to another aspect of this disclosure, an artificial intelligence-based code performance optimization system is provided, comprising: an analyzer for analyzing the runtime performance data of a target service to determine a target optimization object; an analysis agent for acquiring source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and historical experience knowledge; an encoding agent for generating code patches according to the optimization scheme description information; a performance verification engine for verifying the code patches to obtain verification results; and a self-evolving experience base for acquiring current experience knowledge based on the verification results and updating the historical experience knowledge based on the current experience knowledge.

[0007] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to said at least one processor; wherein the memory stores instructions executable by said at least one processor, said instructions being executed by said at least one processor to enable said at least one processor to perform the method as described in any of the foregoing aspects.

[0008] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method according to any of the preceding aspects.

[0009] According to another aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method according to any of the preceding aspects.

[0010] According to embodiments of this disclosure, code performance optimization can be improved.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0012] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0013] Figure 1 This is a schematic diagram based on the first embodiment of the present disclosure;

[0014] Figure 2 This is a schematic diagram of the overall architecture provided according to embodiments of this disclosure;

[0015] Figure 3 This is a schematic diagram according to the second embodiment of the present disclosure;

[0016] Figure 4 This is a schematic diagram according to the third embodiment of the present disclosure;

[0017] Figure 5 This is a schematic diagram according to the fourth embodiment of the present disclosure;

[0018] Figure 6 This is a schematic diagram of an electronic device used to implement the code performance optimization method of the embodiments of this disclosure. Detailed Implementation

[0019] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0020] Among related technologies, performance monitoring tools and static code analysis can be used to optimize code performance, but the optimization effect needs to be improved.

[0021] Figure 1 This is a schematic diagram based on the first embodiment of the present disclosure. This embodiment provides a code performance optimization method based on artificial intelligence. Figure 1 As shown, the method includes:

[0022] 101. Analyze the runtime performance data of the target service to determine the target optimization object.

[0023] 102. Using an analytical agent, obtain source code information and historical experience knowledge associated with the target optimization object, and generate optimization scheme description information based on the source code information and historical experience knowledge.

[0024] 103. Using an coded intelligent agent, generate code patches based on the description information of the optimization scheme.

[0025] 104. Verify based on the code patch to obtain the verification results.

[0026] 105. Obtain current experience knowledge based on the verification results, and update the historical experience knowledge based on the current experience knowledge.

[0027] In this context, the target service refers to the service to be optimized. In cloud computing scenarios, applications typically contain multiple microservices, and some or all of these microservices can be used as the target service.

[0028] Runtime performance data refers to performance-related data of the target service during runtime, specifically flame graphs. Assuming the target service comprises N (positive integer) microservices, N flame graphs can be obtained, each corresponding to one microservice. A flame graph is a visual chart of runtime performance data, primarily used to intuitively locate performance bottlenecks, such as function execution time and resource hotspots. It is widely used in backend services, system maintenance, and performance optimization scenarios.

[0029] The target optimization object refers to the object to be optimized. For example, performance data can be represented by a flame graph, which can characterize the frequency of function stack occurrences. Based on this, a predetermined number of function stacks with high occurrence frequencies can be selected as target optimization objects. Assuming that M (positive integer) function stacks are selected for each target service, then the target optimization objects include N*M function stacks, where * represents multiplication.

[0030] An agent is an autonomous entity driven by a large language model (LLM). It has the ability to plan, remember, invoke tools, and learn, and can autonomously complete complex tasks.

[0031] The analytical agent is used to generate descriptions of optimization solutions.

[0032] A coding agent used to generate code patches.

[0033] After identifying the target optimization object, the target optimization object is input into the analysis agent. The analysis agent analyzes the target optimization object based on the source code information associated with it and the historical experience knowledge in the knowledge base, and outputs the optimization scheme description information.

[0034] Taking the function stack as an example, the source code segment corresponding to the function stack and the context information of the source code segment can be obtained, and the source code segment and its context information can be used as the source code information associated with the function stack.

[0035] Historical experience knowledge can be pre-stored in a knowledge base, and the analytical agent can obtain historical experience knowledge related to the function stack from the knowledge base.

[0036] The optimization scheme description information is in natural language, such as "using SIMD instructions for parallel comparison to reduce memory copying and comparison operations," rather than directly generating code. Based on N*M target optimization objects, N*M*K optimization scheme description information can be obtained, where K is a preset positive integer.

[0037] After the analytical agent obtains the description information of the optimization scheme, it inputs it into the coding agent, which then generates code patches based on the optimization scheme description information. Based on N*M*K optimization scheme descriptions, N*M*K code patches can be obtained.

[0038] Code patches are used to represent source code snippets before and after optimization, and are usually in the form of diff files.

[0039] After obtaining the code patch, it is verified. For example, based on the code patch, the corresponding runtime performance metrics of the source code before and after optimization are obtained, and then the optimized values ​​of the corresponding metrics are obtained as the verification results. The optimized value of the above-mentioned metric is, for example, a reduction in CPU utilization, such as a 5% reduction.

[0040] Based on the verification results, current experiential knowledge can be obtained. This current experiential knowledge can include relevant data corresponding to positive and negative samples. For example, when the optimization value is greater than a preset threshold, the corresponding code patch is considered a positive sample; otherwise, it is considered a negative sample. The structured data of the positive and negative samples are stored in the experience base as current experiential knowledge for subsequent processes. The structured data of positive and negative samples can be the same or different. For example, the structured data of positive samples can include problem feature vectors, source code patterns, and optimization scheme descriptions, while the structured data of negative samples can include problem feature vectors, failed code, and reasons for failure.

[0041] In this embodiment, by determining the target optimization object, generating optimization scheme description information, generating code patches, generating verification results, and updating historical experience knowledge, a comprehensive optimization scheme involving perception, decision-making, coding, verification, and evolution can be achieved. Compared with optimization schemes that only focus on a single point, this can improve the comprehensiveness and accuracy of the processing, thereby enhancing the code performance optimization effect.

[0042] Figure 2 This is a schematic diagram of the overall architecture provided according to embodiments of this disclosure.

[0043] In this embodiment, flame graphs are used as an example to illustrate the performance data.

[0044] like Figure 2 As shown, the overall system 200 includes: a flame graph analyzer 201, an analysis agent 202, an encoding agent 203, a performance verification engine 204, and a self-evolving experience base 205.

[0045] Flame graph analyzer 201 is used to analyze the flame graphs of target services to obtain a preset number of target function stacks. For example, if there are N target services, the input of the flame graph analyzer is N flame graphs, and after analyzing them, N*M target function stacks are determined.

[0046] Analysis agent 202 is used to analyze N*M objective function stacks to obtain N*M*K optimization scheme description information.

[0047] The flame graph analyzer obtains N*M objective function stacks and stores them in memory. The analysis agent can traverse these stacks, selecting one objective function stack for analysis each time. For each objective function stack, it obtains K optimization scheme descriptions, resulting in a total of N*M*K optimization scheme descriptions.

[0048] For each objective function stack, the analysis agent can obtain the corresponding source code fragment and context from the code repository through the source code retrieval engine, as well as relevant historical experience knowledge from the experience repository. Based on the source code fragment, context, and historical experience knowledge, the agent obtains the description information of the optimization scheme.

[0049] Encoded agent 203 is used to generate code patches corresponding to the description information of the optimization scheme.

[0050] The analysis agent can store N*M*K optimization scheme descriptions in memory, and the encoding agent iterates through them, selecting one optimization scheme description each time to generate code, resulting in N*M*K code patches.

[0051] The performance verification engine 204 is used to verify code patches and obtain verification results.

[0052] The coding agent generates a code patch and then inputs it into the performance verification engine. The performance verification engine can create a verification sandbox and use pre-recorded real traffic to perform verification based on the code patch within the verification sandbox to obtain the verification result.

[0053] Self-evolving experience base 205 is used to update experiential knowledge and provide it to analytical agents.

[0054] Based on the above architecture, this disclosure can also provide the following embodiments.

[0055] Figure 3 This is a schematic diagram based on a second embodiment of the present disclosure, which provides a code performance optimization method. For example... Figure 3 As shown, the method includes:

[0056] 301. Use a flame graph analyzer to analyze the flame graph of the target service and obtain the target function stack.

[0057] 302. Employ an analytical agent to obtain source code information and historical experience knowledge associated with the target function stack, and generate optimization scheme description information based on the source code information and historical experience knowledge.

[0058] 303. Employ an intelligent coding agent to generate code patches based on the description information of the optimization scheme.

[0059] 304. Using a performance verification engine, verification is performed based on the code patch to obtain the verification results.

[0060] 305. Using a self-evolving experience base, obtain current experience knowledge based on the verification results, and update the historical experience knowledge based on the current experience knowledge.

[0061] The specific steps are explained below:

[0062] In some embodiments, the runtime performance data includes a flame graph containing the frequency of occurrence of multiple candidate function stacks corresponding to the target service;

[0063] The analysis of the target service's runtime performance data to determine the target optimization object includes:

[0064] Based on the frequency of occurrence, a predetermined number of target function stacks are selected from the plurality of candidate function stacks as the target optimization objects.

[0065] For example, if there are N target services, the input to the flame graph analyzer is N flame graphs, each flame graph corresponding to a target service. Assuming the preset number is M (a positive integer), after analyzing the N flame graphs, N*M target function stacks are obtained, where * indicates multiplication.

[0066] Specifically, for each flame graph, the frequency of occurrence of each candidate function stack in the flame graph can be obtained. If the frequency of occurrence of a candidate function stack is greater than a preset frequency threshold, the candidate function stack is regarded as a suspected hot spot. Then, the suspected hot spots can be filtered. For example, by introducing a whitelist, the function stacks corresponding to operating system kernel calls and known unoptimizable underlying framework code can be filtered out, while the suspected hot spots of business logic layer and middleware call layer are retained. Among the remaining suspected hot spots, M function stacks are selected as target function stacks in descending order of frequency of occurrence.

[0067] In this embodiment, by analyzing the flame graph, the target function stack that appears frequently is taken as the target optimization object, which can be obtained simply and efficiently.

[0068] In some embodiments, the step of employing an analytical agent to obtain source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and historical experience knowledge, includes:

[0069] An analytical agent is used to analyze the target optimization object in order to determine the runtime symbol of the target optimization object;

[0070] The analytical agent is used to send the runtime symbols to the source code retrieval engine, so that the source code retrieval engine can obtain source code fragments and context information based on the runtime symbols, as the source code information;

[0071] The analytical agent is used to obtain feature data of the target optimization object, and the historical experience knowledge is obtained based on the feature data.

[0072] The analytical agent is used to perform reasoning based on the source code information and historical experience knowledge to obtain the description information of the optimization scheme.

[0073] Taking the target function stack as an example of the target optimization object, the analysis agent can obtain the target function stack from memory. After obtaining the target function stack, the analysis agent will determine whether more source code information is needed. If so, it will tell the source code retrieval engine to extract the required runtime symbols such as functions, classes, and variables. The source code retrieval engine will precisely map these runtime symbols to specific file paths, class definitions, and line number ranges in the code library by parsing the project's Abstract Syntax Tree (AST) or symbol table. Based on this information, the corresponding source code fragments will be obtained. Furthermore, to enable the large model to understand the context of local code, the source code retrieval engine will not only search the code of the target function but also recursively search the key implementation logic of its "caller" and the variable types at the "definition point" as context information for the source code fragments.

[0074] After obtaining the aforementioned source code fragments and context information, the source code retrieval engine assembles them according to the preset prompt template, obtains the corresponding prompt information, and sends it to the analysis agent.

[0075] The analytical agent can perform inference based on the Retrieval Augmented Generation (RAG) mechanism. Specifically, before inference, it can perform analysis based on preset rules or a large model to obtain feature data of the target function stack. The feature data is used to characterize key information of the target function stack, such as "high time consumption for HashMap resizing" and "lock contention". After vectorizing the feature data, similarity retrieval is performed in the experience base to obtain successful optimization cases in similar scenarios (such as "replacing ArrayList with LinkedList" or "adding cache") as associated historical experience knowledge.

[0076] The analytical agent, combining the aforementioned source code snippets, context, and historical experience, performs chain-of-thought reasoning to obtain information describing the optimization solution. The specific chain-of-thought reasoning process may include the following multi-step reasoning:

[0077] Step 1 (Source Code Request): This step may require multiple steps. It depends on whether the source code obtained so far is sufficient to derive an optimization plan. If not, continue to request source code from the source code retrieval engine.

[0078] Step 2 (Solution Generation): After obtaining enough source code fragments, provide descriptions of K optimization schemes for each target function stack.

[0079] The output of the analytical agent is an optimization scheme description, not direct code generation. This description is in natural language, such as: "Use the Google Protobuf Arena memory allocator to optimize the creation of XMessage structures," or "Use SIMD instructions for parallel comparisons to reduce memory copying and comparison operations." This description is stored in memory and then passed to the coding agent.

[0080] In this embodiment, the analysis agent combines the context of source code fragments for analysis. The large model no longer relies solely on guessing from local code fragments, but instead performs deep architecture-level optimization based on the complete call chain and runtime hotspot information, thereby improving the optimization effect.

[0081] After obtaining the optimization scheme description information from memory, the coding agent converts it into an executable code patch that conforms to the syntax rules. Specifically, this may include the following:

[0082] (1) Solution translation: The coding agent reads the "optimization solution description information" and the corresponding original code from memory. It follows the syntax rules of the target programming language (such as Java, C++, Go) and generates specific code modification differences.

[0083] (2) Static compliance check: Before the generated code patch is output, it will pass through the built-in lightweight static syntax checker (Linter) to ensure that there are no obvious syntax errors or missing imports, and to ensure that the generated patch can be accepted by the compilation system.

[0084] (3) Output code Patch: Finally, a standard format Git Patch file is generated, ready to enter the verification stage.

[0085] Specifically, based on a preset template, the optimization scheme description information, the target function stack, the source code information, and the instructions for code optimization can be concatenated to obtain a prompt message, which is then sent to the coding agent. The coding agent generates a code patch based on this prompt message.

[0086] In some embodiments, the verification based on the code patch to obtain a verification result includes:

[0087] Create a verification sandbox, compile the initial source code corresponding to the target service within the verification sandbox to obtain initial executable code, and obtain the target source code based on the code patch and the initial source code, compile the target source code to obtain target executable code;

[0088] Within the validation sandbox, the baseline container and the optimization container are launched;

[0089] Within the benchmark container, the initial executable code is used to process real traffic to obtain benchmark performance metrics.

[0090] Within the optimization container, the target executable code is used to process the real traffic in order to obtain optimized performance metrics.

[0091] Based on the benchmark performance index and the optimized performance index, the optimized value of the performance index is obtained as the verification result.

[0092] The performance verification engine performs verification based on code patches, mainly including:

[0093] (1) Sandbox Environment Construction: Dynamically launch an isolated verification sandbox, automatically pull the base branch code, and apply the code patches generated by the coding agent to perform compilation and build. If compilation fails, the "failure feedback" process is triggered directly. The compilation results are published as a window image, and the base container and optimization container are started in the sandbox environment.

[0094] (2) Traffic replay: The verification engine connects to the production environment's traffic recording system, captures real business traffic segments, and replays them in the two containers mentioned above in the sandbox. This ensures a high degree of consistency between the verification scenario and the real production environment, avoiding test bias caused by synthetic data.

[0095] (3) A / B performance comparison: During the traffic replay, the performance indicators in each container of the sandbox are collected in real time, such as code execution time and CPU consumption flame graph, so as to obtain the baseline performance indicators (such as baseline CPU consumption rate) and the optimized performance indicators (such as optimized CPU consumption rate). The difference between the two is used as the performance indicator optimization value. For example, after subtracting the two, the CPU consumption rate is reduced by 5%, and this 5% is the performance indicator optimization value.

[0096] (4) Verification result: The verification result is determined based on the optimized value of the performance index. If the optimized value of the performance index (such as 5% mentioned above) is greater than or equal to the preset threshold, the verification result is "verification successful"; otherwise, the verification result is "verification failed".

[0097] In this embodiment, A / B testing and performance comparison of the optimized code are performed using real production traffic in an isolated environment. This enables automated verification, compressing the original manual "modification-compilation-deployment-stress testing" process, which would have taken several days, into minutes, greatly reducing manpower requirements. By replaying real traffic, it is ensured that the surviving optimization solutions are effective in real production scenarios, avoiding the off-target problem of static rules.

[0098] After obtaining the verification results, the current experience knowledge can be obtained based on the verification results, and the historical experience knowledge can be updated using the current experience knowledge.

[0099] In some embodiments, obtaining current experiential knowledge based on the verification result and updating the historical experiential knowledge based on the current experiential knowledge includes:

[0100] If the verification result is successful, the code patch is used as a positive sample, and the structured data of the positive sample is obtained; if the verification result is unsuccessful, the code patch is used as a negative sample, and the structured data of the negative sample is obtained.

[0101] The positive sample structured data and / or the negative sample structured data are used as the current experiential knowledge to update the historical experiential knowledge.

[0102] A self-evolving experience base enables the self-evolution of experiential knowledge, and mainly includes:

[0103] (1) Structured accumulation: Regardless of whether the performance verification engine is successful or not, the system will write the complete case metadata into the experience library.

[0104] Positive samples (successful cases): Store {problem feature vector, source code pattern, optimization strategy, performance gain}. This reinforces the system's memory of the correct optimization path.

[0105] Negative samples (failure cases): Store {problem feature vector, failure code, reason for failure (e.g., performance degradation, increased computing power consumption)}. This helps the system avoid the same error pitfalls when making future decisions.

[0106] (2) Knowledge feedback: The experience base is connected to the analysis agent in real time through the vector index interface. As the running time goes on, the more high-quality cases are accumulated in the experience base, the more accurate the "intuition" of the analysis agent when facing new services and new code becomes, thus realizing the self-evolution of the system.

[0107] The experience base can specifically be a vector database that stores successful (positive samples) and unsuccessful (negative samples) cases of each optimization, and transforms posterior knowledge into prior experience for the next decision through the RAG mechanism.

[0108] In this embodiment, by labeling positive and negative samples, logical errors or negative performance optimizations that may arise from general large models are effectively intercepted, ensuring the safety of code changes. Furthermore, by obtaining structured data from positive and negative samples and updating experiential knowledge, knowledge accumulation and self-evolution can be achieved.

[0109] Figure 4 This is a schematic diagram according to the third embodiment of the present disclosure. This embodiment provides a code performance optimization device based on artificial intelligence. The device 400 includes: an analysis module 401, a first generation module 402, a second generation module 403, a verification module 404, and an update module 405.

[0110] Analysis module 401 is used to analyze the runtime performance data of the target service in order to determine the target optimization object;

[0111] The first generation module 402 is used to employ an analytical agent to obtain source code information and historical experience knowledge associated with the target optimization object, and to generate optimization scheme description information based on the source code information and historical experience knowledge.

[0112] The second generation module 403 is used to generate code patches based on the optimization scheme description information using a coding intelligent agent.

[0113] Verification module 404 is used to perform verification based on the code patch to obtain a verification result;

[0114] The update module 405 is used to obtain the current experience knowledge based on the verification result and update the historical experience knowledge based on the current experience knowledge.

[0115] In this embodiment, by determining the target optimization object, generating optimization scheme description information, generating code patches, generating verification results, and updating historical experience knowledge, a comprehensive optimization scheme involving perception, decision-making, coding, verification, and evolution can be achieved. Compared with optimization schemes that only focus on a single point, this can provide the comprehensiveness and accuracy of the processing process, thereby improving the code performance optimization effect.

[0116] In some embodiments, the runtime performance data includes a flame graph containing the frequency of occurrence of multiple candidate function stacks corresponding to the target service;

[0117] Analysis module 401 is further used for:

[0118] Based on the frequency of occurrence, a predetermined number of target function stacks are selected from the plurality of candidate function stacks as the target optimization objects.

[0119] In this embodiment, by analyzing the flame graph, the target function stack that appears frequently is taken as the target optimization object, which can be obtained simply and efficiently.

[0120] In some embodiments, the first generation module 402 is further configured to:

[0121] An analytical agent is used to analyze the target optimization object in order to determine the runtime symbol of the target optimization object;

[0122] The analytical agent is used to send the runtime symbols to the source code retrieval engine, so that the source code retrieval engine can obtain source code fragments and context information based on the runtime symbols, as the source code information;

[0123] The analytical agent is used to obtain feature data of the target optimization object, and the historical experience knowledge is obtained based on the feature data.

[0124] The analytical agent is used to perform reasoning based on the source code information and historical experience knowledge to obtain the description information of the optimization scheme.

[0125] In this embodiment, the analysis agent combines the context of source code fragments for analysis. The large model no longer relies solely on guessing from local code fragments, but instead performs deep architecture-level optimization based on the complete call chain and runtime hotspot information, thereby improving the optimization effect.

[0126] In some embodiments, the verification module 404 is further configured to:

[0127] Create a verification sandbox, compile the initial source code corresponding to the target service within the verification sandbox to obtain initial executable code, and obtain the target source code based on the code patch and the initial source code, compile the target source code to obtain target executable code;

[0128] Within the validation sandbox, the baseline container and the optimization container are launched;

[0129] Within the benchmark container, the initial executable code is used to process real traffic to obtain benchmark performance metrics.

[0130] Within the optimization container, the target executable code is used to process the real traffic in order to obtain optimized performance metrics.

[0131] Based on the benchmark performance index and the optimized performance index, obtain the optimized value of the performance index;

[0132] The verification results are obtained based on the optimized values ​​of the performance indicators.

[0133] In this embodiment, A / B testing and performance comparison of the optimized code are performed using real production traffic in an isolated environment. This enables automated verification, compressing the original manual "modification-compilation-deployment-stress testing" process, which would have taken several days, into minutes, greatly reducing manpower requirements. By replaying real traffic, it is ensured that the surviving optimization solutions are effective in real production scenarios, avoiding the off-target problem of static rules.

[0134] In some embodiments, the update module 405 is further configured to:

[0135] If the verification result is successful, the code patch is used as a positive sample, and the structured data of the positive sample is obtained; if the verification result is unsuccessful, the code patch is used as a negative sample, and the structured data of the negative sample is obtained.

[0136] The positive sample structured data and / or the negative sample structured data are used as the current experiential knowledge to update the historical experiential knowledge.

[0137] In this embodiment, by labeling positive and negative samples, logical errors or negative performance optimizations that may arise from general large models are effectively intercepted, ensuring the safety of code changes. Furthermore, by obtaining structured data from positive and negative samples and updating experiential knowledge, knowledge accumulation and self-evolution can be achieved.

[0138] Figure 5 This is a schematic diagram according to the fourth embodiment of the present disclosure. This embodiment provides a code performance optimization system based on artificial intelligence. The system 500 includes: an analyzer 501, an analysis agent 502, a coding agent 503, a performance verification engine 504, and a self-evolving experience base 505.

[0139] Analyzer 501 is used to analyze the runtime performance data of the target service to determine the target optimization object; analysis agent 502 is used to obtain source code information and historical experience knowledge associated with the target optimization object, and generate optimization scheme description information based on the source code information and historical experience knowledge; coding agent 503 is used to generate code patches according to the optimization scheme description information; performance verification engine 504 is used to verify according to the code patches to obtain verification results; self-evolving experience base 505 is used to obtain current experience knowledge according to the verification results, and update the historical experience knowledge based on the current experience knowledge.

[0140] For details, please refer to the relevant descriptions in the above embodiments.

[0141] In this embodiment, by determining the target optimization object, generating optimization scheme description information, generating code patches, generating verification results, and updating historical experience knowledge, a comprehensive optimization scheme involving perception, decision-making, coding, verification, and evolution can be achieved. Compared with optimization schemes that only focus on a single point, this can provide the comprehensiveness and accuracy of the processing process, thereby improving the code performance optimization effect.

[0142] It is understood that the same or similar content in different embodiments of this disclosure can be referred to each other.

[0143] It is understood that the terms "first" and "second" in the embodiments of this disclosure are only used for distinction and do not indicate the degree of importance or the order of events.

[0144] It is understandable that, unless otherwise specified, the order of steps in the process indicates that the temporal relationship between these steps is not limited.

[0145] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0146] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0147] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device 600 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0148] like Figure 6 As shown, the electronic device 600 includes a computing unit 601, which can perform various appropriate actions and processes based on a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 606 into a random access memory (RAM) 603. The RAM 603 may also store various programs and data required for the operation of the electronic device 600. The computing unit 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0149] Multiple components in electronic device 600 are connected to I / O interface 605, including: input unit 606, such as keyboard, mouse, etc.; output unit 607, such as various types of displays, speakers, etc.; storage unit 608, such as disk, optical disk, etc.; and communication unit 609, such as network card, modem, wireless transceiver, etc. Communication unit 609 allows electronic device 600 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0150] The computing unit 601 can be a variety of general-purpose and / or proprietary processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various proprietary artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as code performance optimization methods. For example, in some embodiments, the code performance optimization method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 600 via ROM 602 and / or communication unit 609. When the computer program is loaded into RAM 603 and executed by the computing unit 601, one or more steps of the code performance optimization method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to perform code performance optimization methods by any other suitable means (e.g., by means of firmware).

[0151] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), proprietary integrated circuits (ASICs), proprietary standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a proprietary or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0152] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, a dedicated computer, or other programmable task processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0153] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0154] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0155] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0156] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service system that addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.

[0157] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0158] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. An AI-based code performance optimization method, comprising: Analyze the runtime performance data of the target service to determine the target optimization objects; An analytical agent is used to obtain source code information and historical experience knowledge associated with the target optimization object, and optimization scheme description information is generated based on the source code information and historical experience knowledge. A coding agent is used to generate code patches based on the description information of the optimization scheme. Verification is performed based on the code patch to obtain verification results; Based on the verification results, current experience knowledge is obtained, and the historical experience knowledge is updated based on the current experience knowledge.

2. The method according to claim 1, wherein, The performance data includes a flame graph, which contains the frequency of occurrence of multiple candidate function stacks corresponding to the target service; The analysis of the target service's runtime performance data to determine the target optimization object includes: Based on the frequency of occurrence, a predetermined number of target function stacks are selected from the plurality of candidate function stacks as the target optimization objects.

3. The method according to claim 1, wherein, The step involves employing an analytical agent to acquire source code information and historical experience knowledge associated with the target optimization object, and generating optimization scheme description information based on the source code information and historical experience knowledge, including: An analytical agent is used to analyze the target optimization object in order to determine the runtime symbol of the target optimization object; The analytical agent is used to send the runtime symbols to the source code retrieval engine, so that the source code retrieval engine can obtain source code fragments and context information based on the runtime symbols, as the source code information; The analytical agent is used to obtain feature data of the target optimization object, and the historical experience knowledge is obtained based on the feature data. The analytical agent is used to perform reasoning based on the source code information and historical experience knowledge to obtain the description information of the optimization scheme.

4. The method according to claim 1, wherein, The verification based on the code patch to obtain the verification result includes: Create a verification sandbox, compile the initial source code corresponding to the target service within the verification sandbox to obtain initial executable code, and obtain the target source code based on the code patch and the initial source code, compile the target source code to obtain target executable code; Within the validation sandbox, the baseline container and the optimization container are launched; Within the benchmark container, the initial executable code is used to process real traffic to obtain benchmark performance metrics. Within the optimization container, the target executable code is used to process the real traffic in order to obtain optimized performance metrics. Based on the benchmark performance index and the optimized performance index, obtain the optimized value of the performance index; The verification results are obtained based on the optimized values ​​of the performance indicators.

5. The method according to claim 4, wherein, The step of obtaining current experience knowledge based on the verification result and updating the historical experience knowledge based on the current experience knowledge includes: If the verification result is successful, the code patch is used as a positive sample, and the structured data of the positive sample is obtained; if the verification result is unsuccessful, the code patch is used as a negative sample, and the structured data of the negative sample is obtained. The positive sample structured data and / or the negative sample structured data are used as the current experiential knowledge to update the historical experiential knowledge.

6. An artificial intelligence-based code performance optimization device, comprising: The analysis module is used to analyze the runtime performance data of the target service in order to determine the target optimization objects; The first generation module is used to use an analytical agent to obtain source code information and historical experience knowledge associated with the target optimization object, and generate optimization scheme description information based on the source code information and historical experience knowledge. The second generation module is used to generate code patches based on the optimization scheme description information using a coding agent. The verification module is used to verify the code patch to obtain the verification result; The update module is used to obtain current experience knowledge based on the verification results and update the historical experience knowledge based on the current experience knowledge.

7. An artificial intelligence-based code performance optimization system, comprising: The analyzer is used to analyze the runtime performance data of the target service in order to determine the target optimization objects; An analytical agent is used to obtain source code information and historical experience knowledge associated with the target optimization object, and to generate optimization scheme description information based on the source code information and historical experience knowledge. An intelligent coding agent is used to generate code patches based on the description information of the optimization scheme. A performance verification engine is used to verify the code patch to obtain verification results. The self-evolving experience base is used to obtain current experience knowledge based on the verification results and update the historical experience knowledge based on the current experience knowledge.

8. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-5.

9. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-5.

10. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-5.