Application framework rapid construction and reuse method and system
Through deep learning and multi-level feature extraction technology, efficient construction and reuse methods of application frameworks are solved, and the problems of insufficient understanding of code features and insufficient adaptive optimization capabilities in the existing technology are achieved, and deep understanding of code analysis and significant improvements in system performance are achieved.
Patent Information
- Application Number
- CN202510131704.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-06
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2045-02-06
AI Technical Summary
The existing application framework construction methods lack a deep understanding of code characteristics and cannot accurately grasp the multi-dimensional relationship between codes, resulting in unreasonable module division, irregular interface design, and difficulty in adapting to dynamically changing business needs. They lack adaptive optimization capabilities, which affects the maintainability and scalability of the system.
By mapping code snippets to high-dimensional tensor space, extracting multi-level features and performing cross-layer feature fusion, building a hypergraph structure to determine the multi-dimensional relationship between codes, applying deep learning technologies such as recursive neural tensor networks and Bayesian networks, combining adaptive particle filtering and multi-level generation networks, optimizing the code structure and execution paths.
It realizes a deep understanding of code structure and semantics, improves the accuracy and comprehensiveness of code analysis, significantly improves the framework's reuse efficiency and adaptability, optimizes code execution efficiency and resource utilization, and ensures the correctness and reliability of the code.
Smart Images

Figure CN119576290B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of application framework construction, and in particular to a method and system for rapid construction and reuse of an application framework. Background Art
[0002] As the scale and complexity of software systems continue to increase, the construction and reuse of application frameworks have become key technologies for improving software development efficiency. Traditional application framework construction methods mainly rely on manual experience for code organization and structural design, and reuse of functional modules through predefined interfaces and component libraries. At present, the industry widely adopts framework construction methods based on design patterns, module reuse methods based on componentization, and distributed framework construction methods based on microservices. These methods have played an important role in improving code reusability and development efficiency.
[0003] However, there are still problems with the existing application framework construction methods. The framework construction process lacks a deep understanding of code characteristics and cannot accurately grasp the multi-dimensional correlation between codes, resulting in unreasonable module division and irregular interface design; the code execution performance and resource consumption are not fully considered during the framework reuse process, which can easily introduce performance bottlenecks and reduce system operation efficiency; the existing methods are difficult to adapt to dynamically changing business needs, lack adaptive optimization capabilities, and the framework's maintainability and scalability are insufficient; the code refactoring and optimization process lacks reliable correctness guarantees and can easily introduce new program errors.
[0004] In summary, it is urgent to propose an intelligent method for rapid construction and reuse of application frameworks. Through multi-level feature extraction, we can deeply understand the semantics of the code and accurately identify the correlation between codes; based on probabilistic graph models and deep learning technology, we can achieve adaptive optimization of the framework; use formal methods to ensure the correctness of code refactoring; and improve system performance while ensuring code quality. This will not only help improve the automation level of framework construction, but also significantly enhance the reuse efficiency and adaptability of the framework, and can solve problems in existing technologies. Summary of the invention
[0005] The embodiment of the present invention provides a method and system for quickly constructing and reusing an application framework, which can solve the problems in the prior art.
[0006] According to a first aspect of the embodiments of the present invention,
[0007] A method for quickly building and reusing an application framework is provided, including:
[0008] Map the code snippet to a high-dimensional tensor space, and obtain an initial feature vector through tensor decomposition; construct a multi-channel convolution kernel group, extract code features from the lexical layer, syntax layer, data flow layer, and control flow layer based on the initial feature vector, and generate a hierarchical feature tensor; perform cross-layer feature fusion on the hierarchical feature tensor, use a dynamic weight adaptive mechanism to calculate the importance of features at each layer, and generate a fusion feature matrix; construct a hypergraph structure based on the fusion feature matrix, determine the multi-dimensional association relationship between codes, and generate a code association graph; apply a recursive neural tensor network to process the code association graph and construct a deep semantic network; integrate a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph;
[0009] Based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules and form a code dependency probability graph; a variational inference algorithm is executed on the code dependency probability graph to calculate the probability distribution of the code execution path and generate an initial reconstruction scheme; an adaptive particle filter is applied to track the code execution status of the initial reconstruction scheme and obtain a code performance indicator sequence; based on the code performance indicator sequence, topological sorting and critical path analysis are performed to determine the parallel reorganization order of code blocks; code asynchronous loading is performed according to the parallel reorganization order to generate reconstructed code; the performance bottleneck points and memory access patterns of the reconstructed code are analyzed to generate a performance feature vector;
[0010] The performance feature vector is input into a dual-dimensional discriminator to generate a discriminant score based on the code quality dimension and the execution efficiency dimension; based on the discriminant score, a multi-level generation network is driven to generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; according to the adaptive loss function, the optimized code execution program is sliced, and the code correctness is verified by symbolic execution and constraint solving; incremental synthesis is performed on the verified code fragments to generate the final optimized code.
[0011] In an optional embodiment,
[0012] Map the code snippet to a high-dimensional tensor space, and obtain the initial feature vector through tensor decomposition; construct a multi-channel convolution kernel group, extract code features from the lexical layer, syntax layer, data flow layer, and control flow layer based on the initial feature vector, and generate a hierarchical feature tensor; perform cross-layer feature fusion on the hierarchical feature tensor, and use a dynamic weight adaptive mechanism to calculate the importance of features at each layer, and generate a fusion feature matrix including:
[0013] Generate a high-dimensional feature matrix from the code snippet through a sequence encoding model and map it to a high-dimensional tensor space, perform tensor decomposition on the high-dimensional feature matrix to obtain a factor matrix, and select a corresponding number of feature vectors in the factor matrix as initial feature vectors based on a preset selection number;
[0014] Constructing a multi-channel convolution kernel group, the multi-channel convolution kernel group includes a lexical layer convolution kernel, a grammatical layer convolution kernel, a data stream layer convolution kernel and a control stream layer convolution kernel, based on the initial feature vector, using the lexical layer convolution kernel to extract lexical layer features, using the grammatical layer convolution kernel to extract grammatical layer features, using the data stream layer convolution kernel to extract data stream layer features, using the control stream layer convolution kernel to extract control stream layer features, and connecting the lexical layer features, the grammatical layer features, the data stream layer features and the control stream layer features to form a hierarchical feature tensor;
[0015] The first random noise and the second random noise are respectively superimposed on the hierarchical feature tensor to generate two perturbation feature tensors, the two perturbation feature tensors are respectively input into a feature mapping network to obtain feature representation, based on the feature representation, the similarity between the two perturbation feature tensors of the same code snippet is calculated to obtain the positive sample pair similarity, the similarity between different code snippets in any perturbation feature tensors is calculated to obtain the negative sample pair similarity, based on the positive sample pair similarity and the negative sample pair similarity, a contrast loss function is constructed, and the feature mapping network is optimized using the contrast loss function to obtain an optimized feature representation;
[0016] The two perturbation feature tensors corresponding to the optimized feature representation are subjected to feature fusion through a deep neural network, and the feature fusion result is added to the hierarchical feature tensor to obtain an enhanced feature tensor; a dynamic weight adaptive network is constructed to calculate the importance scores of the lexical layer features, grammatical layer features, data flow layer features and control flow layer features in the enhanced feature tensor, the importance scores are normalized to obtain inter-layer weight coefficients, the inter-layer weight coefficients are weighted and summed with the features of the corresponding layers, and the enhanced feature tensor is superimposed on the weighted result to obtain a fused feature matrix.
[0017] In an optional embodiment,
[0018] Constructing a hypergraph structure based on the fusion feature matrix, determining the multi-dimensional association relationship between codes, and generating a code association graph; applying a recursive neural tensor network to process the code association graph and constructing a deep semantic network; integrating a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph includes:
[0019] Extract each code snippet in the fusion feature matrix as a vertex to form a code vertex set; calculate the feature cosine similarity of any two code snippets in the code vertex set, and based on the feature cosine similarity, connect two code snippets that are greater than a preset similarity threshold to form a hyperedge, determine the weight of the hyperedge based on the feature cosine similarity, and all the hyperedges form a hyperedge set; the weights of all the hyperedges form a hyperedge weight matrix; based on the code vertex set, calculate the semantic similarity value, call chain relevance value, and data flow association value of any two code snippets, and form a multidimensional association strength matrix; combine the code vertex set, the hyperedge set, the hyperedge weight matrix, and the multidimensional association strength matrix to generate a code association graph;
[0020] Combining the hyperedge weight matrix in the code association graph and the multidimensional association strength matrix to form an edge association feature, inputting the edge association feature into a recursive neural tensor network, wherein the tensor layer of the recursive neural tensor network performs recursive calculation based on the edge association feature, a preset weight tensor, a preset weight vector, and a preset bias value, mapping the edge association feature into a semantic feature vector, performing multi-layer nonlinear transformation on the semantic feature vector, and generating a deep semantic network;
[0021] Extracting the semantic feature vector corresponding to each code snippet in the deep semantic network; calculating the correlation weights between the semantic feature vectors to generate a spatial feature matrix; extracting the execution timing sequence of the code snippet from the deep semantic network, calculating the hidden state vector and the context vector of each time step based on the execution timing sequence, calculating the temporal attention score according to the hidden state vector and the context vector, and generating a temporal feature matrix;
[0022] A spatiotemporal feature balance factor is set, and the spatial feature matrix and the temporal feature matrix are weightedly fused according to the spatiotemporal feature balance factor to generate a code spatiotemporal feature graph.
[0023] In an optional embodiment,
[0024] Based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules, and a code dependency probability graph is formed, including:
[0025] Based on the code spatiotemporal feature graph, a code feature vector is formed by dimension normalization and concatenation, and the code feature vector is stored in a corresponding node of the observation layer to obtain an observation layer feature matrix;
[0026] Based on the observation layer feature matrix, the number of function calls, the number of data flow transfers, and the number of control flow conversions between all code modules are counted, and weighted combinations are performed to calculate the conditional dependency strength matrix between modules; the conditional dependency strength matrix is used as the initial state of the hidden variable layer node, and based on the elements in the conditional dependency strength matrix that are greater than the first preset threshold, the connection relationship between the hidden variable layer nodes is constructed to obtain the hidden variable layer network structure;
[0027] Initialize the parameter layer nodes using Dirichlet distribution, establish connections between the parameter layer nodes and the nodes in the hidden variable layer network structure, establish connections between the nodes in the hidden variable layer network structure and the corresponding nodes of the observation layer feature matrix, and obtain an initial hierarchical Bayesian network in combination with preset initial probability weights;
[0028] Based on the initial hierarchical Bayesian network, a forward propagation algorithm is used to calculate the marginal probability distribution matrix of the nodes of the hidden variable layer, a joint conditional probability tensor of the nodes of the hidden variable layer is calculated based on the marginal probability distribution matrix and the chain rule, and a log-likelihood function is calculated, the log-likelihood function is derived to obtain a network parameter gradient matrix, network parameters and probability weights are updated based on the network parameter gradient matrix, and the execution is repeated until the iterative difference of the network parameters is less than a second preset threshold value, thereby obtaining an optimized hierarchical Bayesian network;
[0029] Node pairs with connection relationships are extracted from the optimized hierarchical Bayesian network to form a code module dependency edge set, the conditional probability weight of each edge in the code module dependency edge set is calculated to obtain an edge weight matrix, all corresponding nodes are formed into a node set, and a code dependency probability graph is generated based on the node set, the code module dependency edge set and the edge weight matrix.
[0030] In an optional embodiment,
[0031] Executing a variational reasoning algorithm on the code dependency probability graph, calculating the probability distribution of the code execution path, and generating an initial reconstruction plan includes:
[0032] Constructing a mean field variational distribution function, decomposing the global posterior distribution of the code dependency probability graph into the product of multiple local conditional distributions to obtain a variational distribution matrix, and calculating a conditional probability vector based on the current state of each local conditional distribution in the variational distribution matrix;
[0033] Using the conditional probability vector, a logarithmic expectation matrix is obtained by calculating the logarithmic expectation of the local conditional distribution of each code module node and the joint distribution of the corresponding adjacent code module nodes; based on the logarithmic expectation matrix, a distribution difference measurement function that measures the difference between the variational distribution and the true posterior distribution is constructed;
[0034] Calculate the gradient of the distribution difference metric function with respect to the local conditional distribution parameter of each code module node to obtain a gradient vector; update the local conditional distribution parameter of each code module node based on the gradient vector and a preset learning rate; substitute the updated local conditional distribution parameter into the variational distribution matrix and recalculate;
[0035] Repeat the execution until the change in the local conditional distribution parameters between two adjacent iterations is less than a preset change threshold, and then stop the iteration to obtain the execution path probability distribution matrix between the code module nodes; from the execution path probability distribution matrix, select the code module execution sequence with the maximum posterior probability as the optimal execution path to generate an initial reconstruction plan.
[0036] In an optional embodiment,
[0037] Applying adaptive particle filtering to track the code execution status of the initial reconstruction scheme and obtaining a code performance indicator sequence; performing topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of code blocks; performing code asynchronous loading according to the parallel reorganization order to generate reconstructed code includes:
[0038] Construct a code execution state space model, initialize a preset number of state tracking particles; calculate the Euclidean distance between each state tracking particle and the target state, and calculate the particle weight based on the Euclidean distance; calculate the inverse of the sum of squares of the particle weights as a resampling criterion value; when the resampling criterion value is less than a preset resampling threshold, resample the state tracking particles based on the particle weights, and update the state estimation value; collect the code performance indicators of the initial reconstruction scheme based on the state estimation value, and generate a code performance indicator sequence;
[0039] Based on the code performance indicator sequence, a code module dependency graph is constructed to determine the dependency strength between adjacent code modules; a candidate node queue with an in-degree of zero is maintained, a performance score of each node in the candidate node queue is calculated based on the code performance indicator sequence, a node corresponding to the maximum performance score is selected to be added to a topological sequence, and removed from the candidate node queue, the in-degree of the adjacent nodes of the node is updated, and the adjacent nodes with the in-degree updated to zero are added to the candidate node queue; the execution is repeated until the candidate node queue is empty, and a performance optimized topological sequence is obtained;
[0040] An initial earliest execution time is set for the starting code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed forward, and the earliest execution time of the target code module is added to the inter-module dependency strength to obtain the earliest execution time of the next code module; a target latest execution time is set for the terminating code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed backward, and the inter-module dependency strength is subtracted from the latest execution time of the target code module to obtain the latest execution time of the previous code module; if the earliest execution time and the latest execution time of each code module are equal, they are marked as critical path modules, and a parallel reorganization order is generated according to the position order of the critical path modules in the performance optimization topology sequence;
[0041] According to the parallel reorganization order, the codes corresponding to the critical path modules are packaged as pre-loading units, and the codes corresponding to other path modules are set as delayed loading units to generate reconstructed codes.
[0042] In an optional embodiment,
[0043] The performance feature vector is input into the dual-dimensional discriminator, and a discriminant score is generated based on the code quality dimension and the execution efficiency dimension; based on the discriminant score, a multi-level generation network is driven to generate optimized code structure, module dependency and interface protocol respectively, and the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient are calculated to construct an adaptive loss function; according to the adaptive loss function, the optimized code execution program is sliced, and the correctness of the code is verified by symbolic execution and constraint solving; incremental synthesis is performed on the verified code fragments to generate the final optimized code, including:
[0044] The performance feature vector is input into the code quality dimension discriminator and the execution efficiency dimension discriminator. The code quality dimension discriminator generates a code structure rationality score based on the forward propagation of the multi-layer perceptron. The execution efficiency dimension discriminator generates a performance optimization potential score based on the timing update of the recurrent neural network. The code structure rationality score and the performance optimization potential score are weighted and fused to obtain a comprehensive discrimination score.
[0045] Based on the comprehensive discrimination score, a code structure generator, a dependency generator and an interface protocol generator are driven to output optimized code structure, module dependency and interface protocol respectively;
[0046] According to the optimized code structure, the module dependency and the interface protocol, a maintenance coefficient, a performance efficiency coefficient and a resource consumption coefficient are calculated, and the maintenance coefficient, the performance efficiency coefficient and the resource consumption coefficient are dynamically weighted based on the comprehensive discrimination score to construct an adaptive loss function;
[0047] Extracting control dependency and data dependency from the optimized code structure based on the adaptive loss function to construct a program dependency graph, performing path constraint solving on the program dependency graph, and obtaining an input-output mapping relationship;
[0048] The code snippets are verified for equivalence according to the input-output mapping relationship, and the synthesis order is constructed according to the dependency relationship of the verified code snippets to complete the incremental code synthesis and generate the final optimized code.
[0049] According to a second aspect of the embodiments of the present invention,
[0050] Provides a system for rapid construction and reuse of application frameworks, including:
[0051] The first unit is used to map the code snippet to a high-dimensional tensor space, obtain an initial feature vector through tensor decomposition; construct a multi-channel convolution kernel group, extract code features from the lexical layer, syntax layer, data flow layer and control flow layer based on the initial feature vector, and generate a hierarchical feature tensor; perform cross-layer feature fusion on the hierarchical feature tensor, use a dynamic weight adaptive mechanism to calculate the importance of features in each layer, and generate a fusion feature matrix; construct a hypergraph structure based on the fusion feature matrix, determine the multi-dimensional association relationship between codes, and generate a code association graph; apply a recursive neural tensor network to process the code association graph and construct a deep semantic network; integrate a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph;
[0052] The second unit is used to construct a hierarchical Bayesian network model based on the code spatiotemporal feature graph, determine the conditional dependency relationship between code modules, and form a code dependency probability graph; perform a variational inference algorithm on the code dependency probability graph, calculate the probability distribution of the code execution path, and generate an initial reconstruction scheme; apply an adaptive particle filter to track the code execution state of the initial reconstruction scheme and obtain a code performance indicator sequence; perform topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of code blocks; perform asynchronous code loading according to the parallel reorganization order to generate reconstructed code; analyze the performance bottleneck points and memory access patterns of the reconstructed code to generate a performance feature vector;
[0053] The third unit is used to input the performance feature vector into a dual-dimensional discriminator, generate a discriminant score based on the code quality dimension and the execution efficiency dimension; drive a multi-level generation network based on the discriminant score, generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; execute program slicing on the optimized code according to the adaptive loss function, and verify the correctness of the code through symbolic execution and constraint solving; perform incremental synthesis on the verified code snippets to generate the final optimized code.
[0054] According to a third aspect of the embodiments of the present invention,
[0055] An electronic device is provided, comprising:
[0056] processor;
[0057] a memory for storing processor-executable instructions;
[0058] The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0059] A fourth aspect of the embodiments of the present invention is:
[0060] A computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the aforementioned method is implemented.
[0061] In the embodiment of the present invention, by mapping code snippets to high-dimensional tensor space and performing multi-level feature extraction and fusion, combined with the construction of hypergraph structure and deep semantic network, a deep understanding of code structure and semantics is achieved, and the accuracy and comprehensiveness of code analysis are improved. At the same time, the generation of spatiotemporal feature graph enables the system to better capture the dynamic execution characteristics of the code, providing a reliable basis for subsequent optimization; hierarchical Bayesian network and variational inference algorithm are used to model and analyze code dependencies, and adaptive particle filtering technology is combined to track the code execution status in real time, which can accurately identify performance bottlenecks and optimize code execution paths. The optimal parallel reorganization order is determined by topological sorting and critical path analysis, which significantly improves the execution efficiency and resource utilization of the code; the collaborative optimization mechanism of dual-dimensional discriminator and multi-level generation network is introduced, and the balanced optimization of code quality and execution efficiency is achieved through the dynamic adjustment of adaptive loss function. The verification mechanism of symbolic execution and constraint solving is combined to ensure the correctness and reliability of the optimized code, and finally high-quality optimized code is generated by incremental synthesis, which improves the overall performance and maintainability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 A schematic diagram of a process for quickly constructing and reusing an application framework according to an embodiment of the present invention;
[0063] Figure 2 It is a schematic diagram of the structure of the application framework rapid construction and reuse system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0065] The technical solution of the present invention is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0066] Figure 1 FIG. 1 is a flow chart of a method for rapidly constructing and reusing an application framework according to an embodiment of the present invention. Figure 1 As shown, the method includes:
[0067] S101. Map the code snippet to a high-dimensional tensor space, and obtain an initial feature vector through tensor decomposition; construct a multi-channel convolution kernel group, extract code features from the lexical layer, syntax layer, data flow layer, and control flow layer based on the initial feature vector, and generate a hierarchical feature tensor; perform cross-layer feature fusion on the hierarchical feature tensor, use a dynamic weight adaptive mechanism to calculate the importance of features at each layer, and generate a fusion feature matrix; construct a hypergraph structure based on the fusion feature matrix, determine the multi-dimensional association relationship between codes, and generate a code association graph; apply a recursive neural tensor network to process the code association graph and construct a deep semantic network; integrate a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph;
[0068] In this embodiment, by extracting features from the lexical layer, syntax layer, data flow layer and control flow layer, the characteristics of code snippets at different levels can be fully captured, and the accuracy and comprehensiveness of code feature representation can be improved; the dynamic weight adaptive mechanism allocates weights according to the importance of different feature layers, avoiding the information loss that may be caused by fixed weight allocation, and can effectively highlight key features and improve the rationality of feature fusion; based on the fusion feature matrix, a hypergraph structure is constructed, which can capture the complex multi-dimensional association relationship between code snippets, and a structured representation is performed through a code association graph, which is convenient for subsequent deep learning model processing; the application of recursive neural tensor networks can better handle high-order and nonlinear associations in code association graphs, generate deep semantic networks, and improve the depth and accuracy of relationship modeling between code snippets; combined with spatial attention mechanism and temporal attention mechanism, it can simultaneously focus on the structural characteristics and dynamic execution characteristics of the code, and the generated code spatiotemporal feature graph has a more comprehensive modeling of code behavior; through high-dimensional tensor mapping and feature fusion, accurate features can be extracted in complex code scenarios, and combined with deep networks and attention mechanisms, the effects of code analysis, association mining and behavior prediction can be improved.
[0069] S102. Based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules and form a code dependency probability graph; a variational inference algorithm is executed on the code dependency probability graph to calculate the probability distribution of the code execution path and generate an initial reconstruction scheme; an adaptive particle filter is applied to track the code execution status of the initial reconstruction scheme and obtain a code performance indicator sequence; based on the code performance indicator sequence, topological sorting and critical path analysis are performed to determine the parallel reorganization order of code blocks; code asynchronous loading is performed according to the parallel reorganization order to generate reconstructed code; performance bottlenecks and memory access patterns of the reconstructed code are analyzed to generate a performance feature vector;
[0070] In this embodiment, by constructing a hierarchical Bayesian network model and generating a code dependency probability graph, the conditional dependency relationship between code modules can be accurately determined, providing a reliable structured basis for code optimization; by using a variational inference algorithm to calculate the probability distribution of the code execution path, the optimal execution path solution can be identified, the code execution efficiency can be improved and resource consumption can be reduced; the adaptive particle filter can track the execution status of the initial reconstruction solution in real time, dynamically capture the performance changes and potential problems of the code, and provide refined performance monitoring; through topological sorting and critical path analysis, the optimal parallel reorganization order of code blocks is clarified, which helps to achieve efficient asynchronous code loading, thereby making full use of multi-core computing resources and improving parallel execution efficiency; after reconstructing the code, the analysis of performance bottlenecks and memory access patterns can discover the key performance limiting factors of the code, and further optimize data layout and access efficiency; generate performance feature vectors, provide high-dimensional feature representation for subsequent performance prediction and optimization, thereby supporting more intelligent optimization strategy design; combined with multi-level optimization strategies such as execution path optimization, parallel reorganization, asynchronous loading, etc., it can ultimately significantly improve code operation efficiency and system performance, while optimizing memory usage and response time.
[0071] S103. Input the performance feature vector into the dual-dimensional discriminator, and generate a discriminant score based on the code quality dimension and the execution efficiency dimension; drive a multi-level generation network based on the discriminant score to generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; execute program slicing on the optimized code according to the adaptive loss function, and verify the correctness of the code through symbolic execution and constraint solving; perform incremental synthesis on the verified code fragments to generate the final optimized code.
[0072] In this embodiment, a dual-dimensional discriminator is used to generate discriminant scores from two core dimensions: code quality and execution efficiency, providing a comprehensive and accurate evaluation basis for the code optimization process, ensuring the diversity and balance of optimization goals; a multi-level generation network is used to optimize the code structure, module dependencies, and interface protocols respectively, which can improve the maintainability, performance efficiency, and modularity of the code from different levels, thereby maximizing the overall optimization effect; the effect of code optimization is quantified by calculating the maintenance coefficient, performance efficiency coefficient, and resource consumption coefficient, which facilitates the comparison and improvement of different optimization schemes and provides data support for continuous optimization; an adaptive loss function is used according to the optimization goal. Dynamically adjust the optimization direction to ensure the global optimality of the optimized code in terms of performance and resource usage, while avoiding deviations caused by single-target optimization; combine symbolic execution and constraint solving to verify the optimized code execution program slices to ensure the logical and functional correctness of the generated code and avoid potential runtime errors introduced by optimization; perform incremental synthesis of verified code snippets to quickly generate the final optimized code while ensuring the correctness of the code, reducing repeated calculations and development costs; through the full-process optimization and verification mechanism, significantly improve the execution efficiency, modularity and maintainability of the code, providing a solid foundation for code performance optimization and long-term maintenance.
[0073] In an optional implementation, the code snippet is mapped to a high-dimensional tensor space, and an initial feature vector is obtained by tensor decomposition; a multi-channel convolution kernel group is constructed, and code features are extracted from the lexical layer, the syntax layer, the data flow layer, and the control flow layer based on the initial feature vector to generate a hierarchical feature tensor; cross-layer feature fusion is performed on the hierarchical feature tensor, and the importance of features of each layer is calculated using a dynamic weight adaptive mechanism, and the generated fusion feature matrix includes:
[0074] Generate a high-dimensional feature matrix from the code snippet through a sequence encoding model and map it to a high-dimensional tensor space, perform tensor decomposition on the high-dimensional feature matrix to obtain a factor matrix, and select a corresponding number of feature vectors in the factor matrix as initial feature vectors based on a preset selection number;
[0075] Constructing a multi-channel convolution kernel group, the multi-channel convolution kernel group includes a lexical layer convolution kernel, a grammatical layer convolution kernel, a data stream layer convolution kernel and a control stream layer convolution kernel, based on the initial feature vector, using the lexical layer convolution kernel to extract lexical layer features, using the grammatical layer convolution kernel to extract grammatical layer features, using the data stream layer convolution kernel to extract data stream layer features, using the control stream layer convolution kernel to extract control stream layer features, and connecting the lexical layer features, the grammatical layer features, the data stream layer features and the control stream layer features to form a hierarchical feature tensor;
[0076] The first random noise and the second random noise are respectively superimposed on the hierarchical feature tensor to generate two perturbation feature tensors, the two perturbation feature tensors are respectively input into a feature mapping network to obtain feature representation, based on the feature representation, the similarity between the two perturbation feature tensors of the same code snippet is calculated to obtain the positive sample pair similarity, the similarity between different code snippets in any perturbation feature tensors is calculated to obtain the negative sample pair similarity, based on the positive sample pair similarity and the negative sample pair similarity, a contrast loss function is constructed, and the feature mapping network is optimized using the contrast loss function to obtain an optimized feature representation;
[0077] The two perturbation feature tensors corresponding to the optimized feature representation are subjected to feature fusion through a deep neural network, and the feature fusion result is added to the hierarchical feature tensor to obtain an enhanced feature tensor; a dynamic weight adaptive network is constructed to calculate the importance scores of the lexical layer features, grammatical layer features, data flow layer features and control flow layer features in the enhanced feature tensor, the importance scores are normalized to obtain inter-layer weight coefficients, the inter-layer weight coefficients are weighted and summed with the features of the corresponding layers, and the enhanced feature tensor is superimposed on the weighted result to obtain a fused feature matrix.
[0078] In a specific implementation, the code snippet is first converted into a high-dimensional feature matrix through a sequence encoding model. In the specific implementation, the Transformer encoder is used to encode the code, and the input code snippet is passed through the word embedding layer to obtain an initial vector sequence, which is mapped to a 512-dimensional feature space after being processed by a multi-head self-attention mechanism and a feedforward neural network to generate a high-dimensional feature matrix. Tucker decomposition is performed on the feature matrix to obtain a core tensor and three factor matrices. Based on the preset selection number k (k=16 in practice), the k eigenvectors with the largest corresponding dimensions are selected from the factor matrix as the initial eigenvectors.
[0079] Construct a multi-channel convolution kernel group to extract multi-level features. The lexical layer convolution kernel uses 1×1 convolution to extract lexical features such as identifiers and keywords; the grammatical layer convolution kernel uses 3×3 convolution to extract grammatical structure features; the data flow layer convolution kernel uses 5×5 convolution to extract variable definition usage relationship features; the control flow layer convolution kernel uses 7×7 convolution to extract program execution path features. With the initial feature vector as input, feature extraction is performed through four types of convolution kernels respectively. In specific implementation, the lexical layer uses 32 convolution kernels, the grammatical layer uses 64 convolution kernels, the data flow layer uses 128 convolution kernels, and the control flow layer uses 256 convolution kernels. Connect the four layers of features in the channel dimension to form a hierarchical feature tensor.
[0080] A contrastive learning mechanism is introduced to the hierarchical feature tensor to enhance the feature representation. Two perturbation versions are generated by random dropout and Gaussian noise, and the perturbation strength is set to 0.1 and 0.2 respectively. The perturbation feature tensor is input into the feature mapping network composed of three layers of fully connected networks to obtain a 128-dimensional feature representation. The cosine similarity of the feature representation of the two perturbation versions of the same code snippet is calculated as the similarity of the positive sample pair, and the cosine similarity between any perturbation versions of different code snippets is calculated as the similarity of the negative sample pair. The contrastive loss is constructed based on the InfoNCE loss function, and the temperature coefficient is set to 0.07. The parameters of the feature mapping network are optimized by stochastic gradient descent to obtain a more discriminative feature representation.
[0081] The two optimized perturbation feature representations are input into the multilayer perceptron network for feature fusion. The fusion network contains two hidden layers with 256 and 512 neurons respectively. The fusion result is residually connected with the original hierarchical feature tensor to obtain the enhanced feature tensor. A dynamic weight adaptive network is constructed to calculate the importance of the four-level features. The network consists of an attention layer and a softmax layer. The importance scores are normalized to obtain the inter-layer weight coefficients. In practice, the typical values of the weight coefficients of the lexical layer, grammatical layer, data flow layer, and control flow layer are 0.1, 0.2, 0.3, and 0.4 respectively. The weight coefficients are weighted and summed with the corresponding layer features, and the enhanced feature tensor is superimposed to finally obtain the fusion feature matrix.
[0082] In a specific application, the input code length is 256 tokens, and after the above processing, a 768-dimensional fusion feature representation is obtained. Experiments show that this method can improve the performance of downstream tasks by 15-20% compared with a single feature extraction method. Fusion features can more comprehensively characterize the lexical, grammatical, and semantic features of the code, and have stronger expressiveness and robustness.
[0083] In this embodiment, through a multi-level feature extraction and fusion mechanism, feature information in multiple dimensions such as code lexical, grammatical, data flow and control flow can be fully captured, thereby improving the completeness and accuracy of code analysis; contrastive learning and random perturbations are used to enhance the robustness of feature representation, so that the model can better adapt to subtle changes in the code and improve the generalization ability of feature extraction; the state weight adaptive mechanism can automatically adjust the fusion weight according to the importance of features at different levels, thereby realizing intelligent fusion of features and improving the expressiveness and distinguishability of fused features.
[0084] In an optional implementation, constructing a hypergraph structure based on the fused feature matrix, determining the multidimensional association relationship between codes, and generating a code association graph; applying a recursive neural tensor network to process the code association graph to construct a deep semantic network; integrating a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph includes:
[0085] Extract each code snippet in the fusion feature matrix as a vertex to form a code vertex set; calculate the feature cosine similarity of any two code snippets in the code vertex set, and based on the feature cosine similarity, connect two code snippets that are greater than a preset similarity threshold to form a hyperedge, determine the weight of the hyperedge based on the feature cosine similarity, and all the hyperedges form a hyperedge set; the weights of all the hyperedges form a hyperedge weight matrix; based on the code vertex set, calculate the semantic similarity value, call chain relevance value, and data flow association value of any two code snippets, and form a multidimensional association strength matrix; combine the code vertex set, the hyperedge set, the hyperedge weight matrix, and the multidimensional association strength matrix to generate a code association graph;
[0086] Combining the hyperedge weight matrix in the code association graph and the multidimensional association strength matrix to form an edge association feature, inputting the edge association feature into a recursive neural tensor network, wherein the tensor layer of the recursive neural tensor network performs recursive calculation based on the edge association feature, a preset weight tensor, a preset weight vector, and a preset bias value, mapping the edge association feature into a semantic feature vector, performing multi-layer nonlinear transformation on the semantic feature vector, and generating a deep semantic network;
[0087] Extracting the semantic feature vector corresponding to each code snippet in the deep semantic network; calculating the correlation weights between the semantic feature vectors to generate a spatial feature matrix; extracting the execution timing sequence of the code snippet from the deep semantic network, calculating the hidden state vector and the context vector of each time step based on the execution timing sequence, calculating the temporal attention score according to the hidden state vector and the context vector, and generating a temporal feature matrix;
[0088] A spatiotemporal feature balance factor is set, and the spatial feature matrix and the temporal feature matrix are weightedly fused according to the spatiotemporal feature balance factor to generate a code spatiotemporal feature graph.
[0089] The hyperedge specifically refers to the representation of the association relationship between two or more code snippets in the code association graph, reflecting the high-order association characteristics between these code snippets. The construction of a hyperedge is usually based on a specific similarity metric, such as feature cosine similarity. The weight of the hyperedge is used to indicate the strength of the association relationship between the connected code snippets.
[0090] The semantic similarity value specifically refers to the value used to measure the semantic similarity between any two code snippets. This similarity reflects the functional or logical similarity of the code snippets, and is usually calculated based on the semantic feature vector of the code.
[0091] The call chain correlation value specifically refers to the correlation strength between code snippets in the call relationship. It reflects the closeness of the direct or indirect call relationship between one code snippet and another code snippet, and is a structured correlation indicator.
[0092] The data flow correlation value specifically refers to the dependency between code snippets in data flow, including the correlation strength in terms of variable transfer, parameter sharing, or result use between code snippets, reflecting the closeness of their interaction at the data level.
[0093] The spatiotemporal feature balance factor specifically refers to an important parameter used to coordinate spatial features (such as static association characteristics between code snippets) and temporal features (such as execution timing characteristics of code snippets). By adjusting this factor, the contribution ratio of the spatial feature matrix and the temporal feature matrix can be balanced when generating the code spatiotemporal feature graph, so that the result is more in line with the needs of specific analysis scenarios.
[0094] In a specific embodiment, when constructing a hypergraph structure based on a fused feature matrix, each code snippet is first extracted from the fused feature matrix as a vertex. For each code snippet, its feature vector is extracted, including lexical features, grammatical features, and semantic features. The similarity between any two code snippets is measured by calculating the cosine similarity value between their feature vectors. When the similarity value of two code snippets exceeds a preset threshold (such as 0.8), a hyperedge connection is established between the two vertices. The weight of the hyperedge is set to the corresponding similarity value.
[0095] When constructing multi-dimensional association relationships, it is necessary to analyze the semantic similarity, call chain relevance, and data flow relevance between code snippets. Semantic similarity is calculated by analyzing the text information such as the function description, variable naming, and comments of the code; call chain relevance is obtained by analyzing the function call relationship between codes; and data flow relevance is determined by tracking the definition and usage relationship of variables. The association strength values of these three dimensions form a multi-dimensional association strength matrix.
[0096] The hypergraph structure is input into the recursive neural tensor network for processing. The input of the network includes the hyperedge weight matrix and the multi-dimensional association strength matrix. In the tensor layer, by setting the appropriate weight tensor, weight vector and bias value, the input features are recursively calculated to map the edge association features into semantic feature vectors. Then, through multiple layers of nonlinear transformation, a network structure containing deep semantic information is generated.
[0097] Based on the deep semantic network, the spatial attention mechanism and the temporal attention mechanism are introduced. The spatial attention mechanism generates a spatial feature matrix by calculating the relevant weights between the semantic feature vectors corresponding to different code snippets, capturing the spatial dependencies between codes. The temporal attention mechanism calculates the hidden state and context information of each time step based on the execution order of the code, and then obtains the temporal feature matrix to characterize the temporal dependencies of the code.
[0098] Finally, a spatiotemporal feature balance factor (such as 0.6) is introduced to adjust the importance of spatial features and temporal features. The final code spatiotemporal feature graph is generated by weighted fusion of the spatial feature matrix and the temporal feature matrix, realizing a comprehensive expression of the spatiotemporal dependency of the code.
[0099] In this embodiment, by constructing a hypergraph structure and multi-dimensional association relationships, the complex association relationships between code snippets can be fully characterized, avoiding the limitation of traditional graph structures that can only express binary relationships, and improving the accuracy and completeness of code association analysis; a recursive neural tensor network is used to process the code association graph, and the deep semantic features of the code are automatically extracted through deep learning methods, overcoming the defects of traditional methods that rely on artificial feature engineering, and enhancing the robustness and generalization ability of feature expression; combining spatial attention mechanism and temporal attention mechanism, accurate modeling of code spatiotemporal dependency is achieved, and through dynamic adjustment of spatiotemporal feature balance factors, the rationality of feature fusion is guaranteed, and the accuracy and efficiency of code analysis are improved.
[0100] In an optional implementation, based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules, and the code dependency probability graph is formed, including:
[0101] Based on the code spatiotemporal feature graph, a code feature vector is formed by dimension normalization and concatenation, and the code feature vector is stored in a corresponding node of the observation layer to obtain an observation layer feature matrix;
[0102] Based on the observation layer feature matrix, the number of function calls, the number of data flow transfers, and the number of control flow conversions between all code modules are counted, and weighted combinations are performed to calculate the conditional dependency strength matrix between modules; the conditional dependency strength matrix is used as the initial state of the hidden variable layer node, and based on the elements in the conditional dependency strength matrix that are greater than the first preset threshold, the connection relationship between the hidden variable layer nodes is constructed to obtain the hidden variable layer network structure;
[0103] Initialize the parameter layer nodes using Dirichlet distribution, establish connections between the parameter layer nodes and the nodes in the hidden variable layer network structure, establish connections between the nodes in the hidden variable layer network structure and the corresponding nodes of the observation layer feature matrix, and obtain an initial hierarchical Bayesian network in combination with preset initial probability weights;
[0104] Based on the initial hierarchical Bayesian network, a forward propagation algorithm is used to calculate the marginal probability distribution matrix of the nodes of the hidden variable layer, a joint conditional probability tensor of the nodes of the hidden variable layer is calculated based on the marginal probability distribution matrix and the chain rule, and a log-likelihood function is calculated, the log-likelihood function is derived to obtain a network parameter gradient matrix, network parameters and probability weights are updated based on the network parameter gradient matrix, and the execution is repeated until the iterative difference of the network parameters is less than a second preset threshold value, thereby obtaining an optimized hierarchical Bayesian network;
[0105] Node pairs with connection relationships are extracted from the optimized hierarchical Bayesian network to form a code module dependency edge set, the conditional probability weight of each edge in the code module dependency edge set is calculated to obtain an edge weight matrix, all corresponding nodes are formed into a node set, and a code dependency probability graph is generated based on the node set, the code module dependency edge set and the edge weight matrix.
[0106] The hierarchical Bayesian network model includes an observation layer, a latent variable layer and a parameter layer;
[0107] The observation layer specifically refers to the bottom layer of the Bayesian network, which contains features extracted or calculated directly from the data. These features reflect the basic properties between code modules, such as the code feature vector generated by the code spatiotemporal feature graph, the number of function calls, the number of data flow transfers, the number of control flow conversions, etc. The observation layer is explicit and can be obtained through statistics or analysis.
[0108] The hidden variable layer is located above the observation layer and is used to model the potential dependencies between code modules. It initializes the node state through the conditional dependency strength matrix to reflect the implicit association information between modules. The connection relationship between nodes in the hidden variable layer is determined by the conditional dependency strength exceeding the preset threshold and presented in the form of a network structure.
[0109] The parameter layer provides the prior information of probability distribution for the Bayesian network. The parameter layer nodes are initialized by Dirichlet distribution, which establishes a connection with the hidden variable layer to help define the probability relationship between nodes. The parameter layer is used to support the learning and optimization process of the network, such as calculating probability weights and updating network parameters.
[0110] The chain rule specifically refers to a basic rule in probability theory for decomposing joint probability distributions. It states that the joint probability of a set of events can be expressed as the product of the conditional probabilities of these events, thereby recursively decomposing a complex joint probability into a series of smaller conditional probabilities. The chain rule is the core principle for calculating the joint conditional probability of nodes in the hidden variable layer in Bayesian networks, and is used to represent and derive complex dependencies.
[0111] In a specific implementation, first, a feature vector is constructed for the code spatiotemporal feature graph. The node attributes, edge attributes and other information in the code spatiotemporal feature graph are extracted, including function call relationships, variable dependencies, control flow information, etc. These features are dimensionally normalized, and the feature values of different dimensions are mapped between 0 and 1. The normalized features are then concatenated into feature vectors in a predefined order. For example, the feature vector of a code module may be [0.8, 0.3, 0.5, 0.6], which respectively represent the function complexity, number of variables, call depth, control flow complexity and other features. The feature vectors of all code modules form an observation layer feature matrix.
[0112] Next, conditional dependencies are constructed based on the observation layer feature matrix. The number of function calls, data flow transfers, and control flow conversions between code modules are counted. For example, if module A calls module B's function 10 times, data flow transfers 5 times, and control flow conversions 3 times, the weights can be set to 0.5, 0.3, and 0.2, respectively, and the weighted conditional dependency strength is 8.5. The conditional dependency strength is calculated for all module pairs to form a dependency strength matrix. Set the first preset threshold to 0.6. When the dependency strength is greater than 0.6, a connection is established between the corresponding hidden variable layer nodes.
[0113] Then, initialize the parameter layer and build the complete network. Use Dirichlet distribution to generate the initial values of the parameter layer nodes. For example, for binary relationships, they can be initialized to [0.3, 0.7]. Connect the parameter layer nodes to the hidden variable layer nodes, and set the initial probability weights to uniform distribution. At the same time, connect the hidden variable layer nodes to the corresponding nodes of the observation layer to form a three-layer network structure.
[0114] After that, the network is optimized and trained. The marginal probability distribution of the nodes in the hidden variable layer is calculated by forward propagation, for example, the probability distribution of node A is [0.4, 0.6]. The joint probability distribution is calculated based on the marginal probability and conditional probability. The log-likelihood function value is calculated and the parameter gradient is derived. The network parameters and probability weights are updated using the gradient descent method. The iteration is stopped when the parameter update amount is less than the second preset threshold (such as 0.001).
[0115] Finally, the code dependency is extracted from the optimized network. The node pairs with connections are taken as dependency edges, and their conditional probabilities are taken as edge weights. For example, if the probability that module A depends on module B is 0.8, a directed edge with a weight of 0.8 is added to the dependency graph. Finally, a code dependency probability graph containing a node set, an edge set, and an edge weight matrix is obtained.
[0116] In this embodiment, by constructing a hierarchical Bayesian network model to analyze code dependencies, the conditional dependency strength between code modules can be accurately identified, thereby improving the accuracy and reliability of dependency identification; a three-layer network structure and an iterative optimization strategy are adopted to make full use of the spatiotemporal feature information of the code, which can effectively capture the potential dependency patterns between code modules and enhance the depth and breadth of dependency analysis; dependencies are represented based on a probabilistic graph model, which not only retains the quantitative information of dependency strength, but also reflects the uncertainty of dependencies, thereby providing more valuable dependency information support for subsequent code reconstruction, test case generation and other tasks.
[0117] In an optional implementation, performing a variational inference algorithm on the code dependency probability graph, calculating the probability distribution of the code execution path, and generating an initial reconstruction scheme includes:
[0118] Constructing a mean field variational distribution function, decomposing the global posterior distribution of the code dependency probability graph into the product of multiple local conditional distributions to obtain a variational distribution matrix, and calculating a conditional probability vector based on the current state of each local conditional distribution in the variational distribution matrix;
[0119] Using the conditional probability vector, a logarithmic expectation matrix is obtained by calculating the logarithmic expectation of the local conditional distribution of each code module node and the joint distribution of the corresponding adjacent code module nodes; based on the logarithmic expectation matrix, a distribution difference measurement function that measures the difference between the variational distribution and the true posterior distribution is constructed;
[0120] Calculate the gradient of the distribution difference metric function with respect to the local conditional distribution parameter of each code module node to obtain a gradient vector; update the local conditional distribution parameter of each code module node based on the gradient vector and a preset learning rate; substitute the updated local conditional distribution parameter into the variational distribution matrix and recalculate;
[0121] Repeat the execution until the change in the local conditional distribution parameters between two adjacent iterations is less than a preset change threshold, and then stop the iteration to obtain the execution path probability distribution matrix between the code module nodes; from the execution path probability distribution matrix, select the code module execution sequence with the maximum posterior probability as the optimal execution path to generate an initial reconstruction plan.
[0122] In a specific implementation, when performing a variational inference algorithm on a code dependency probability graph, it is first necessary to construct a mean field variational distribution function. This function decomposes the global posterior distribution of the code dependency probability graph into the product of multiple local conditional distributions. In specific implementation, for each code module node, a corresponding local conditional distribution function is established, and the product of these local distribution functions is used as an approximate expression of the variational distribution. For example, for a dependency graph containing five code module nodes, it can be decomposed into five independent local conditional distributions, and the parameters of these distributions are stored in a variational distribution matrix.
[0123] Based on the current state of each local conditional distribution in the variational distribution matrix, the conditional probability vector is calculated. In the specific implementation, for each code module node, the dependency relationship between it and the adjacent nodes is considered, and the conditional probability of the node is calculated given the state of other nodes. For example, for a code module node, the conditional probability values between the nodes directly connected to it can be calculated by analyzing its call relationship and data flow dependency.
[0124] Using the calculated conditional probability vector, the logarithmic expectation between the local conditional distribution of each code module node and the joint distribution of the adjacent nodes is analyzed. These logarithmic expectation values are stored in the logarithmic expectation matrix. Based on this matrix, a metric function is constructed to measure the difference between the variational distribution and the true posterior distribution. This function can reflect the approximation degree of the current variational distribution to the true distribution.
[0125] Next, the gradient of the metric function with respect to the local conditional distribution parameters of each code module node is calculated. In specific implementation, the coordinate descent method can be used to update the distribution parameters of each node one by one. After obtaining the gradient vector, the local conditional distribution parameters of each node are updated in combination with the pre-set learning rate parameters. For example, the learning rate can be set to 0.01, and the distribution parameters can be optimized by gradient descent.
[0126] Substitute the updated parameters into the variational distribution matrix and recalculate the conditional probabilities between nodes. Through multiple iterations of optimization, the iteration is stopped when the change in the local conditional distribution parameters between two adjacent iterations is less than the preset threshold (such as 0.001). Finally, the execution path probability distribution matrix between the code module nodes is obtained.
[0127] From the execution path probability distribution matrix, the code module execution sequence with the maximum a posteriori probability is selected as the optimal execution path. For example, if the obtained probability distribution matrix shows that the execution path of module A→module B→module D→module C→module E has the maximum a posteriori probability, then this path is used as a reference for code refactoring to generate an initial refactoring plan.
[0128] In this embodiment, by constructing a mean field variational distribution function and performing iterative optimization, the computational complexity can be effectively reduced, making it possible to perform probabilistic reasoning on large-scale code dependency graphs, thereby improving the practicality and scalability of the algorithm; the calculation method of conditional probability vectors and logarithmic expectation matrices can accurately capture the dependencies and execution order between code modules, ensuring that the generated reconstruction scheme can maintain the functional integrity and correctness of the original code; the method of selecting the optimal execution path based on the maximum a posteriori probability can find the most reasonable code module organization structure, which helps to improve the maintainability and readability of the code and reduce the cost of subsequent development and maintenance.
[0129] In an optional implementation, applying adaptive particle filtering, tracking the code execution state of the initial reconstruction scheme, and obtaining a code performance indicator sequence; performing topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of code blocks; and performing code asynchronous loading according to the parallel reorganization order to generate the reconstructed code includes:
[0130] Construct a code execution state space model, initialize a preset number of state tracking particles; calculate the Euclidean distance between each state tracking particle and the target state, and calculate the particle weight based on the Euclidean distance; calculate the inverse of the sum of squares of the particle weights as a resampling criterion value; when the resampling criterion value is less than a preset resampling threshold, resample the state tracking particles based on the particle weights, and update the state estimation value; collect the code performance indicators of the initial reconstruction scheme based on the state estimation value, and generate a code performance indicator sequence;
[0131] Based on the code performance indicator sequence, a code module dependency graph is constructed to determine the dependency strength between adjacent code modules; a candidate node queue with an in-degree of zero is maintained, a performance score of each node in the candidate node queue is calculated based on the code performance indicator sequence, a node corresponding to the maximum performance score is selected to be added to a topological sequence, and removed from the candidate node queue, the in-degree of the adjacent nodes of the node is updated, and the adjacent nodes with the in-degree updated to zero are added to the candidate node queue; the execution is repeated until the candidate node queue is empty, and a performance optimized topological sequence is obtained;
[0132] An initial earliest execution time is set for the starting code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed forward, and the earliest execution time of the target code module is added to the inter-module dependency strength to obtain the earliest execution time of the next code module; a target latest execution time is set for the terminating code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed backward, and the inter-module dependency strength is subtracted from the latest execution time of the target code module to obtain the latest execution time of the previous code module; if the earliest execution time and the latest execution time of each code module are equal, they are marked as critical path modules, and a parallel reorganization order is generated according to the position order of the critical path modules in the performance optimization topology sequence;
[0133] According to the parallel reorganization order, the codes corresponding to the critical path modules are packaged as pre-loading units, and the codes corresponding to other path modules are set as delayed loading units to generate reconstructed codes.
[0134] In a specific implementation, a code execution state space model is first constructed, which includes key indicators such as CPU occupancy, memory usage, and number of threads during code execution. 100 state tracking particles are initialized, and each particle carries the estimated values of these indicators. For each state tracking particle, the Euclidean distance to the target state is calculated using the real execution data collected in real time. For example, if the CPU occupancy of the current particle is 75%, the target state is 80%, the memory usage is 500MB, and the target is 450MB, the distance value between the particle and the target state can be calculated. A weight is assigned to each particle based on the distance value, and the smaller the distance, the greater the weight.
[0135] Calculate the inverse of the sum of squares of all particle weights as the resampling criterion value, and set the resampling threshold to 0.5. When the criterion value is less than 0.5, the resampling process is triggered. During resampling, particles with larger weights will be copied multiple times, and particles with smaller weights will be eliminated, keeping the total number of particles unchanged. In this way, the particle swarm will gradually move closer to the actual code execution state. Based on the updated particle state, performance indicators during code execution are continuously collected, including response time, throughput, resource utilization, etc., to form a sequence of timing performance indicators.
[0136] Next, we build a code module dependency graph based on the performance indicator sequence. By analyzing the code call relationship, we determine the dependency strength between modules. For example, if module A calls module B 100 times per second, the dependency strength between the two is 100. We maintain a candidate node queue with an in-degree of zero, and initially add all nodes with an in-degree of zero to the queue. We calculate the performance score of the candidate node, which is calculated based on the node's response time, resource usage and other indicators. We select the node with the highest score to join the topological sequence, and update the in-degree of its adjacent nodes. When the in-degree of a node becomes zero, we add it to the candidate queue. We repeat this process until the candidate queue is empty, and we get a topological sequence optimized for performance.
[0137] Set the initial earliest execution time of the starting module in the topology sequence to 0 milliseconds. During forward traversal, the earliest execution time of a module plus the dependency strength with the next module is the earliest execution time of the next module. For example, if the earliest execution time of module A is 0 milliseconds and the dependency strength with module B is 100 milliseconds, then the earliest execution time of module B is 100 milliseconds. Set the target latest execution time of the terminating module to 1000 milliseconds, and traverse backward to calculate the latest execution time of each module. The module whose earliest execution time is equal to the latest execution time is the critical path module.
[0138] Finally, the parallel reorganization order is generated according to the position order of the critical path modules in the topological sequence. The code corresponding to the critical path module is packaged as a preload unit and loaded first when the application starts. The code of other path modules is set as a delayed loading unit and loaded when actually needed, thereby generating performance-optimized reconstructed code.
[0139] In this embodiment, accurate tracking of code execution status is achieved through adaptive particle filtering, which improves the accuracy and reliability of performance indicator collection and provides a reliable data basis for subsequent optimization; reasonable scheduling of code modules is achieved based on topological sorting and critical path analysis methods, which fully considers the dependencies and performance characteristics between modules and ensures the correctness and efficiency of code execution after reconstruction; a strategy combining preloading and delayed loading is adopted to significantly reduce application startup time, optimize resource utilization efficiency, improve code execution performance, and ensure functional integrity and stability.
[0140] In an optional implementation, the performance feature vector is input into a dual-dimensional discriminator, and a discriminant score is generated based on the code quality dimension and the execution efficiency dimension; based on the discriminant score, a multi-level generation network is driven to generate optimized code structure, module dependency and interface protocol respectively, and a maintenance coefficient, a performance efficiency coefficient and a resource consumption coefficient are calculated to construct an adaptive loss function; program slicing is performed on the optimized code according to the adaptive loss function, and the correctness of the code is verified by symbolic execution and constraint solving; incremental synthesis is performed on the verified code fragments to generate the final optimized code, including:
[0141] The performance feature vector is input into the code quality dimension discriminator and the execution efficiency dimension discriminator. The code quality dimension discriminator generates a code structure rationality score based on the forward propagation of the multi-layer perceptron. The execution efficiency dimension discriminator generates a performance optimization potential score based on the timing update of the recurrent neural network. The code structure rationality score and the performance optimization potential score are weighted and fused to obtain a comprehensive discrimination score.
[0142] Based on the comprehensive discrimination score, a code structure generator, a dependency generator and an interface protocol generator are driven to output optimized code structure, module dependency and interface protocol respectively; according to the optimized code structure, the module dependency and the interface protocol, a maintenance coefficient, a performance efficiency coefficient and a resource consumption coefficient are calculated, and the maintenance coefficient, the performance efficiency coefficient and the resource consumption coefficient are dynamically weighted based on the comprehensive discrimination score to construct an adaptive loss function;
[0143] Extracting control dependency and data dependency from the optimized code structure based on the adaptive loss function to construct a program dependency graph, performing path constraint solving on the program dependency graph, and obtaining an input-output mapping relationship;
[0144] The code snippets are verified for equivalence according to the input-output mapping relationship, and the synthesis order is constructed according to the dependency relationship of the verified code snippets to complete the incremental code synthesis and generate the final optimized code.
[0145] In a specific implementation, first, feature extraction is performed on the input code to construct a performance feature vector. The feature vector contains static features such as code complexity index, loop nesting depth, number of branch statements, function call relationship, and dynamic features such as CPU usage, memory usage, and response time. These features are normalized to form a feature vector.
[0146] In the code quality dimension discriminator, a multi-layer perceptron structure is used, which includes an input layer, three hidden layers, and an output layer. The input layer receives the performance feature vector, and the output layer generates the code structure rationality score through the nonlinear transformation of the hidden layer. In the specific implementation, the hidden layer uses the ReLU activation function, and the output layer uses the Sigmoid function to map the score to the range of zero to one.
[0147] The execution efficiency dimension discriminator adopts a long short-term memory network structure, which includes an input gate, a forget gate, and an output gate. The discriminator receives the timing features during code execution, learns long-term dependencies through a gating mechanism, and outputs a performance optimization potential score. The scores of the two dimensions are fused through adaptive weights to obtain a comprehensive discrimination score.
[0148] Based on the comprehensive discriminant score, three generator networks are driven. The code structure generator uses an encoder-decoder architecture to encode the original code structure into an intermediate representation, and then decodes it to generate an optimized code structure. The dependency generator uses a graph neural network to model the calling relationship between modules and generate an optimized dependency graph. The interface protocol generator analyzes the interface definition based on the attention mechanism and generates a standardized interface description.
[0149] According to the generated optimization plan, three key coefficients are calculated: the maintenance coefficient reflects the maintainability of the code, which is calculated by statistical cyclomatic complexity, code repetition rate and other indicators; the performance efficiency coefficient measures the operating efficiency, based on indicators such as execution time and resource occupancy; the resource consumption coefficient evaluates the system overhead, taking into account the use of resources such as memory and CPU. These coefficients and the comprehensive discriminant score jointly construct the adaptive loss function.
[0150] Next, we slice the program and build a program dependency graph through control flow analysis and data flow analysis. We perform symbolic execution on the dependency graph and collect path constraints. We verify the satisfiability of these conditions through the constraint solver and obtain the input-output mapping relationship. For each code snippet, we compare whether the input and output behaviors before and after optimization are equivalent.
[0151] Finally, the verified code snippets are sorted according to the dependencies and synthesized incrementally. First, the basic functional modules are synthesized, and then the dependent modules are gradually added to ensure interface matching, and finally a complete optimized code is generated.
[0152] In this embodiment, a comprehensive evaluation of code quality and execution efficiency is achieved through dual-dimensional judgment, which overcomes the limitations of traditional single-dimensional evaluation and improves the accuracy and reliability of the optimization scheme. A multi-level generation network is used to collaboratively optimize the code structure, dependencies and interface protocols, and code optimization from multiple levels is achieved. At the same time, an adaptive loss function is used to dynamically balance various optimization goals to ensure the balance of the optimization results. Program slicing and symbolic execution technology are introduced to verify the correctness of the code, and the incremental synthesis strategy is combined to ensure the controllability of the optimization process, which significantly improves the security and reliability of code optimization and reduces the risk of introducing defects in the optimization process.
[0153] Figure 2 FIG. 1 is a schematic diagram of a structure of a system for rapidly building and reusing an application framework according to an embodiment of the present invention. Figure 2 As shown, the system comprises:
[0154] The first unit is used to map the code snippet to a high-dimensional tensor space, obtain an initial feature vector through tensor decomposition; construct a multi-channel convolution kernel group, extract code features from the lexical layer, syntax layer, data flow layer and control flow layer based on the initial feature vector, and generate a hierarchical feature tensor; perform cross-layer feature fusion on the hierarchical feature tensor, use a dynamic weight adaptive mechanism to calculate the importance of features in each layer, and generate a fusion feature matrix; construct a hypergraph structure based on the fusion feature matrix, determine the multi-dimensional association relationship between codes, and generate a code association graph; apply a recursive neural tensor network to process the code association graph and construct a deep semantic network; integrate a spatial attention mechanism and a temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature graph;
[0155] The second unit is used to construct a hierarchical Bayesian network model based on the code spatiotemporal feature graph, determine the conditional dependency relationship between code modules, and form a code dependency probability graph; perform a variational inference algorithm on the code dependency probability graph, calculate the probability distribution of the code execution path, and generate an initial reconstruction scheme; apply an adaptive particle filter to track the code execution state of the initial reconstruction scheme and obtain a code performance indicator sequence; perform topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of code blocks; perform asynchronous code loading according to the parallel reorganization order to generate reconstructed code; analyze the performance bottleneck points and memory access patterns of the reconstructed code to generate a performance feature vector;
[0156] The third unit is used to input the performance feature vector into a dual-dimensional discriminator, generate a discriminant score based on the code quality dimension and the execution efficiency dimension; drive a multi-level generation network based on the discriminant score, generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; execute program slicing on the optimized code according to the adaptive loss function, and verify the correctness of the code through symbolic execution and constraint solving; perform incremental synthesis on the verified code snippets to generate the final optimized code.
[0157] According to a third aspect of the embodiments of the present invention,
[0158] An electronic device is provided, comprising:
[0159] processor;
[0160] a memory for storing processor-executable instructions;
[0161] The processor is configured to call the instructions stored in the memory to execute the aforementioned method.
[0162] A fourth aspect of the embodiments of the present invention is:
[0163] A computer-readable storage medium is provided, on which computer program instructions are stored. When the computer program instructions are executed by a processor, the aforementioned method is implemented.
[0164] The present invention may be a method, an apparatus, a system and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for executing various aspects of the present invention.
[0165] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for rapidly building and reusing an application framework, characterized in that: include: Map the code snippet to a high-dimensional tensor space and obtain the initial feature vector through tensor decomposition; Constructing a multi-channel convolution kernel group, extracting code features from the lexical layer, the grammatical layer, the data flow layer, and the control flow layer based on the initial feature vector, and generating a hierarchical feature tensor; Performing cross-layer feature fusion on the hierarchical feature tensor, calculating the importance of features at each layer using a dynamic weight adaptive mechanism, and generating a fused feature matrix; Based on the fusion feature matrix, a hypergraph structure is constructed to determine the multi-dimensional association relationship between codes and generate a code association graph; a recursive neural tensor network is applied to process the code association graph to construct a deep semantic network; Integrating the spatial attention mechanism and the temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature map; Based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules and form a code dependency probability graph; Execute a variational inference algorithm on the code dependency probability graph, calculate the probability distribution of the code execution path, and generate an initial reconstruction scheme; apply an adaptive particle filter to track the code execution state of the initial reconstruction scheme and obtain a code performance indicator sequence; perform topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of the code blocks; Asynchronous loading of code is performed according to the parallel reorganization sequence to generate reconstructed code; Analyze the performance bottlenecks and memory access patterns of the reconstructed code to generate a performance feature vector; Inputting the performance feature vector into a dual-dimensional discriminator to generate a discriminant score based on a code quality dimension and an execution efficiency dimension; Based on the discriminant score, a multi-level generation network is driven to generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; the optimized code execution program is sliced according to the adaptive loss function, and the code correctness is verified by symbolic execution and constraint solving; incremental synthesis is performed on the verified code fragments to generate the final optimized code.
2. The method according to claim 1, characterized in that Mapping the code snippet to a high-dimensional tensor space, and obtaining an initial feature vector by tensor decomposition; constructing a multi-channel convolution kernel group, extracting code features from the lexical layer, syntax layer, data flow layer, and control flow layer based on the initial feature vector, and generating a hierarchical feature tensor; Perform cross-layer feature fusion on the hierarchical feature tensor, use a dynamic weight adaptive mechanism to calculate the importance of each layer of features, and generate a fusion feature matrix including: Generate a high-dimensional feature matrix from the code snippet through a sequence encoding model and map it to a high-dimensional tensor space, perform tensor decomposition on the high-dimensional feature matrix to obtain a factor matrix, and select a corresponding number of feature vectors in the factor matrix as initial feature vectors based on a preset selection number; Constructing a multi-channel convolution kernel group, the multi-channel convolution kernel group includes a lexical layer convolution kernel, a grammatical layer convolution kernel, a data stream layer convolution kernel and a control stream layer convolution kernel, based on the initial feature vector, using the lexical layer convolution kernel to extract lexical layer features, using the grammatical layer convolution kernel to extract grammatical layer features, using the data stream layer convolution kernel to extract data stream layer features, using the control stream layer convolution kernel to extract control stream layer features, and connecting the lexical layer features, the grammatical layer features, the data stream layer features and the control stream layer features to form a hierarchical feature tensor; The first random noise and the second random noise are respectively superimposed on the hierarchical feature tensor to generate two perturbation feature tensors, the two perturbation feature tensors are respectively input into a feature mapping network to obtain feature representation, based on the feature representation, the similarity between the two perturbation feature tensors of the same code snippet is calculated to obtain the positive sample pair similarity, the similarity between different code snippets in any perturbation feature tensors is calculated to obtain the negative sample pair similarity, based on the positive sample pair similarity and the negative sample pair similarity, a contrast loss function is constructed, and the feature mapping network is optimized using the contrast loss function to obtain an optimized feature representation; The two perturbation feature tensors corresponding to the optimized feature representation are subjected to feature fusion through a deep neural network, and the feature fusion result is added to the hierarchical feature tensor to obtain an enhanced feature tensor; a dynamic weight adaptive network is constructed to calculate the importance scores of the lexical layer features, grammatical layer features, data flow layer features and control flow layer features in the enhanced feature tensor, the importance scores are normalized to obtain inter-layer weight coefficients, the inter-layer weight coefficients are weighted and summed with the features of the corresponding layers, and the enhanced feature tensor is superimposed on the weighted result to obtain a fused feature matrix.
3. The method according to claim 1, characterized in that Based on the fusion feature matrix, a hypergraph structure is constructed to determine the multi-dimensional association relationship between codes and generate a code association graph; a recursive neural tensor network is applied to process the code association graph to construct a deep semantic network; Integrating the spatial attention mechanism and the temporal attention mechanism in the deep semantic network to generate the code spatiotemporal feature graph includes: Extract each code snippet in the fusion feature matrix as a vertex to form a code vertex set; calculate the feature cosine similarity of any two code snippets in the code vertex set, and based on the feature cosine similarity, connect two code snippets that are greater than a preset similarity threshold to form a hyperedge, determine the weight of the hyperedge based on the feature cosine similarity, and all the hyperedges form a hyperedge set; the weights of all the hyperedges form a hyperedge weight matrix; based on the code vertex set, calculate the semantic similarity value, call chain relevance value, and data flow association value of any two code snippets, and form a multidimensional association strength matrix; combine the code vertex set, the hyperedge set, the hyperedge weight matrix, and the multidimensional association strength matrix to generate a code association graph; Combining the hyperedge weight matrix in the code association graph and the multidimensional association strength matrix to form an edge association feature, inputting the edge association feature into a recursive neural tensor network, wherein the tensor layer of the recursive neural tensor network performs recursive calculation based on the edge association feature, a preset weight tensor, a preset weight vector, and a preset bias value, mapping the edge association feature into a semantic feature vector, performing multi-layer nonlinear transformation on the semantic feature vector, and generating a deep semantic network; Extracting the semantic feature vector corresponding to each code snippet in the deep semantic network; calculating the correlation weights between the semantic feature vectors to generate a spatial feature matrix; extracting the execution timing sequence of the code snippet from the deep semantic network, calculating the hidden state vector and the context vector of each time step based on the execution timing sequence, calculating the temporal attention score according to the hidden state vector and the context vector, and generating a temporal feature matrix; A spatiotemporal feature balance factor is set, and the spatial feature matrix and the temporal feature matrix are weightedly fused according to the spatiotemporal feature balance factor to generate a code spatiotemporal feature graph.
4. The method according to claim 1, characterized in that: Based on the code spatiotemporal feature graph, a hierarchical Bayesian network model is constructed to determine the conditional dependency relationship between code modules, and a code dependency probability graph is formed, including: Based on the code spatiotemporal feature graph, a code feature vector is formed by dimension normalization and concatenation, and the code feature vector is stored in a corresponding node of the observation layer to obtain an observation layer feature matrix; Based on the observation layer feature matrix, the number of function calls, the number of data flow transfers, and the number of control flow conversions between all code modules are counted, and weighted combinations are performed to calculate the conditional dependency strength matrix between modules; the conditional dependency strength matrix is used as the initial state of the hidden variable layer node, and based on the elements in the conditional dependency strength matrix that are greater than the first preset threshold, the connection relationship between the hidden variable layer nodes is constructed to obtain the hidden variable layer network structure; Initialize the parameter layer nodes using Dirichlet distribution, establish connections between the parameter layer nodes and the nodes in the hidden variable layer network structure, establish connections between the nodes in the hidden variable layer network structure and the corresponding nodes of the observation layer feature matrix, and obtain an initial hierarchical Bayesian network in combination with preset initial probability weights; Based on the initial hierarchical Bayesian network, a forward propagation algorithm is used to calculate the marginal probability distribution matrix of the nodes of the hidden variable layer, a joint conditional probability tensor of the nodes of the hidden variable layer is calculated based on the marginal probability distribution matrix and the chain rule, and a log-likelihood function is calculated, the log-likelihood function is derived to obtain a network parameter gradient matrix, network parameters and probability weights are updated based on the network parameter gradient matrix, and the execution is repeated until the iterative difference of the network parameters is less than a second preset threshold value, thereby obtaining an optimized hierarchical Bayesian network; Node pairs with connection relationships are extracted from the optimized hierarchical Bayesian network to form a code module dependency edge set, the conditional probability weight of each edge in the code module dependency edge set is calculated to obtain an edge weight matrix, all corresponding nodes are formed into a node set, and a code dependency probability graph is generated based on the node set, the code module dependency edge set and the edge weight matrix.
5. The method according to claim 4, characterized in that Executing a variational reasoning algorithm on the code dependency probability graph, calculating the probability distribution of the code execution path, and generating an initial reconstruction plan includes: Constructing a mean field variational distribution function, decomposing the global posterior distribution of the code dependency probability graph into the product of multiple local conditional distributions to obtain a variational distribution matrix, and calculating a conditional probability vector based on the current state of each local conditional distribution in the variational distribution matrix; Using the conditional probability vector, a logarithmic expectation matrix is obtained by calculating the logarithmic expectation of the local conditional distribution of each code module node and the joint distribution of the corresponding adjacent code module nodes; based on the logarithmic expectation matrix, a distribution difference measurement function that measures the difference between the variational distribution and the true posterior distribution is constructed; Calculate the gradient of the distribution difference metric function with respect to the local conditional distribution parameter of each code module node to obtain a gradient vector; update the local conditional distribution parameter of each code module node based on the gradient vector and a preset learning rate; substitute the updated local conditional distribution parameter into the variational distribution matrix and recalculate; Repeat the execution until the change in the local conditional distribution parameters between two adjacent iterations is less than a preset change threshold, and then stop the iteration to obtain the execution path probability distribution matrix between the code module nodes; from the execution path probability distribution matrix, select the code module execution sequence with the maximum posterior probability as the optimal execution path to generate an initial reconstruction plan.
6. The method according to claim 1, characterized in that Applying adaptive particle filtering to track the code execution status of the initial reconstruction scheme and obtain a code performance indicator sequence; performing topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of the code blocks; According to the parallel reorganization sequence, the code is asynchronously loaded and the reconstructed code is generated, including: Construct a code execution state space model, initialize a preset number of state tracking particles; calculate the Euclidean distance between each state tracking particle and the target state, and calculate the particle weight based on the Euclidean distance; calculate the inverse of the sum of squares of the particle weights as a resampling criterion value; when the resampling criterion value is less than a preset resampling threshold, resample the state tracking particles based on the particle weights, and update the state estimation value; collect the code performance indicators of the initial reconstruction scheme based on the state estimation value, and generate a code performance indicator sequence; Based on the code performance indicator sequence, a code module dependency graph is constructed to determine the dependency strength between adjacent code modules; a candidate node queue with an in-degree of zero is maintained, a performance score of each node in the candidate node queue is calculated based on the code performance indicator sequence, a node corresponding to the maximum performance score is selected to be added to a topological sequence, and removed from the candidate node queue, the in-degree of the adjacent nodes of the node is updated, and the adjacent nodes with the in-degree updated to zero are added to the candidate node queue; the execution is repeated until the candidate node queue is empty, and a performance optimized topological sequence is obtained; An initial earliest execution time is set for the starting code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed forward, and the earliest execution time of the target code module is added to the inter-module dependency strength to obtain the earliest execution time of the next code module; a target latest execution time is set for the terminating code module in the performance optimization topology sequence; the performance optimization topology sequence is traversed backward, and the inter-module dependency strength is subtracted from the latest execution time of the target code module to obtain the latest execution time of the previous code module; if the earliest execution time and the latest execution time of each code module are equal, they are marked as critical path modules, and a parallel reorganization order is generated according to the position order of the critical path modules in the performance optimization topology sequence; According to the parallel reorganization order, the codes corresponding to the critical path modules are packaged as pre-loading units, and the codes corresponding to other path modules are set as delayed loading units to generate reconstructed codes.
7. The method according to claim 1, characterized in that Input the performance feature vector into a dual-dimensional discriminator, generate a discriminant score based on the code quality dimension and the execution efficiency dimension; drive a multi-level generation network based on the discriminant score, respectively generate an optimized code structure, module dependency and interface protocol, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; perform program slicing on the optimized code according to the adaptive loss function, and verify the correctness of the code through symbolic execution and constraint solving; Perform incremental synthesis on the verified code snippets to generate the final optimized code including: The performance feature vector is input into the code quality dimension discriminator and the execution efficiency dimension discriminator. The code quality dimension discriminator generates a code structure rationality score based on the forward propagation of the multi-layer perceptron. The execution efficiency dimension discriminator generates a performance optimization potential score based on the timing update of the recurrent neural network. The code structure rationality score and the performance optimization potential score are weighted and fused to obtain a comprehensive discrimination score. Based on the comprehensive discrimination score, a code structure generator, a dependency generator and an interface protocol generator are driven to output optimized code structure, module dependency and interface protocol respectively; According to the optimized code structure, the module dependency and the interface protocol, a maintenance coefficient, a performance efficiency coefficient and a resource consumption coefficient are calculated, and the maintenance coefficient, the performance efficiency coefficient and the resource consumption coefficient are dynamically weighted based on the comprehensive discrimination score to construct an adaptive loss function; Extracting control dependency and data dependency from the optimized code structure based on the adaptive loss function to construct a program dependency graph, performing path constraint solving on the program dependency graph, and obtaining an input-output mapping relationship; The code snippets are verified for equivalence according to the input-output mapping relationship, and the synthesis order is constructed according to the dependency relationship of the verified code snippets to complete the incremental code synthesis and generate the final optimized code.
8. An application framework rapid construction and reuse system, used to implement the method described in any one of claims 1 to 7, characterized in that: include: The first unit is used to map the code snippet into a high-dimensional tensor space and obtain the initial feature vector through tensor decomposition; Constructing a multi-channel convolution kernel group, extracting code features from the lexical layer, the grammatical layer, the data flow layer, and the control flow layer based on the initial feature vector, and generating a hierarchical feature tensor; Performing cross-layer feature fusion on the hierarchical feature tensor, calculating the importance of features at each layer using a dynamic weight adaptive mechanism, and generating a fused feature matrix; Based on the fusion feature matrix, a hypergraph structure is constructed to determine the multi-dimensional association relationship between codes and generate a code association graph; a recursive neural tensor network is applied to process the code association graph to construct a deep semantic network; Integrating the spatial attention mechanism and the temporal attention mechanism in the deep semantic network to generate a code spatiotemporal feature map; The second unit is used to construct a hierarchical Bayesian network model based on the code spatiotemporal feature graph, determine the conditional dependency relationship between code modules, and form a code dependency probability graph; Execute a variational inference algorithm on the code dependency probability graph, calculate the probability distribution of the code execution path, and generate an initial reconstruction scheme; apply an adaptive particle filter to track the code execution state of the initial reconstruction scheme and obtain a code performance indicator sequence; perform topological sorting and critical path analysis based on the code performance indicator sequence to determine the parallel reorganization order of the code blocks; Asynchronous loading of code is performed according to the parallel reorganization sequence to generate reconstructed code; Analyze the performance bottlenecks and memory access patterns of the reconstructed code to generate a performance feature vector; A third unit is used to input the performance feature vector into a dual-dimensional discriminator to generate a discriminant score based on a code quality dimension and an execution efficiency dimension; Based on the discriminant score, a multi-level generation network is driven to generate optimized code structure, module dependency and interface protocol respectively, calculate the maintenance coefficient, performance efficiency coefficient and resource consumption coefficient, and construct an adaptive loss function; the optimized code execution program is sliced according to the adaptive loss function, and the code correctness is verified by symbolic execution and constraint solving; incremental synthesis is performed on the verified code fragments to generate the final optimized code.
9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to call the instructions stored in the memory to execute the method described in any one of claims 1 to 7.
10. A computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Judicial causal Bayesian network construction method based on hierarchical additive noise model
CN116432759A
Combined formalized analysis method based on multi-task Bayesian graph neural network
CN117992330A