Code review and optimization method driven by large language model

Through the code review and optimization method driven by the large language model, the shortcomings of traditional tools in false positives, response speed and optimization suggestions generation are solved, efficient and intelligent code review and optimization are achieved, and the overall efficiency and quality of software development are improved.

CN119512556APending Publication Date: 2025-02-25INSPUR QILU SOFTWARE IND
View PDF 0 Cites 21 Cited by

Patent Information

Application Number
CN202411398400.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

Traditional static code scanning tools have problems with false alarms and missed reports in modern software development, insufficient response speed and adaptability, and insufficient generation of optimization suggestions, which cannot effectively support a development environment with rapid iteration.

Method used

Using a large language model-driven code review and optimization method, the code is deeply analyzed through the reinforced training model, potential defects and optimization possibilities are identified, and specific optimization suggestions are generated. The method includes data collection and annotation, model training, code analysis and semantic understanding, defect recognition and optimization suggestions generation, user feedback interaction, and continuous learning and update.

Benefits of technology

It significantly improves the automation and intelligence level of code review and optimization, reduces false positive rates, improves development efficiency and code quality, and ensures the security and performance of the software.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512556A_ABST
    Figure CN119512556A_ABST
Patent Text Reader

Abstract

The invention provides a large language model-driven code review and optimization method, which belongs to the field of computer science, and comprises the following steps of: firstly, performing intensive training on a model through rich code samples and accurate manual annotation to ensure that the model has accurate code understanding and analysis capability; and then, performing deep analysis on an input source code by utilizing the trained large language model, and constructing an abstract syntax tree (AST) to capture deep semantic information of the code. And finally, the model automatically analyzes the codes, identifies potential defects, non-standard coding practices and optimization possibilities, and generates specific optimization suggestions, including code repair schemes and guidance following optimal practices, according to identification results, so that efficient support is provided for developers, and the quality of software products is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the intersection of software engineering and computer science, and in particular to a code review and optimization method driven by a large language model. Background Art

[0002] In modern software development, the quality and security of code are increasingly valued. Traditional code review tools, such as static code scanning tools such as Fortify and Sonar, have become an important part of the development process. These tools can identify potential defects and irregularities in the code through static analysis technology, helping developers improve the reliability and maintainability of the code. However, with the increasing complexity of software projects, the limitations of these traditional tools are becoming more and more obvious.

[0003] First, traditional static code scanning tools often generate a large number of false positives and missed negatives. Developers need to spend a lot of time and energy to manually screen these results in order to eliminate unnecessary warnings, resulting in low work efficiency. This process that relies on manual intervention not only increases development costs, but may also cause potential security vulnerabilities and performance issues to be ignored, bringing challenges to software maintenance.

[0004] Secondly, as the market continues to increase the speed of software iteration, the response speed and adaptability of traditional tools are increasingly insufficient. These tools often rely on fixed rules and patterns for code analysis, and are difficult to flexibly adapt to the rapidly changing development environment and technology stack. This makes it difficult for development teams to effectively review and optimize code during rapid iterations.

[0005] In addition, traditional tools are also deficient in generating optimization suggestions. Although they can identify problems, they often lack targeted repair suggestions and best practice guidance, and cannot provide substantial help to developers. This limitation forces development teams to rely on personal experience when solving problems, further affecting development efficiency and the quality of software products.

[0006] As software projects become more complex, traditional code review methods can no longer meet the growing demand for high efficiency and high quality in modern software development. Summary of the invention

[0007] In order to solve the above technical problems, the present invention provides a large language model driven code review and optimization method, which significantly improves the automation and intelligence level of code review and optimization, thereby effectively improving the overall efficiency and quality of software development.

[0008] This invention focuses on using advanced large language model technology to realize the intelligence of code detection and repair process, integrating cutting-edge technologies of multiple disciplines such as machine learning, natural language processing, programming language theory and software quality assurance, to comprehensively improve the efficiency of software development and product quality to cope with increasingly complex software engineering challenges.

[0009] The technical solution of the present invention is:

[0010] A code review and optimization method driven by a large language model. First, the model is intensively trained through rich code samples and precise manual annotations to ensure that it has accurate code understanding and analysis capabilities. Then, the trained large language model is used to deeply parse the input source code and build an abstract syntax tree (AST) to capture the deep semantic information of the code. Finally, the model automatically analyzes the code, identifies potential defects, irregular coding practices, and optimization possibilities, and generates specific optimization suggestions based on the identification results, including code repair solutions and guidance on following best practices, to provide efficient support for developers and ensure the quality of software products. It consists of six parts: data collection and annotation, model training, code parsing and semantic understanding, defect identification and generation of optimization suggestions, user feedback interaction, and continuous learning and updating.

[0011] in,

[0012] 1) Data collection and annotation is divided into the following two sub-parts:

[0013] 1.1) Collection of code samples

[0014] 1.2) Manual labeling: After collecting code samples, the data is labeled with high quality;

[0015] 2) Training the model, fine-tuning the SFT model, rewarding the RM model and strengthening the training PPO step, and constructing a code analysis and optimization model;

[0016] 3) Code parsing and semantic understanding: By parsing the code structure and extracting relevant semantic features, the model can better understand the logic and context of the code, thereby improving the model's performance in tasks such as error detection and optimization suggestion generation;

[0017] 4) Defect identification and generation of optimization suggestions, based on code analysis and semantic understanding, comprehensively covers potential problems in the code and provides optimization guidance;

[0018] 5) User feedback interaction: provide a better user experience through an intuitive user interface and efficient feedback mechanism, and continuously optimize model performance to achieve self-improvement and evolution of the tool

[0019] 6) Continuous learning and updating: Through incremental learning, online learning, and automated data updates, the model can continuously adapt to emerging code patterns, programming standards, and security threats over time, ensuring that the tool always keeps pace with actual development needs.

[0020] Furthermore,

[0021] Use automated tools to generate diverse code to enhance the data diversity of the model, including

[0022] Code generation: Use code generation models to generate different types of code samples, covering different syntax and logic patterns;

[0023] Fault injection: Use code mutation testing tools to introduce human errors or faults into the code, simulate defects in real development scenarios, and generate samples with different error modes

[0024] Manual annotation includes

[0025] Multi-level annotation:

[0026] Types of labels: Each code sample needs to be labeled with the location, type, severity, and repair suggestions of the defect; the types of labels include syntax errors, logic errors, security vulnerabilities, and performance issues. When evaluating the severity, a level classification is used to indicate the urgency of the problem to help the model prioritize high-risk issues.

[0027] Hierarchical division: the annotation structure includes contextual information;

[0028] Review the marked data to ensure the accuracy and consistency of the marking;

[0029] Consistency assessment: Cohen’s Kappa coefficient is used to assess the consistency between different annotators to ensure the quality of data annotation.

[0030] Model fine-tuning

[0031] Based on the pre-trained general language model, the model is further fine-tuned to make it more suitable for code understanding, error detection, and optimization suggestion generation tasks, including:

[0032] a) Data preparation: Use the multi-language, multi-problem type code samples collected and annotated in the previous step as fine-tuning training sets to ensure the adaptability and accuracy of the model;

[0033] b) Loss function: We customize the loss function for the code analysis task and calculate the cross entropy to evaluate the accuracy of error detection. We also use the ROUGE metric to evaluate the quality of the generated code fixes and optimization suggestions.

[0034] c) Model structure optimization: adjust the model’s learning rate, batch size, and dropout rate to ensure the best performance on code data;

[0035] Reward Model

[0036] After fine-tuning the basic model, set up a reward model to further train the model in terms of semantic understanding and problem detection capabilities using unlabeled code data, including

[0037] a) Self-supervised learning:

[0038] Self-supervised task design: Design self-supervised learning tasks to improve the model's capabilities in code completion, refactoring, and comment generation;

[0039] Data source: Use unlabeled code data for self-supervised learning to expand the model's training data set;

[0040] Model training strategy: Enhance the model's understanding of the deep semantics of the code through self-supervision tasks and maximize the potential of unlabeled data

[0041] 3) Intensive training

[0042] Enhanced training is performed to further improve the model’s performance, ensuring that it can handle multi-task scenarios and has self-learning capabilities, including:

[0043] a) Context processing: ensure that the model can fully utilize the context information of the code and maintain its semantic consistency when processing longer code segments;

[0044] b) Multi-task learning: training several related tasks simultaneously to improve the model’s generalization ability and adaptability to a variety of problems;

[0045] Task design: Ensure that the model can identify different types of code problems, detect defects and potential problems in the code, and generate targeted repair solutions and optimization suggestions;

[0046] Task sharing: Sharing some model parameters to promote collaboration between different tasks, thereby improving overall semantic understanding capabilities;

[0047] Loss function weight distribution: Dynamically adjust the loss function weight of each task according to the importance of the task to ensure balanced development in multi-task learning.

[0048] Furthermore,

[0049] After training, the model is fully validated and evaluated to ensure that it performs as expected in real-world scenarios, including accuracy, model efficiency, cross-language capabilities, and generalization to different types of questions;

[0050] Multi-dimensional evaluation: Evaluate the model's performance from several perspectives to ensure that it has comprehensive code analysis capabilities;

[0051] Accuracy: Standard evaluation metrics are used to measure the model's performance in code error detection, and the ROUGE metric is used to evaluate the accuracy and naturalness of the optimization suggestions generated by the model.

[0052] Performance: Evaluate the model’s inference speed and computing resource consumption in real-world applications to ensure real-time and efficiency in large code bases;

[0053] Generalization: Apply the model to different types of project codes, evaluate its performance on codes in different fields and various problem types, and ensure its wide adaptability;

[0054] Cross-language evaluation: Evaluate the model's performance in multiple programming languages ​​to ensure that it has cross-language code analysis and optimization capabilities;

[0055] Language coverage: Evaluate the model's performance on different programming languages ​​through test datasets;

[0056] Cross-lingual consistency: The model should be consistent in identifying the same type of questions in different languages;

[0057] Language-specific problems: Evaluate the model’s performance on language-specific problems to ensure adaptation to unique features.

[0058] Furthermore,

[0059] Code parsing and semantic understanding, including

[0060] 1) Parsing of input code

[0061] Code parsing is the basis for building a code analysis model. By parsing the grammatical structure of the code, the model can understand the logic and semantics of the code.

[0062] a) Abstract syntax tree generation: Parse the source code into an abstract syntax tree, which displays the syntax structure of the code in a tree structure, so that the model can extract syntax and structure information;

[0063] Abstract syntax tree generator: Use a parsing tool that supports multiple languages ​​to uniformly parse multiple programming languages ​​and generate a consistent abstract syntax tree structure;

[0064] Abstract syntax tree structure analysis: Each node in the abstract syntax tree represents a basic element of the code. The tree structure shows the nesting and dependency relationships of the code. The model can extract syntax features through nodes and obtain the execution flow and scope information of the code by traversing the tree.

[0065] Syntax error handling: Design an error recovery mechanism so that the parser can generate a partial abstract syntax tree when a syntax or structural error is detected, to ensure that subsequent analysis tasks can continue;

[0066] Handling of incomplete code: In code completion or real-time review scenarios, the input code may be incomplete. The parser should be able to process partial code and generate the corresponding partial abstract syntax tree.

[0067] b) Cross-language parsing: ensure that the code can be parsed across multiple programming languages ​​and generate a unified grammatical structure representation;

[0068] Syntactic universality: Create a universal grammatical structure representation for abstract syntax trees of different languages ​​so that the model can share knowledge between different languages;

[0069] Language-specific parsing: Identify and process language-specific nodes, ensuring that language-specific rules can be incorporated during parsing;

[0070] Feature extraction

[0071] After generating the AST of the code, the model extracts features from it. These features can help the model understand the function, semantics, and context of the code.

[0072] a) Context-aware: By extracting code context information, the model can understand the interdependencies between code snippets;

[0073] Scope: Understand the definition and usage of variables in different scopes, extract function call chain information, and track the context of function calls;

[0074] Dependencies: Trace the data flow path, understand how data is passed between variables, and extract control flow dependency information of the code, especially in conditional statements and loop structures;

[0075] Cross-file / module context: In a project, code is usually distributed across several files or modules; the model tracks dependencies across files or modules when parsing a single file;

[0076] b) Code snippet association

[0077] Identify and relate different pieces of code, especially those that depend on or call each other, to improve the model's ability to understand complex code structures;

[0078] Function association: Extract the calling relationship between functions in the code, build a function dependency graph, identify recursive function calls, and understand their termination conditions and execution logic;

[0079] Relationship between classes and objects: For object-oriented languages, understand the inheritance relationship of classes and the interface implementation relationship, and track the creation, modification, and use of objects to ensure that the model understands the behavior, polymorphism, life cycle, and state changes of objects;

[0080] Code snippet reuse: Detects repeated snippets in the code by comparing the similarities between code snippets, helping the model identify common code patterns or anti-patterns.

[0081] Furthermore,

[0082] Defect identification aims to quickly and accurately find potential problems in your code, including:

[0083] a) Multi-type defect detection: The model has the ability to accurately detect multiple types of defects in the code, covering syntax, logic, security and performance, including:

[0084] Syntax error detection: By parsing the abstract syntax tree of the code, the model can identify parts that do not meet the syntax standards; the model can quickly detect through rule matching and syntax tree traversal;

[0085] Logic error detection: Identify potential logic errors by analyzing control flow graphs and data flow graphs;

[0086] Security vulnerability detection: The model detects common security issues by training security vulnerability datasets and combining cross-file and module dependency analysis. At the same time, the model supports the detection of specific security specifications.

[0087] Performance problem detection: Performance problem detection focuses on the computational complexity and resource usage of the code. The model analyzes the execution path and resource consumption of the code to identify performance bottlenecks such as unnecessary loop nesting and invalid database queries.

[0088] Code style and maintainability problem detection: detect irregular programming habits;

[0089] b) Pattern recognition: Improve the coverage of defect detection by identifying common patterns and anti-patterns in the code;

[0090] Common pattern recognition: The model helps developers optimize code structure and improve scalability and maintainability by learning design patterns;

[0091] Anti-pattern detection: Anti-patterns refer to code patterns that are common but not recommended in the development process. Through pattern matching technology, the model identifies these unrecommended practices and reminds developers to make corresponding optimizations;

[0092] Optimization suggestion generation

[0093] Multi-level suggestions: For the identified code defects, the model generates multi-level optimization suggestions and provides several solutions from simple fixes to deep optimization for developers to choose from, including:

[0094] Basic repair suggestions: For syntax errors and simple logic errors, the model provides direct repair solutions;

[0095] In-depth optimization suggestions: The optimization suggestions provided by the model are not limited to the code itself, but also provide system-level improvement suggestions;

[0096] Best Practices Recommendations: The model provides developers with coding recommendations by learning industry-recognized best practices.

[0097] Contextual association: Context-aware technology is used to generate optimization suggestions that are associated with the global context of the code, rather than just a single code snippet. The model analyzes the code structure of the entire project and provides optimization suggestions from a more global perspective.

[0098] Furthermore,

[0099] User feedback interaction, including:

[0100] User interface

[0101] a) Visual presentation: Intuitive user interface that presents test results and optimization suggestions in a visual way;

[0102] Defect marking and highlighting: In the code editing interface, the tool will automatically mark detected defects or potential problems, and use different colors to highlight different levels of problems. Developers can directly view detailed descriptions of the problems and related optimization suggestions in the interface;

[0103] Optimization suggestion panel: For each detected problem, the interface provides an optimization suggestion panel, which lists detailed repair solutions and improvement measures; the suggestions are divided into basic repair, deep optimization and best practice levels, and developers can choose the appropriate solution according to their needs; in addition, the panel also provides AI repair function, which quickly generates repair code by the model;

[0104] User feedback mechanism

[0105] Continuous learning and improvement of the model is achieved through active feedback and automatic feedback, including:

[0106] a) Feedback learning mechanism

[0107] Feedback learning: After collecting user feedback, the tool stores it in a feedback database as training data for continuous model learning. By periodically retraining the model and using user feedback information to fine-tune the model, the accuracy and practicality of the model can be further improved.

[0108] Feedback reward mechanism: When a user accepts a suggestion, the model will give a positive reward to the decision path behind the suggestion, otherwise it will give a penalty, thereby optimizing the model parameters to make it more in line with the user's needs and usage habits;

[0109] b) Automatic feedback collection mechanism: Use user behavior data to collect implicit feedback and promote self-improvement of the model;

[0110] Automatically evaluate the effectiveness of suggestions: The tool tracks the developer's code modification behavior as implicit feedback;

[0111] User usage log analysis: The tool collects user usage logs and analyzes developers' behavior patterns to uncover users' preferences and needs for code quality and optimization suggestions, and adjusts the model's decision-making strategy based on this information.

[0112] Furthermore,

[0113] Continuous learning and updating, including:

[0114] Incremental Learning

[0115] Incremental learning means that the model can update itself after receiving new data without losing existing knowledge;

[0116] a) Online learning: The model is updated immediately upon receiving new data without the need to retrain the entire model. Specific implementation aspects:

[0117] i. Real-time data processing: The tool collects the developer's operational behaviors and feedback information as new data inputs. The model analyzes these inputs and optimizes its ability to identify code defects in similar scenarios by fine-tuning the model's parameters.

[0118] ii. Small batch updates: Whenever a certain amount of user feedback or new code samples are collected, the model will be updated in small batches, and the updated model will be immediately applied to subsequent code reviews;

[0119] b) Dynamic parameter adjustment: The model dynamically adjusts its learning rate, weights, and other parameters based on the latest data to ensure greater adaptability to new programming patterns or defect types;

[0120] c) Automated data update: This mechanism ensures that the model continuously obtains the latest code samples and defect information, thereby improving the generalization ability on new problems. The tool collects new code samples from sources such as user-submitted code data, various code repositories, open source projects, and internal enterprise projects. After preprocessing and standardization, it is added to the model's training data set for subsequent incremental learning and updates.

[0121] Continuous Improvement

[0122] By introducing user feedback mechanisms and automated data updates, the model can continuously improve during operation. The improvements are not only reflected in the accuracy of problem identification and optimization suggestions, but also in the model's understanding of code structure, cross-language support, and performance optimization.

[0123] a) Periodic model optimization: Regularly conduct comprehensive evaluation and optimization of the model to ensure its continuous improvement. During the evaluation process, use the test data set to perform regression testing on the model, check the performance of the model in different languages ​​and problem types, and ensure the adaptability after the technology evolves. During the optimization process, new technologies or algorithms can be introduced;

[0124] b) Enhanced multi-language capabilities: As programming languages ​​are updated and new languages ​​emerge, the model will collect code samples of these new languages ​​for training through an automated data update mechanism to improve its cross-language processing capabilities; each model update will include extensions to different languages ​​to meet the needs of developers using a variety of programming languages;

[0125] c) Security vulnerability priority learning: The model will give priority to learning new security vulnerabilities and their protection strategies. Whenever there is a new security vulnerability report or fix, the tool will give priority to learning and integrating it to ensure that the model can identify and fix these vulnerabilities in the first place.

[0126] The beneficial effects of the present invention are

[0127] The present invention provides an intelligent code review and optimization tool by introducing the parsing capabilities of a large language model, automated detection and repair, low false alarm rate, efficient optimization suggestions, and continuous learning and updating mechanisms. This not only effectively addresses the challenges of traditional static code scanning tools in modern software development, but also significantly improves the accuracy of code review, development efficiency, and code quality, ensuring that the software meets high standards in terms of security and performance, thereby providing the software development team with an efficient, intelligent, and reliable tool, ultimately contributing important value to quality assurance and security improvement in the software development process. BRIEF DESCRIPTION OF THE DRAWINGS

[0128] Figure 1 It is a schematic diagram of the workflow of the present invention. DETAILED DESCRIPTION

[0129] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0130] Code review tools based on advanced large language models can quickly identify and optimize relevant issues in the early stages of code development, provide efficient support for developers, and ensure the high-standard delivery of software products. By building a more intelligent review process, this tool will effectively fill the gaps in traditional tools and bring a higher level of automation and intelligence to software development.

[0131] The main purpose of this invention is to provide an intelligent code review and optimization method based on an advanced large language model to address the challenges faced by traditional static code scanning tools in modern software development. Specific goals include:

[0132] 1. Automated detection and repair: By leveraging the powerful parsing capabilities of large language models, potential defects in source code can be automatically detected and repaired, reducing human intervention and improving efficiency.

[0133] 2. Reduce false positive rate: Optimize the code analysis process, reduce false positives and missed negatives, enable developers to focus more on real defects, and improve the accuracy of code review.

[0134] 3. Speed ​​up development: Quickly identify and optimize problems in the early stages of software development to adapt to rapidly iterative market demands and improve overall development efficiency.

[0135] 4. Provide specific optimization suggestions: Based on the identification results, generate detailed optimization suggestions and repair plans to help developers follow best practices, thereby improving code quality and maintainability.

[0136] 5. Improve software security and performance: Ensure high-standard delivery of software products by timely discovering and resolving potential security vulnerabilities and performance issues.

[0137] In summary, the present invention aims to provide a highly efficient and intelligent tool for software development teams, significantly improve the quality and efficiency of code review and optimization, and promote software development to higher standards.

[0138] Technical solution:

[0139] The overall architecture of the present invention consists of six key parts: data collection and annotation, model training, code parsing and semantic understanding, defect identification and generation of optimization suggestions, user feedback interaction, and continuous learning and updating. By integrating these parts, the present invention aims to significantly improve the automation and intelligence level of code review and optimization, thereby effectively improving the overall efficiency and quality of software development.

[0140] Technical details:

[0141] 1. Data collection and annotation

[0142] In the data collection and annotation part, high-quality and diverse code data is the key to the success of large language models, which can be divided into the following two sub-parts:

[0143] 1) Collection of code samples

[0144] Data collection is the basis for model training and subsequent optimization. In order to improve the generalization ability of the model, the collected code samples need to cover multiple dimensions to ensure their diversity and representativeness.

[0145] a) Multi-language support: Ensure that the model can handle multiple programming languages ​​to adapt to different needs and application scenarios.

[0146] Language types: Collect code samples of mainstream programming languages, including but not limited to Python, Java, C++, JavaScript, Go, Rust, Ruby, etc. Ensure that the model has cross-language capabilities and can handle the syntax and structure of different languages.

[0147] Data sources: The sources of code samples include open source projects in public code repositories (such as GitHub, GitLab, etc.), enterprise code bases, etc.

[0148] Balance: Ensure that the sample size of code in each language is roughly balanced to avoid overfitting the model to one language and ignoring other languages.

[0149] b) Problem diversity: Collect samples covering a variety of code problems to improve the performance of the model in diverse scenarios.

[0150] Types of issues: Samples are collected for various common errors and vulnerabilities in the code (such as syntax errors, logic errors, performance issues, security vulnerabilities, and code style issues).

[0151] Multi-scenario coverage: Code is collected from different fields and types of projects (such as web development, data analysis, embedded development, mobile development, etc.) to ensure the diversity of problems.

[0152] Specific security issue samples: Obtain code samples of known security issues from the security community and vulnerability libraries (such as CVE and CNNVD databases) to ensure that the model can identify high-level security vulnerabilities.

[0153] c) Dynamically generate data: To avoid manually writing and collecting samples, use automated tools to generate a large amount of diverse code to enhance the data diversity of the model.

[0154] Code generation: Use code generation models to generate a large number of different types of code samples, covering different syntax and logic patterns.

[0155] Fault injection: Use code mutation testing tools (PITest) to introduce human errors or faults into the code, simulate defects in real development scenarios, and generate samples with different error modes.

[0156] 2) Manual labeling

[0157] After collecting a large number of code samples, professionals will annotate the data with high quality to support subsequent model training and evaluation.

[0158] a) Multi-level annotation: Annotation work needs to have multiple levels of precision. It is necessary not only to point out the errors in the code, but also to classify and describe the type, severity and repair suggestions of the errors.

[0159] Types of labels: Each code sample needs to be labeled with the location, type, severity, and repair suggestions of the defect. The types of labels include syntax errors, logic errors, security vulnerabilities, and performance issues. When evaluating the severity, the level classification (low, medium, and high) is used to indicate the urgency of the problem to help the model prioritize high-risk issues. Repair suggestions are provided by human experts to help the model learn to generate optimization suggestions that better meet the needs of developers.

[0160] Hierarchical division: The annotation structure can include complex contextual information, such as cross-file function call problems or complex concurrency errors.

[0161] b) Review the marked data to ensure the accuracy and consistency of the marking.

[0162] Double review: Each code sample is annotated by at least two experts to ensure accuracy and comprehensiveness.

[0163] Consistency assessment: Cohen's Kappa is used to assess the consistency between different annotators to ensure the quality of data annotation.

[0164] 2. Training Model

[0165] Through steps such as model fine-tuning (SFT), reward model (RM) and reinforcement training (PPO), an efficient, accurate and generalizable code analysis and optimization model is built.

[0166] 3) Model fine-tuning

[0167] Based on the pre-trained general language model, the model is further fine-tuned to make it more suitable for code understanding, error detection, and optimization suggestion generation tasks.

[0168] a) Data preparation: Use the multi-language, multi-problem type code samples collected and annotated in the previous step as fine-tuning training sets to ensure the adaptability and accuracy of the model.

[0169] b) Loss Function: We customize the loss function for the code analysis task and calculate the cross entropy to evaluate the accuracy of error detection. We also use the ROUGE metric to evaluate the quality of the generated code fixes and optimization suggestions.

[0170] c) Model structure optimization: Adjust the model’s learning rate, batch size, dropout rate and other hyperparameters to ensure the best performance on the code data.

[0171] 4) Reward Model

[0172] After fine-tuning the basic model, set up a reasonable reward model and use unlabeled code data to further train the model in terms of semantic understanding and problem detection capabilities.

[0173] a) Self-supervised learning:

[0174] Self-supervised task design: Design self-supervised learning tasks to improve the model's capabilities in code completion, refactoring, and comment generation.

[0175] Data source: Use unlabeled code data for self-supervised learning to expand the model’s training dataset.

[0176] Model training strategy: Enhance the model’s understanding of the deep semantics of the code through self-supervision tasks and maximize the potential of unlabeled data.

[0177] 5) Strengthening training

[0178] Strengthen training is performed to further improve the performance of the model, ensuring that it can handle multi-task scenarios and has self-learning capabilities.

[0179] a) Context processing: Ensure that the model can fully utilize the contextual information of the code, such as function calls, variable dependencies, etc., especially when processing longer code segments to maintain their semantic consistency.

[0180] b) Multi-task learning: Train multiple related tasks simultaneously to improve the model’s generalization ability and adaptability to a variety of problems.

[0181] Task design: Ensure that the model can identify different types of code problems, such as syntax errors, logic errors, security vulnerabilities, performance issues, etc., detect defects and potential problems in the code, and generate targeted repair solutions and optimization suggestions.

[0182] Task sharing: Sharing some model parameters to promote collaboration between different tasks. For example, the code classification task and the defect detection task share the encoding layer to improve the overall semantic understanding ability.

[0183] Loss function weight distribution: Dynamically adjust the loss function weight of each task according to the importance of the task to ensure balanced development in multi-task learning.

[0184] 6) Verification and evaluation

[0185] After training, the model is fully validated and evaluated to ensure that its performance in real-world scenarios meets expectations, not only in terms of accuracy, but also in terms of efficiency, cross-language capabilities, and generalization to different types of questions.

[0186] a) Multi-dimensional evaluation: Evaluate the performance of the model from multiple perspectives to ensure that it has comprehensive code analysis capabilities.

[0187] Accuracy: Use standard evaluation metrics (precision, recall, F1 score, etc.) to measure the model’s performance in detecting code errors, and use the ROUGE metric to evaluate the accuracy and naturalness of the optimization suggestions generated by the model.

[0188] Performance: Evaluate the model’s inference speed and computing resource consumption in real-world applications to ensure real-time and efficiency in large code bases.

[0189] Generalization: Apply the model to different types of project codes, evaluate its performance on codes in different fields and various problem types, and ensure its adaptability is broad.

[0190] b) Cross-language evaluation: Evaluate the model’s performance in multiple programming languages ​​to ensure that it has cross-language code analysis and optimization capabilities.

[0191] Language coverage: Evaluate the model’s performance on different programming languages ​​through the test dataset.

[0192] Cross-language consistency: The model should be consistent in identifying the same type of issues across different languages. For example, the model should be able to handle performance issues in Python and C++ code at a similar level.

[0193] Language-specific problems: Evaluate the model’s performance on language-specific problems, such as Java’s memory management problems and C++’s pointer operations, to ensure that it is adaptable to unique features.

[0194] 3. Code parsing and semantic understanding

[0195] By parsing the code structure and extracting relevant semantic features, the model can better understand the logic and context of the code, thereby improving the model's performance in tasks such as error detection and optimization suggestion generation.

[0196] 3) Parsing of input code

[0197] Code parsing is the basis for building a code analysis model. By parsing the grammatical structure of the code, the model can deeply understand the logic and semantics of the code.

[0198] a) Abstract Syntax Tree (AST) Generation: The source code is parsed into an Abstract Syntax Tree (AST) to display the grammatical structure of the code in a tree structure, so that the model can extract syntax and structural information.

[0199] AST generator: Use a parsing tool that supports multiple languages ​​(such as ANTLR) to uniformly parse multiple programming languages ​​and generate a consistent AST structure to facilitate subsequent cross-language feature extraction and analysis.

[0200] AST structure analysis: Each node in the AST represents a basic element of the code (such as variable declaration, function definition, conditional statement, etc.). The tree structure shows the nesting and dependency of the code. The model can extract grammatical features through the nodes and obtain the execution flow and scope information of the code by traversing the tree.

[0201] Syntax error handling: Design error recovery mechanisms so that the parser can generate partial ASTs when syntax or structural errors are detected, to ensure that subsequent analysis tasks can continue.

[0202] Handling of incomplete code: In code completion or real-time review scenarios, the input code may be incomplete, and the parser should be able to handle partial code and generate the corresponding partial AST.

[0203] b) Cross-language parsing: Ensure that the code can be parsed across multiple programming languages ​​and generate a unified grammatical structure representation to facilitate feature extraction and model analysis.

[0204] Syntactic universality: Different programming languages ​​have different syntax and features, but the basic structures of most languages ​​are similar (such as variable declaration, control flow, function definition, etc.). A common grammatical structure representation can be created for ASTs of different languages ​​so that the model can share knowledge between different languages.

[0205] Language-specific parsing: Identify and process unique nodes in a specific language (such as Java interfaces and C++ pointer operations) to ensure that language-specific rules can be added during parsing to improve semantic understanding.

[0206] 4) Feature extraction

[0207] After generating the AST of the code, the model needs to extract useful features from it. These features can help the model understand the function, semantics, and context of the code.

[0208] a) Context-aware: By extracting code context information, the model can understand the interdependencies between code snippets.

[0209] Scope: Understand the definition and usage of variables in different scopes, extract function call chain information, and track the context of function calls, including information such as incoming parameters and return values.

[0210] Dependencies: Trace the data flow path, understand how data is passed between variables, and extract the control flow dependency information of the code, especially in conditional statements (such as if, while, etc.) and loop structures.

[0211] Cross-file / module context: In a project, code is usually distributed across multiple files or modules. The model should be able to track cross-file or module dependencies when parsing a single file, such as cross-file calls of functions or classes, module imports, etc.

[0212] b) Code snippet association

[0213] Identify and relate different fragments in the code, especially those that depend on or call each other, to improve the model's ability to understand complex code structures.

[0214] Function association: Extract the calling relationship between functions in the code, build a function dependency graph, and identify recursive function calls to understand their termination conditions and execution logic.

[0215] Relationship between classes and objects: For object-oriented languages, understand the inheritance relationship and interface implementation relationship of classes, and track the creation, modification, and use of objects to ensure that the model understands the behavior, polymorphism, life cycle, and state changes of objects.

[0216] Code snippet reuse: Detect duplicate snippets in the code by comparing the similarities between code snippets, helping the model identify common code patterns or anti-patterns (such as code redundancy).

[0217] 4. Defect identification and generation of optimization suggestions

[0218] Based on code parsing and semantic understanding, the present invention proposes a multi-dimensional, multi-level defect identification and optimization suggestion generation method, which can comprehensively cover potential problems in the code and provide developers with optimization guidance with practical value.

[0219] 3) Defect identification

[0220] Defect identification is one of the core functions of the model, which aims to quickly and accurately discover potential problems in the code.

[0221] a) Multi-type defect detection: The model has the ability to accurately detect multiple types of defects in the code, covering multiple aspects such as syntax, logic, security and performance. Specifically, it includes:

[0222] Syntax error detection: By parsing the abstract syntax tree (AST) of the code, the model can identify parts that do not meet the syntax standards. Common syntax errors such as unclosed brackets and undefined variables can be quickly detected by the model through rule matching and syntax tree traversal.

[0223] Logical error detection: Logical errors often cannot be caught at the compile stage, but will cause exceptions or unexpected behaviors at runtime. The model identifies potential logical errors such as infinite loops, conditional judgment errors, etc. by analyzing control flow graphs and data flow graphs.

[0224] Security vulnerability detection: The model can detect common security issues such as SQL injection, cross-site scripting (XSS), etc. by training security vulnerability datasets and combining cross-file and module dependency analysis. At the same time, the model supports the detection of specific security specifications, such as high-risk vulnerability types in CWE and OWASP Top 10.

[0225] Performance problem detection: Performance problem detection focuses on the computational complexity and resource usage of the code. The model analyzes the execution path and resource consumption of the code to identify performance bottlenecks such as unnecessary loop nesting and invalid database queries.

[0226] · Code style and maintainability problem detection: To ensure the readability and maintainability of the code, the model can detect irregular programming habits, such as lengthy functions, overly complex conditional branches, unused variables, etc.

[0227] b) Pattern recognition: In order to improve the extensiveness of defect detection, the model also introduces pattern recognition technology to improve the coverage of defect detection by identifying common patterns and anti-patterns in the code.

[0228] Common pattern recognition: The model helps developers optimize code structure and improve scalability and maintainability by learning excellent design patterns, such as singleton pattern and factory pattern.

[0229] Anti-pattern detection: Anti-patterns refer to common but not recommended code patterns in the development process, such as excessive conditional judgments, too deep loop nesting, etc. Through pattern matching technology, the model can identify these unrecommended practices and remind developers to make corresponding optimizations

[0230] 4) Optimization suggestion generation

[0231] a) Multi-level suggestions: For the identified code defects, the model can generate multi-level optimization suggestions and provide a variety of solutions from simple repairs to deep optimization for developers to choose from. Specifically, they include:

[0232] Basic repair suggestions: For syntax errors and simple logic errors, the model provides direct repair solutions, such as adding missing symbols in the code, adjusting the order of conditional judgments, etc.

[0233] In-depth optimization suggestions: For complex logic problems, performance bottlenecks or security vulnerabilities, the optimization suggestions provided by the model are not limited to the code itself, but also provide system-level improvement suggestions. For example, for SQL injection vulnerabilities, in addition to fixing related SQL statements, the model also recommends that developers use parameterized queries or ORM frameworks.

[0234] Best Practices: The model can provide developers with coding recommendations by learning industry-recognized best practices. For example, in Python development, it is recommended to follow the PEP 8 standard; in JavaScript development, it is recommended to use the new features of ES6 to optimize the code structure.

[0235] b) Contextual association: The model can also generate optimization suggestions associated with the global context of the code through context-aware technology, rather than just a single code snippet. This means that the model can analyze the code structure of the entire project and provide optimization suggestions from a more global perspective. For example, the model can identify irregular function calls across modules, or remind developers to use a certain coding style uniformly across multiple files.

[0236] 5. User feedback interaction

[0237] In order to give full play to the actual value of the code review and optimization tool, the present invention introduces a user feedback interaction module. This module aims to provide a better user experience through an intuitive user interface and an efficient feedback mechanism, and continuously optimize the model performance to achieve self-improvement and evolution of the tool.

[0238] 3) User interface

[0239] a) Visual presentation: To help developers understand and use the analysis and optimization suggestions provided by the tool, an intuitive user interface is designed to present the detection results and optimization suggestions in a visual way.

[0240] Defect marking and highlighting: In the code editing interface, the tool will automatically mark detected defects or potential problems, and use different colors to highlight different levels of problems. Developers can directly view detailed descriptions of the problems and related optimization suggestions in the interface.

[0241] Optimization suggestion panel: For each detected problem, the interface provides an optimization suggestion panel, which lists detailed repair solutions and improvement measures. The suggestions are divided into multiple levels such as basic repair, deep optimization and best practices. Developers can choose the appropriate solution according to their needs. In addition, the panel also provides AI repair function, which quickly generates repair code by the model.

[0242] 4) User feedback mechanism

[0243] In order to continuously improve the accuracy and practicality of the model, the present invention designs a user feedback mechanism to achieve continuous learning and improvement of the model through active feedback and automatic feedback.

[0244] a) Feedback learning mechanism

[0245] Feedback learning: After collecting user feedback, the tool stores it in the feedback database as training data for continuous model learning. By periodically retraining the model and using user feedback information to fine-tune the model, the accuracy and practicality of the model can be further improved.

[0246] Feedback reward mechanism: Introducing the idea of ​​reinforcement learning, a feedback reward mechanism is set up for the model. When a user accepts a suggestion, the model will give a positive reward to the decision path behind the suggestion, otherwise it will be punished, thereby optimizing the model's parameters to make it more in line with user needs and usage habits.

[0247] b) Automatic feedback collection mechanism: In order to reduce the burden on users, the present invention also provides an automatic feedback collection mechanism, which uses user behavior data to collect implicit feedback and promote self-improvement of the model.

[0248] Automatically evaluate the effectiveness of suggestions: The tool tracks the developer's code modification behavior as implicit feedback. For example, if the developer manually modifies the code after receiving the optimization suggestion, this modification behavior will be recorded in the next scan and compared with the suggestions given by the model to evaluate whether the model's suggestions are in line with reality.

[0249] User log analysis: The tool collects user logs (such as which suggestions are accepted and which are ignored) to analyze the behavior patterns of developers, thereby finding out the user's preferences and needs for code quality and optimization suggestions, and adjusting the model's decision-making strategy based on this information.

[0250] 6. Continuous learning and updating

[0251] In order to ensure that the code review and optimization tool can maintain high efficiency and accuracy in the long term, the present invention introduces a continuous learning and updating mechanism. This mechanism enables the model to continuously adapt to emerging code patterns, programming specifications and security threats over time through incremental learning, online learning and automatic data updates, ensuring that the tool always keeps pace with actual development needs.

[0252] 3) Incremental Learning

[0253] Incremental learning means that the model can update itself after receiving new data without losing existing knowledge. This learning mode is particularly important for code review tools, because code standards, programming languages, and development technologies are constantly evolving, and incremental learning can keep the tools continuously adaptable.

[0254] a) Online learning: The model is updated immediately when new data is received, without the need to retrain the entire model. Specific implementation aspects:

[0255] Real-time data processing: The tool collects the developer’s operational behaviors and feedback information as new data inputs. The model analyzes these inputs and fine-tunes the model’s parameters to optimize its ability to identify code defects in similar scenarios.

[0256] Small batch updates: Whenever a certain amount of user feedback or new code samples are collected, the model will be updated in small batches. This method can avoid the time and resource consumption caused by large-scale retraining. The updated model will be immediately applied to subsequent code reviews.

[0257] Dynamic parameter adjustment: The model can dynamically adjust its learning rate, weights, and other parameters based on the latest data to ensure greater adaptability to new programming patterns or defect types. For example, if the model frequently receives feedback on a certain type of problem, it can increase its weight on such problems to improve its recognition accuracy.

[0258] b) Automatic data update: This mechanism ensures that the model continuously obtains the latest code samples and defect information, thereby improving the generalization ability on new problems. The tool collects new code samples from sources such as user-submitted code data, various code repositories, open source projects, and internal enterprise projects. After preprocessing and standardization, it is added to the model's training data set for subsequent incremental learning and updates.

[0259] 4) Continuous Improvement

[0260] By introducing user feedback mechanisms and automated data updates, the model can continuously improve during operation. The improvement is not only reflected in the accuracy of problem identification and optimization suggestions, but also includes the model's progress in code structure understanding, cross-language support, performance optimization, etc.

[0261] a) Periodic model optimization: Regularly conduct comprehensive evaluation and optimization of the model to ensure its continuous improvement. During the evaluation process, the model is regression tested using a test data set to check the model's performance in different languages ​​and question types to ensure its adaptability after technological evolution. During the optimization process, new technologies or algorithms can be introduced, such as new deep learning architectures or more efficient parsing methods, to improve the overall performance of the model.

[0262] b) Enhanced multi-language capabilities: As programming languages ​​are updated and new languages ​​emerge, the model will collect code samples of these new languages ​​for training through an automated data update mechanism to improve its cross-language processing capabilities. Each model update will include extensions to different languages ​​to meet the needs of developers using a variety of programming languages.

[0263] c) Security vulnerability priority learning: The model will prioritize learning new security vulnerabilities and their protection strategies. Whenever a new security vulnerability report or fix is ​​released, the tool will prioritize learning and integrating it to ensure that the model can identify and fix these vulnerabilities as soon as possible.

[0264] The above description is only a preferred embodiment of the present invention, which is only used to illustrate the technical solution of the present invention, and is not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A code review and optimization method driven by a large language model, characterized in that: First, the model is trained through code samples and manual annotations to ensure that it has accurate code understanding and analysis capabilities. Then, the trained large language model is used to deeply parse the input source code and build an abstract syntax tree (AST) to capture the deep semantic information of the code. Finally, the model automatically analyzes the code to identify potential defects, irregular coding practices, and optimization possibilities, and generates specific optimization suggestions based on the identification results. It consists of six parts: data collection and annotation, model training, code analysis and semantic understanding, defect identification and generation of optimization suggestions, user feedback interaction, and continuous learning and updating; in, 1) Data collection and annotation is divided into the following two sub-parts: 1.1) Collection of code samples; 1.2) Manual labeling: After collecting code samples, the data is labeled with high quality; 2) Training the model, fine-tuning the SFT model, rewarding the RM model and strengthening the training PPO step, and constructing a code analysis and optimization model; 3) Code parsing and semantic understanding: By parsing the code structure and extracting relevant semantic features, the model can better understand the logic and context of the code, thereby improving the model's performance in error detection and optimization suggestion generation tasks; 4) Defect identification and generation of optimization suggestions, based on code analysis and semantic understanding, comprehensively covers potential problems in the code and provides optimization guidance; 5) User feedback interaction: provide a better user experience through an intuitive user interface and feedback mechanism, and continuously optimize model performance to achieve self-improvement and evolution of the tool; 6) Continuous learning and updating: Through incremental learning, online learning, and automated data updates, the model can continuously adapt to emerging code patterns, programming standards, and security threats over time, ensuring that the tool always keeps pace with actual development needs.

2. The method according to claim 1, characterized in that Use automated tools to generate diverse code to enhance the data diversity of the model, including Code generation: Use code generation models to generate different types of code samples, covering different syntax and logic patterns; Fault injection: Use code mutation testing tools to introduce human errors or faults into the code, simulate defects in real development scenarios, and generate samples with different error modes; Manual annotation includes Multi-level annotation: Types of labels: Each code sample needs to be labeled with the location, type, severity, and repair suggestions of the defect; the types of labels include syntax errors, logic errors, security vulnerabilities, and performance issues. When evaluating the severity, a level classification is used to indicate the urgency of the problem to help the model prioritize high-risk issues. Hierarchical division: the annotation structure includes contextual information; Review the marked data to ensure the accuracy and consistency of the marking; Consistency assessment: Cohen’s Kappa coefficient is used to assess the consistency between different annotators to ensure the quality of data annotation.

3. The method according to claim 1, characterized in that 1) Model fine-tuning Based on the pre-trained general language model, the model is further fine-tuned to make it more suitable for code understanding, error detection, and optimization suggestion generation tasks, including: a) Data preparation: Use the multi-language, multi-problem type code samples collected and annotated in the previous step as fine-tuning training sets to ensure the adaptability and accuracy of the model; b) Loss function: We customize the loss function for the code analysis task and calculate the cross entropy to evaluate the accuracy of error detection. We also use the ROUGE metric to evaluate the quality of the generated code fixes and optimization suggestions. c) Model structure optimization: adjust the model’s learning rate, batch size, and dropout rate to ensure the best performance on code data; 2) Reward Model After fine-tuning the basic model, set up a reward model to further train the model in terms of semantic understanding and problem detection capabilities using unlabeled code data, including a) Self-supervised learning: Self-supervised task design: Design self-supervised learning tasks to improve the model's capabilities in code completion, refactoring, and comment generation; Data source: Use unlabeled code data for self-supervised learning to expand the model's training data set; Model training strategy: Enhance the model's understanding of the deep semantics of the code through self-supervision tasks, and maximize the potential of unlabeled data; 3) Strengthening training Enhanced training is performed to further improve the model’s performance, ensuring that it can handle multi-task scenarios and has self-learning capabilities, including: a) Context processing: ensure that the model can fully utilize the context information of the code and maintain its semantic consistency when processing longer code segments; b) Multi-task learning: training several related tasks simultaneously to improve the model’s generalization ability and adaptability to a variety of problems; c) Task design: Ensure that the model can identify different types of code problems, detect defects and potential problems in the code, and generate targeted repair solutions and optimization suggestions; d) Task sharing: Sharing some model parameters to promote collaboration between different tasks, thereby improving overall semantic understanding capabilities; e) Loss function weight distribution: Dynamically adjust the loss function weight of each task according to the importance of the task to ensure balanced development in multi-task learning.

4. The method according to claim 1, characterized in that: After training, the model is fully validated and evaluated to ensure that it performs as expected in real-world scenarios, including accuracy, model efficiency, cross-language capabilities, and generalization capabilities to different types of questions. Multi-dimensional evaluation: Evaluate the model's performance from several perspectives to ensure that it has comprehensive code analysis capabilities; Accuracy: Standard evaluation metrics are used to measure the model's performance in code error detection, and the ROUGE metric is used to evaluate the accuracy and naturalness of the optimization suggestions generated by the model. Performance: Evaluate the model’s inference speed and computing resource consumption in real-world applications to ensure real-time and efficiency in large code bases; Generalization: Apply the model to different types of project codes, evaluate its performance on codes in different fields and various problem types, and ensure its wide adaptability; Cross-language evaluation: Evaluate the model's performance in multiple programming languages ​​to ensure that it has cross-language code analysis and optimization capabilities; Language coverage: Evaluate the model's performance on different programming languages ​​through test datasets; Cross-lingual consistency: The model should be consistent in identifying the same type of questions in different languages; Language-specific problems: Evaluate the model’s performance on language-specific problems to ensure adaptation to unique features.

5. The method according to claim 1, characterized in that Code parsing and semantic understanding, including 1) Parsing of input code Code parsing is the basis for building a code analysis model. By parsing the grammatical structure of the code, the model can understand the logic and semantics of the code. a) Abstract syntax tree generation: Parse the source code into an abstract syntax tree, which displays the syntax structure of the code in a tree structure, so that the model can extract syntax and structure information; Abstract syntax tree generator: Use a parsing tool that supports multiple languages ​​to uniformly parse multiple programming languages ​​and generate a consistent abstract syntax tree structure; Abstract syntax tree structure analysis: Each node in the abstract syntax tree represents a basic element of the code. The tree structure shows the nesting and dependency relationships of the code. The model can extract syntax features through nodes and obtain the execution flow and scope information of the code by traversing the tree. Syntax error handling: Design an error recovery mechanism so that the parser can generate a partial abstract syntax tree when a syntax or structural error is detected, to ensure that subsequent analysis tasks can continue; Handling of incomplete code: In code completion or real-time review scenarios, the input code may be incomplete. The parser should be able to process partial code and generate the corresponding partial abstract syntax tree. b) Cross-language parsing: ensure that the code can be parsed across multiple programming languages ​​and generate a unified grammatical structure representation; Syntactic universality: Create a universal grammatical structure representation for abstract syntax trees of different languages ​​so that the model can share knowledge between different languages; Language-specific parsing: Identify and process language-specific nodes, ensuring that language-specific rules can be incorporated during parsing; 2) Feature extraction After generating the AST of the code, the model extracts features from it. These features help the model understand the function, semantics, and context of the code. a) Context-aware: By extracting code context information, the model can understand the interdependencies between code snippets; Scope: Understand the definition and usage of variables in different scopes, extract function call chain information, and track the context of function calls; Dependencies: trace the data flow path, understand how data is passed between variables, and extract the control flow dependency information of the code, especially in conditional statements; and in loop structures; Cross-file / module context: In a project, code is usually distributed across several files or modules; the model tracks dependencies across files or modules when parsing a single file; b) Code snippet association Identify and relate different pieces of code, especially those that depend on or call each other, to improve the model's ability to understand complex code structures; Function association: Extract the calling relationship between functions in the code, build a function dependency graph, identify recursive function calls, and understand their termination conditions and execution logic; Relationship between classes and objects: For object-oriented languages, understand the inheritance relationship of classes and the interface implementation relationship, and track the creation, modification, and use of objects to ensure that the model understands the behavior, polymorphism, life cycle, and state changes of objects; Code snippet reuse: Detects repeated snippets in the code by comparing the similarities between code snippets, helping the model identify common code patterns or anti-patterns.

6. The method according to claim 1, characterized in that Defect identification aims to quickly and accurately find potential problems in your code, including: a) Multi-type defect detection: The model has the ability to accurately detect multiple types of defects in the code, covering syntax, logic, security and performance, including: Syntax error detection: By parsing the abstract syntax tree of the code, the model can identify parts that do not meet the syntax standards; the model can quickly detect through rule matching and syntax tree traversal; Logic error detection: Identify potential logic errors by analyzing control flow graphs and data flow graphs; Security vulnerability detection: The model detects common security issues by training security vulnerability datasets and combining cross-file and module dependency analysis. At the same time, the model supports the detection of specific security specifications. Performance problem detection: Performance problem detection focuses on the computational complexity and resource usage of the code. The model analyzes the execution path and resource consumption of the code to identify performance bottlenecks such as unnecessary loop nesting and invalid database queries. Code style and maintainability problem detection: detect irregular programming habits; b) Pattern recognition: Improve the coverage of defect detection by identifying common patterns and anti-patterns in the code; Common pattern recognition: The model helps developers optimize code structure and improve scalability and maintainability by learning design patterns; Anti-pattern detection: Anti-patterns refer to code patterns that are common but not recommended in the development process. Through pattern matching technology, the model identifies these unrecommended practices and reminds developers to make corresponding optimizations; 2) Optimization suggestion generation a) Multi-level suggestions: For the identified code defects, the model generates multi-level optimization suggestions and provides several solutions from simple fixes to deep optimization for developers to choose from, including: Basic repair suggestions: For syntax errors and simple logic errors, the model provides direct repair solutions; In-depth optimization suggestions: The optimization suggestions provided by the model are not limited to the code itself, but also provide system-level improvement suggestions; Best Practices Recommendations: The model provides developers with coding recommendations by learning industry-recognized best practices. Contextual association: Context-aware technology is used to generate optimization suggestions that are associated with the global context of the code, rather than just a single code snippet. The model analyzes the code structure of the entire project and provides optimization suggestions from a more global perspective.

7. The method according to claim 1, characterized in that User feedback interaction, including: 1) User interface a) Visual presentation: Intuitive user interface that presents test results and optimization suggestions in a visual way; Defect marking and highlighting: In the code editing interface, the tool will automatically mark detected defects or potential problems, and use different colors to highlight different levels of problems. Developers can directly view detailed descriptions of the problems and related optimization suggestions in the interface; Optimization suggestion panel: For each detected problem, the interface provides an optimization suggestion panel, which lists detailed repair solutions and improvement measures; the suggestions are divided into basic repair, deep optimization and best practice levels, and developers can choose the appropriate solution according to their needs; in addition, the panel also provides AI repair function, which quickly generates repair code by the model; 2) User feedback mechanism Continuous learning and improvement of the model is achieved through active feedback and automatic feedback, including: a) Feedback learning mechanism Feedback learning: After collecting user feedback, the tool stores it in a feedback database as training data for continuous model learning. By periodically retraining the model and using user feedback information to fine-tune the model, the accuracy and practicality of the model can be further improved. Feedback reward mechanism: When a user accepts a suggestion, the model will give a positive reward to the decision path behind the suggestion, otherwise it will be punished, thereby optimizing the model's parameters to make it more in line with the user's needs and usage habits; b) Automatic feedback collection mechanism: Use user behavior data to collect implicit feedback and promote self-improvement of the model; Automatically evaluate the effectiveness of suggestions: The tool tracks the developer's code modification behavior as implicit feedback; User log analysis: The tool collects user logs and analyzes developer behavior patterns to uncover user preferences and needs for code quality and optimization suggestions, and adjusts the model's decision-making strategy based on this information.

8. The method according to claim 1, characterized in that Continuous learning and updating, including: 1) Incremental Learning Incremental learning means that the model can update itself after receiving new data without losing existing knowledge; a) Online learning: The model is updated immediately upon receiving new data without the need to retrain the entire model. Specific implementation aspects: Real-time data processing: The tool collects the developer's operational behaviors and feedback information as new data inputs. The model analyzes these inputs and fine-tunes the model's parameters to optimize its ability to identify code defects in similar scenarios. Small batch updates: Whenever a certain amount of user feedback or new code samples are collected, the model will be updated in small batches, and the updated model will be immediately applied to subsequent code reviews; b) Dynamic parameter adjustment: The model dynamically adjusts its learning rate, weights, and other parameters based on the latest data to ensure greater adaptability to new programming patterns or defect types; c) Automated data update: This mechanism ensures that the model continuously obtains the latest code samples and defect information, thereby improving the generalization ability on new problems. The tool collects new code samples from sources such as user-submitted code data, various code repositories, open source projects, and internal enterprise projects. After preprocessing and standardization, it is added to the model's training data set for subsequent incremental learning and updates. 2) Continuous Improvement By introducing user feedback mechanisms and automated data updates, the model can continuously improve during operation. The improvements are not only reflected in the accuracy of problem identification and optimization suggestions, but also in the model's understanding of code structure, cross-language support, and performance optimization. a) Periodic model optimization: Regularly conduct comprehensive evaluation and optimization of the model to ensure its continuous improvement. During the evaluation process, use the test data set to perform regression testing on the model, check the performance of the model in different languages ​​and problem types, and ensure the adaptability after the technology evolves. During the optimization process, new technologies or algorithms can be introduced; b) Enhanced multi-language capabilities: As programming languages ​​are updated and new languages ​​emerge, the model will collect code samples of these new languages ​​for training through an automated data update mechanism to improve its cross-language processing capabilities; each model update will include extensions to different languages ​​to meet the needs of developers using a variety of programming languages; c) Security vulnerability priority learning: The model will give priority to learning new security vulnerabilities and their protection strategies. Whenever there is a new security vulnerability report or fix, the tool will give priority to learning and integrating it to ensure that the model can identify and fix these vulnerabilities in the first place.

Citation Information

Cited By

  • Code review method, system and electronic device

    CN119739612A

  • A code extraction and analysis method

    CN119781777A

  • Code quality optimization method and device based on causal reasoning and LLM and storage medium

    CN119938061A

  • Automatic code security optimization method based on large language model

    CN120046149A

  • System and method for static code analysis using large language model

    CN120066573A