A software code optimization method and system based on big data
By combining big data and manifold tangent space networks, a code state uncertainty model is constructed, which solves the instability problem of the code optimization process in existing technologies, realizes dynamic modeling of code running state and stable generation of optimization paths, and improves the stability and reliability of code optimization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- INNER MONGOLIA ZHUMENG NETWORK TECHNOLOGY CO LTD
- Filing Date
- 2026-06-03
- Publication Date
- 2026-07-24
Smart Images

Figure CN122450809A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software engineering technology, and in particular to a software code optimization method and system based on big data. Background Technology
[0002] Existing software code optimization methods primarily rely on static program analysis, compiler optimization rules, or empirical tuning techniques based on runtime performance data. These methods analyze code structure by constructing abstract syntax trees, control flow graphs, and data dependencies, and then optimize the code based on metrics such as execution time and memory access. Furthermore, some methods introduce machine learning models to predict or tune code performance, but these mostly focus on modeling single metrics or analyzing local features, lacking the ability to systematically characterize the overall dynamic characteristics of the code's runtime state.
[0003] However, the aforementioned methods generally suffer from insufficient characterization of uncertainties during code execution, failing to effectively reflect complex variations such as execution time fluctuations, path branch differences, and resource access dispersion, resulting in a lack of a unified modeling foundation for the optimization process. Furthermore, existing methods are mostly based on static or locally optimal strategies, lacking dynamic modeling and global extrapolation capabilities for code state evolution. This makes it impossible to achieve stable convergence of optimization path selection in complex operating environments, thus affecting the stability and reliability of the code optimization results. Summary of the Invention
[0004] One objective of this invention is to propose a software code optimization method and system based on big data. This invention uses uncertainty modeling and manifold tangent space network to achieve code optimization, which has the advantages of high stability and strong controllability.
[0005] A software code optimization method based on big data according to an embodiment of the present invention includes the following steps: Collect multi-source data of the software code to be optimized, preprocess the multi-source data, and obtain a standardized code dataset; Perform program analysis on standardized code datasets, construct abstract syntax trees, control flow graphs and data dependencies, extract code features and construct code state vectors; A code state time series is constructed based on the code state vector, and a code state uncertainty time series is calculated. Adaptive phase space reconstruction is performed on the time series of code state uncertainty to obtain the trajectory series of code state uncertainty, and a code structure correlation matrix is constructed. Based on the trajectory sequence of code state uncertainty, a manifold space representation of code state uncertainty is constructed and mapped to the local tangent space. Combined with the code structure correlation matrix, the evolutionary representation of the tangent space of code state uncertainty under structural constraints is obtained. Based on the tangent space evolution representation of code state uncertainty, an improved manifold tangent space network model is constructed to obtain the code state uncertainty evolution model; State deduction is performed based on the code state uncertainty evolution model to obtain the code state uncertainty change sequence corresponding to each code optimization operation; Based on the sequence of uncertain changes in code state, a sequence of code optimization operations is selected, a code optimization path is generated, and structural adjustments and refactoring are performed to obtain the optimized target code and the results of performance indicator changes.
[0006] Optionally, the multi-source data includes source code text data, compilation intermediate representation data, runtime performance monitoring data, and historical version evolution data, and the preprocessing includes time alignment, missing value completion, and outlier removal.
[0007] Optionally, the construction of the code state vector includes: Lexical and syntactic analysis are performed on the source code text data in the standardized code dataset, and an abstract syntax tree is constructed based on the syntactic rules; Construct a control flow graph based on the control structures and statement execution order relationships in the abstract syntax tree; Data dependencies are constructed based on the variable definition and usage relationships and function call relationships in the abstract syntax tree; The code complexity and branch path count metrics are calculated based on the control flow graph, the memory access count metrics are calculated based on data dependencies, the function call depth metrics are calculated based on function call relationships, and the loop nesting level metrics are calculated based on the loop structure in the abstract syntax tree. The metrics of code complexity, function call depth, nested loop level, number of branch paths, and memory access frequency are uniformly converted to the same numerical range. The metrics are then weighted and combined according to fixed weights to obtain a multidimensional feature sequence. A code state vector is constructed by arranging the values of each indicator based on a multidimensional feature sequence.
[0008] Optionally, the generation of the code state uncertainty time series includes: Based on the code state vector and the sampling results of multiple runs, the code state vector values at each time point are recorded according to a uniform sampling time interval and arranged in chronological order to construct a code state time series. Based on the code state time series, the execution time value, branch path number value and memory access count value corresponding to each moment are extracted, and the execution time series, branch path series and memory access series are formed in chronological order respectively. Based on the execution time series, the execution time fluctuation at each time point is calculated; based on the branch path series, the path branch difference at each time point is calculated; and based on the memory access series, the memory access dispersion at each time point is calculated. Based on the execution time fluctuation, path branch difference, and memory access dispersion, the code state uncertainty value at each moment is obtained; Arrange the code state uncertainty values at each time point in chronological order to construct a time series of code state uncertainty.
[0009] Optionally, the construction of the code structure association matrix includes: Based on the time series of code state uncertainty, the autocorrelation values corresponding to different time intervals are calculated, and the autocorrelation values are normalized and the delay time parameter is selected. Based on the time series of code state uncertainty and the delay time parameter, we construct the reconstruction vector sequence under different embedding dimensions, calculate the distance change between adjacent reconstruction vectors in the reconstruction vector sequence, and select the embedding dimension parameter. Based on the delay time parameter and the embedding dimension parameter, the phase space of the code state uncertainty time series is reconstructed to obtain the code state uncertainty trajectory sequence; Based on function call relationships and data dependencies, the connection relationships between different code units are quantified to obtain a code structure association matrix.
[0010] Optionally, the generation of the code state uncertainty tangent space evolution representation includes: Based on the trajectory sequence of code state uncertainty, the distance between the reconstruction vectors at each time step is calculated, and the neighborhood set of each reconstruction vector is determined based on the distance value, thus constructing a manifold space representation of code state uncertainty. Based on the code state uncertainty manifold space representation, multiple adjacent reconstruction vectors are selected from the neighborhood set corresponding to each reconstruction vector, the difference between the adjacent reconstruction vector and the current reconstruction vector is calculated, and a linear combination is performed based on the difference to obtain the local tangent space corresponding to each reconstruction vector. Based on the local tangent space, each reconstruction vector in the code state uncertainty trajectory sequence is mapped to the corresponding local tangent space. By calculating the projection values of each reconstruction vector in the local tangent space and arranging the projection values in chronological order, a code state uncertainty tangent space representation sequence is constructed. Based on the code structure association matrix, the numerical values of each dimension in the code state uncertainty tangent space representation sequence are weighted, and the connection relationship in the code structure association matrix is applied to the numerical values of each dimension in the tangent space representation sequence to obtain the code state uncertainty tangent space representation sequence after structural constraints. Based on the code state uncertainty tangent space representation sequence after structural constraints, the difference between corresponding values at adjacent time points is calculated in chronological order to obtain the code state uncertainty tangent space evolution representation.
[0011] Optionally, the generation of the code state uncertainty evolution model includes: Based on the tangent space evolution representation of code state uncertainty under structural constraints, the tangent space vectors corresponding to each time step are arranged in chronological order to construct the tangent space sequence. Based on the tangent space sequence, multiple neighboring tangent space vectors are selected in the neighborhood of the tangent space vector at each time step. The difference between the current tangent space vector and the neighboring tangent space vectors is calculated, and the difference is linearly combined to obtain the local linear fitting result at each time step. Based on the local linear fitting results, the local linear fitting results at each time point are arranged in chronological order to construct a local linear representation sequence. Based on the local linear representation sequence, nonlinear weighting is performed on the local linear representations corresponding to each time step. By assigning weights to the local linear representations corresponding to different time positions and performing weighted summation, a global nonlinearity is obtained. Based on the global nonlinearity fusion result, an improved manifold tangent space network model is constructed. The improved manifold tangent space network includes an input feature construction layer, a local linear fitting layer, a structural constraint fusion layer, a global nonlinear fusion layer, and a multi-layer stacked modeling layer. The output of the improved manifold tangent space network model is used as the code state uncertainty evolution model.
[0012] Optionally, the generation of the code state uncertainty change sequence includes: Based on the code state uncertainty evolution model, the code state uncertainty value corresponding to the current code state is determined, and the code state uncertainty value is used as the initial state; Based on different code optimization operations, corresponding input state sequences are constructed for each initial state. Each input state sequence is input into the code state uncertainty evolution model, and iterative calculations are performed in chronological order to obtain the predicted values of code state uncertainty at each time step. Based on the predicted values of code state uncertainty at each time point, they are arranged in chronological order to form a sequence of code state uncertainty changes corresponding to each code optimization operation.
[0013] Optionally, the generation of the performance index change results includes: Based on the code state uncertainty change sequence, the difference between the code state uncertainty values corresponding to adjacent time points is calculated, and a code state uncertainty convergence criterion is constructed based on the difference. Based on the uncertain change sequence of code state, the change rate value is obtained, and stability constraints are constructed based on the change rate value. Based on the convergence criterion and stability constraints of code state uncertainty, the sequences of code state uncertainty changes corresponding to different code optimization operations are screened to obtain the sequences of code optimization operations that satisfy the convergence constraints of code state uncertainty. Based on the code optimization operation sequence, each code optimization operation is arranged in chronological order to generate a code optimization path; Based on the code optimization path, the source code is structurally adjusted and refactored. Each code optimization operation in the code optimization path is applied to the source code in sequence to obtain the optimized target code. Based on the optimized target code, obtain the corresponding execution time, number of branch paths, and number of memory accesses, compare them with the corresponding values before optimization, and output the results of performance metric changes.
[0014] A software code optimization system based on big data according to an embodiment of the present invention includes: The data acquisition and preprocessing module is used to collect multi-source data of the software code to be optimized and preprocess it to obtain a standardized code dataset. The program analysis and state construction module is used to analyze standardized code datasets and construct code state vectors. The uncertainty modeling module is used to construct time series of uncertainties in code states; The phase space reconstruction and structural modeling module is used to reconstruct the phase space and build the code structure association matrix. The manifold tangent space representation module is used to construct an evolutionary representation of code state uncertainty in the tangent space; The evolution model building module is used to construct an improved manifold tangent space network model and obtain an evolution model of code state uncertainty. The state deduction module is used to generate sequences of uncertain changes in code state; The optimization decision and execution module is used to generate code optimization paths and output the optimized target code and performance metric changes.
[0015] The beneficial effects of this invention are: This invention addresses the problem in existing technologies of the difficulty in uniformly characterizing and dynamically modeling the uncertainty of code execution states. By introducing code state uncertainty as the core modeling object, it uniformly quantifies and expresses execution time fluctuations, path branch differences, and memory access dispersion, and constructs a time series of code state uncertainty. Based on this, it combines a phase space reconstruction method to form a trajectory sequence of code state uncertainty, thereby achieving a holistic modeling of the complex dynamic characteristics of code execution states. Compared with traditional optimization methods based on single performance indicators or static structural analysis, this invention can reflect the changing patterns of code execution states from a dynamic evolution perspective, providing a unified and scalable modeling foundation for subsequent optimization and improving the completeness and accuracy of code state representation.
[0016] Furthermore, this invention constructs a manifold space representation of code state uncertainty and introduces a code structure correlation matrix into the local tangent space for structural constraints. Combined with an improved manifold tangent space network model, it models the uncertainty evolution process, achieving a synergistic expression of local linear features and global nonlinear evolution laws, thereby improving the model's ability to characterize complex code behavior. Based on this, by performing state deduction on the uncertainty evolution process under different code optimization operations and selecting optimization paths based on convergence criteria and stability constraints, the code optimization process is transformed from traditional experience-driven or local search to a global decision-making process based on dynamic evolution laws, effectively improving the stability and controllability of the optimization path. Finally, this invention can generate stable and convergent code optimization paths and output the optimized target code and performance index changes, improving the reliability and interpretability of the optimization process while ensuring optimization effectiveness, and has good engineering application value. Attached Figure Description
[0017] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is an overall flowchart of a software code optimization method based on big data proposed in this invention; Figure 2 This is a schematic diagram of the manifold space representation and tangent space mapping process for code state uncertainty in a software code optimization method based on big data proposed in this invention. Figure 3 This is a schematic diagram of the code optimization path generation and code refactoring process in a big data-based software code optimization method proposed in this invention. Detailed Implementation
[0018] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0019] refer to Figures 1-3 A software code optimization method based on big data includes the following steps: Collect multi-source data of the software code to be optimized. The multi-source data includes source code text data, compilation intermediate representation data, runtime performance monitoring data and historical version evolution data. Perform time alignment, missing value completion and outlier removal on the multi-source data to obtain a standardized code dataset. The standardized code dataset is analyzed and processed to construct abstract syntax trees, control flow graphs and data dependencies. Code complexity, function call depth, loop nesting level, number of branch paths, memory access count and execution time indicators are extracted. Based on the extracted features, a code state vector is constructed. A code state time series is constructed based on the code state vector and the sampling results of multiple runs. Based on the execution time fluctuations, path branch differences and memory access dispersion at each moment in the code state time series, the code state uncertainty value at each moment is calculated according to the unified uncertainty mapping rule to obtain the code state uncertainty time series. Based on the autocorrelation characteristics of the code state uncertainty time series, the delay time parameter and embedding dimension parameter are determined. The code state uncertainty time series is then adaptively reconstructed in phase space to obtain the code state uncertainty trajectory sequence. Finally, a code structure correlation matrix is constructed based on function call relationships and data dependencies. Based on the trajectory sequence of code state uncertainty, a manifold space representation of code state uncertainty is constructed. In the manifold space, the local tangent space corresponding to each trajectory point is selected, and the trajectory sequence of code state uncertainty is mapped to the corresponding tangent space to construct a tangent space representation sequence of code state uncertainty. The code structure association matrix is introduced into the tangent space representation sequence to impose structural constraints on each dimension component, and the evolutionary representation of code state uncertainty tangent space under structural constraints is obtained. Based on the tangent space evolution representation of code state uncertainty under structural constraints, an improved manifold tangent space network model is constructed. The tangent space representation sequence is subjected to local linear fitting and global nonlinear fusion to obtain the code state uncertainty evolution model. Based on the code state uncertainty evolution model, the state deduction process of code state uncertainty evolution under different code optimization operations is carried out to obtain the code state uncertainty change sequence corresponding to each code optimization operation; A convergence criterion for code state uncertainty is constructed based on the sequence of code state uncertainty changes. The convergence criterion is used to constrain the code state uncertainty to decrease monotonically with evolution time and its rate of change to meet the stability constraint. Based on the convergence criterion, a sequence of code optimization operations that meet the convergence constraint is selected, a code optimization path is generated, and the source code is structurally adjusted and restructured according to the code optimization path to obtain the optimized target code and output the corresponding performance index change results.
[0020] In this embodiment, the multi-source data includes source code text data, compilation intermediate representation data, runtime performance monitoring data, and historical version evolution data. Preprocessing includes time alignment, missing value completion, and outlier removal.
[0021] In this embodiment, the construction of the code state vector includes: Lexical and syntactic analysis are performed on the source code text data in the standardized code dataset to identify keywords, identifiers, operators and constant information, and an abstract syntax tree is constructed based on the syntactic rules. A control flow graph is constructed based on the control structures and statement execution order relationships in the abstract syntax tree to represent the execution path relationships of the code. Data dependencies are constructed based on the variable definition and usage relationships and function call relationships in the abstract syntax tree to represent the data transfer relationships between variables; The code complexity and branch path count metrics are calculated based on the control flow graph, the memory access count metrics are calculated based on data dependencies, the function call depth metrics are calculated based on function call relationships, and the loop nesting level metrics are calculated based on the loop structure in the abstract syntax tree. The calculation of code complexity index specifically includes: calculation based on the number of nodes and edges in the control flow graph. The basic blocks in the control flow graph are used as nodes, and the program execution path is used as edges. The total number of nodes and edges is counted, and the number of edges is subtracted from the number of nodes and then a constant is added to obtain the complexity value. At the same time, for the case with multiple entry or exit points, the complexity index is calculated and accumulated for each connected region. Furthermore, additional counts can be made for condition judgment nodes, and a fixed weight can be added to the node corresponding to each branch judgment to obtain the code complexity index that reflects the path complexity. The calculation of the branch path quantity index specifically includes: based on all conditional branch nodes in the control flow graph, counting the number of branch exits for each conditional node, and combining different paths for calculation. By traversing all reachable paths from the entry node to the exit node, counting the number of different paths, and when there is a loop structure, expanding the loop by one level to calculate the number of paths, and then calculating the number of paths for loop paths with a fixed weight. Finally, the number of all paths is accumulated to obtain the branch path quantity index. The calculation of the memory access count metric specifically includes: based on the definition and usage relationships of variables in data dependencies, counting the number of reads and writes for each variable during program execution; mapping the access behavior of variables in different statements to access count values; accumulating the access counts of all variables; treating parameter passing and return value access during function calls as additional access behaviors and counting them; and finally, weighted summing of the read and write counts to obtain the memory access count metric. The calculation of the function call depth index specifically includes: constructing a function call chain based on the function call relationship, taking each function as a node and the function call relationship as a directed connection relationship, starting from the program entry function, traversing down the call path layer by layer, recording the number of nested function calls in each call path, counting the maximum number of nested levels in all call paths, and taking the maximum nesting level as the function call depth index. When there is a recursive call, the recursion is expanded once and its nesting level is calculated and included in the statistics. The calculation of the loop nesting level index specifically includes: based on the loop structure nodes in the abstract syntax tree, marking each loop structure with a level, marking the outermost loop as the first level, and incrementing the marking of the nested loops inside it layer by layer, traversing all loop structure paths in the abstract syntax tree, recording the maximum loop level on each path, and statistically analyzing the maximum loop level in all paths to obtain the loop nesting level index. When there are multiple nested structures, the maximum nesting depth is used as the final result. The metrics of code complexity, function call depth, nested loop level, number of branch paths, and memory access frequency are uniformly converted to the same numerical range. The metrics are then weighted and combined according to fixed weights to obtain a multidimensional feature sequence. A code state vector is constructed by arranging the values of each indicator based on a multidimensional feature sequence.
[0022] In this embodiment, the generation of the code state uncertainty time series includes: Based on the code state vector and the sampling results of multiple runs, the code state vector values at each time point are recorded according to a uniform sampling time interval and arranged in chronological order to construct a code state time series. Based on the code state time series, the execution time value, branch path number value and memory access count value corresponding to each moment are extracted, and the execution time series, branch path series and memory access series are formed in chronological order respectively. Based on the execution time series, the difference between the execution time value at each time point and the average value of the execution time series is calculated, and the difference is squared and normalized to obtain the execution time fluctuation at each time point. Based on the branch path sequence, the difference between the number of branch paths at adjacent time points is calculated, and the absolute value of the difference is processed and normalized to obtain the path branch difference at each time point. Based on the memory access sequence, the difference between the number of memory accesses at each time step and the average value of the memory access sequence is calculated, and the difference is squared and normalized to obtain the discrete value of memory access at each time step. Based on the execution time fluctuation, path branch difference, and memory access dispersion, the three values corresponding to the same moment are weighted and summed and normalized according to the unified uncertainty mapping rule to obtain the code state uncertainty value at each moment. Arrange the code state uncertainty values at each time point in chronological order to construct a time series of code state uncertainty.
[0023] In this embodiment, the construction of the code structure association matrix includes: Based on the time series of code state uncertainty, the autocorrelation values corresponding to different time intervals are calculated, and the autocorrelation values are normalized. The time interval corresponding to the first time the autocorrelation value is lower than its average value is selected as the delay time parameter. Based on the time series of code state uncertainty and the delay time parameter, we construct the reconstruction vector sequence under different embedding dimensions, calculate the distance change between adjacent reconstruction vectors in the reconstruction vector sequence, and select the embedding dimension corresponding to the distance change tending to be stable as the embedding dimension parameter. The construction of the reconstructed vector sequence specifically includes: after determining the delay time parameter, selecting the value of the current moment from the time series as the starting point, and selecting the values of multiple subsequent moments in sequence according to the delay time interval, and concatenating these values in order to form a multi-dimensional vector, wherein the vector dimension is determined by the embedding dimension. By changing the value of the embedding dimension, the combination process is repeated to construct reconstructed vector sequences under different dimension conditions, and arrange them in time order to form a reconstructed vector sequence. Based on the delay time parameter and the embedding dimension parameter, the phase space reconstruction of the code state uncertainty time series is performed. The code state uncertainty value at each moment is combined with multiple subsequent code state uncertainty values selected according to the delay time parameter to form a multidimensional reconstruction vector. The multidimensional reconstruction vector is arranged in chronological order to obtain the code state uncertainty trajectory sequence. Based on function call relationships and data dependencies, the connection relationships between different code units are quantified to obtain a code structure association matrix.
[0024] In this embodiment, the generation of the code state uncertainty tangent space evolution representation includes: Based on the trajectory sequence of code state uncertainty, the distance between the reconstruction vectors at each time step is calculated, and the neighborhood set of each reconstruction vector is determined based on the distance value, thus constructing a manifold space representation of code state uncertainty. The construction of the code state uncertainty manifold space specifically includes: calculating the distance relationship between the reconstruction vectors corresponding to each time step, determining the neighborhood range of each reconstruction vector as the center, constructing the adjacency relationship reflecting the local similarity relationship based on the distance distribution between each reconstruction vector and other reconstruction vectors in its neighborhood, uniformly representing all reconstruction vectors and their corresponding adjacency relationships as a low-dimensional continuous structure, and organizing the overall data structure by keeping the distance relationship in the neighborhood unchanged, thus forming a code state uncertainty manifold space representation that can reflect the continuity of the evolution of code state uncertainty. Based on the code state uncertainty manifold space representation, multiple adjacent reconstruction vectors are selected from the neighborhood set corresponding to each reconstruction vector. The difference between the adjacent reconstruction vector and the current reconstruction vector is calculated. Based on the difference, a linear combination is performed to minimize the error between the reconstruction result of the combined difference and the current reconstruction vector, thus obtaining the local tangent space corresponding to each reconstruction vector. Based on the local tangent space, each reconstruction vector in the code state uncertainty trajectory sequence is mapped to the corresponding local tangent space. By calculating the projection values of each reconstruction vector in the local tangent space and arranging the projection values in chronological order, a code state uncertainty tangent space representation sequence is constructed. Based on the code structure association matrix, the numerical values of each dimension in the code state uncertainty tangent space representation sequence are weighted, and the connection relationship in the code structure association matrix is applied to the numerical values of each dimension in the tangent space representation sequence to obtain the code state uncertainty tangent space representation sequence after structural constraints. Based on the code state uncertainty tangent space representation sequence after structural constraints, the difference between corresponding values at adjacent time points is calculated in chronological order to obtain the code state uncertainty tangent space evolution representation.
[0025] In this embodiment, the generation of the code state uncertainty evolution model includes: Based on the tangent space evolution representation of code state uncertainty under structural constraints, the tangent space vectors corresponding to each time step are arranged in chronological order to construct the tangent space sequence. Based on the tangent space sequence, multiple neighboring tangent space vectors are selected in the neighborhood of the tangent space vector at each time step. The difference between the current tangent space vector and the neighboring tangent space vectors is calculated, and the difference is linearly combined to minimize the error between the linear combination result and the current tangent space vector, thus obtaining the local linear fitting result at each time step. Based on the local linear fitting results, the local linear fitting results at each time point are arranged in chronological order to construct a local linear representation sequence. Based on the local linear representation sequence, nonlinear weighting is performed on the local linear representations corresponding to each time step. By assigning weights to the local linear representations corresponding to different time positions and performing weighted summation, a global nonlinearity is obtained. Based on the global nonlinearity fusion result, an improved manifold tangent space network model is constructed. The improved manifold tangent space network includes an input feature construction layer, a local linear fitting layer, a structural constraint fusion layer, a global nonlinear fusion layer, and a multi-layer stacked modeling layer. The output of the improved manifold tangent space network model is used as the code state uncertainty evolution model. The improved manifold tangent space network model is constructed based on the global nonlinear fusion result, including input mapping, local linear fitting, structural constraint fusion and global nonlinear fusion. Each process is connected sequentially in time to form the network structure. The input is a sequence of tangent space vectors arranged in chronological order. Input mapping processes unify the vectors at each time step into the same feature space. During the local linear fitting process, the difference combination of each time step vector and its neighboring vectors is performed to make the linear combination result of the neighboring vectors approximate the current vector, thus obtaining a local linear representation. During the structural constraint fusion process, a code structure association matrix is introduced to constrain the values of each dimension in the local linear representation, ensuring that the dimensions with structural associations change in a consistent manner. During the global nonlinear fusion process, the representations at different time positions are weighted and combined to achieve cross-time information fusion, resulting in a global nonlinear fusion result. Finally, the code state uncertainty evolution model is obtained through output mapping. Based on tangent space representation, this network characterizes local structural features through local linear fitting, ensures code structure consistency through structural constraints, and characterizes the overall evolution law through global nonlinear fusion, thereby modeling the dynamic process of uncertain changes in code state.
[0026] In this embodiment, the generation of the code state uncertainty change sequence includes: Based on the code state uncertainty evolution model, the code state uncertainty value corresponding to the current code state is determined, and the code state uncertainty value is used as the initial state; Based on different code optimization operations, corresponding input state sequences are constructed for the initial state, and each input state sequence is composed of multiple code state uncertainty values in chronological order. Each input state sequence is input into the code state uncertainty evolution model, and iterative calculations are performed in chronological order. At each time step, the code state uncertainty value of the previous time step is used as the input of the next time step to obtain the predicted code state uncertainty value for each time step. Based on the predicted values of code state uncertainty at each time point, they are arranged in chronological order to form a sequence of code state uncertainty changes corresponding to each code optimization operation.
[0027] In this embodiment, the generation of performance index change results includes: Based on the code state uncertainty change sequence, the difference between the code state uncertainty values corresponding to adjacent time points is calculated, and a code state uncertainty convergence criterion is constructed based on the difference. When the difference corresponding to consecutive time points is less than zero, it is determined to be monotonically decreasing. Based on the uncertain change sequence of code state, the change rate value is obtained, and stability constraints are constructed based on the change rate value. The stability constraint is as follows: Based on the code state uncertainty change sequence, the ratio of the difference between the code state uncertainty values at adjacent time points to the corresponding time interval is calculated to obtain the change rate value at each time point. The difference between the change rate values at each time point is calculated. When the absolute value of the difference between the change rate values at adjacent time points is less than the threshold, the change rate fluctuation is determined to meet the stability requirement. At the same time, the change rate values at all time points are statistically analyzed, the average change rate is calculated, and the absolute value of the difference between the change rate value at each time point and the average change rate is constrained to be less than a set range, thereby ensuring that the overall change rate fluctuation is limited. Under the above conditions, the code state uncertainty change sequence is determined to meet the stability constraint. Based on the convergence criterion and stability constraints of code state uncertainty, the sequences of code state uncertainty changes corresponding to different code optimization operations are screened to obtain the sequences of code optimization operations that satisfy the convergence constraints of code state uncertainty. Based on the code optimization operation sequence, each code optimization operation is arranged in chronological order to generate a code optimization path; Based on the code optimization path, the source code is structurally adjusted and refactored. Each code optimization operation in the code optimization path is applied to the source code in sequence to obtain the optimized target code. Based on the optimized target code, obtain the corresponding execution time, number of branch paths, and number of memory accesses, compare them with the corresponding values before optimization, and output the results of performance metric changes.
[0028] A software code optimization system based on big data, comprising: The data acquisition and preprocessing module is used to collect multi-source data of the software code to be optimized and preprocess it to obtain a standardized code dataset. The program analysis and state construction module is used to analyze standardized code datasets and construct code state vectors. The uncertainty modeling module is used to construct time series of uncertainties in code states; The phase space reconstruction and structural modeling module is used to reconstruct the phase space and build the code structure association matrix. The manifold tangent space representation module is used to construct an evolutionary representation of code state uncertainty in the tangent space; The evolution model building module is used to construct an improved manifold tangent space network model and obtain an evolution model of code state uncertainty. The state deduction module is used to generate sequences of uncertain changes in code state; The optimization decision and execution module is used to generate code optimization paths and output the optimized target code and performance metric changes.
[0029] Example 1: To verify the feasibility of this invention in practice, it was applied to the code optimization scenario of a backend service system of an internet company. This system handles high-concurrency access requests for extended periods, and its code has undergone multiple iterations, gradually exhibiting problems such as complex structure, lengthy call chains, and significant performance fluctuations. In actual operation, it experiences unstable execution time, frequent fluctuations in memory access, and significant changes in branch paths, resulting in inconsistent responsiveness at different times. This makes it difficult to achieve continuous and stable performance improvements through traditional optimization methods. This invention addresses this issue by modeling and controlling the uncertainty of the software code's runtime state, thereby generating a stable and controllable optimization path.
[0030] In practical applications, the system's source code text data, intermediate compilation representation data, runtime performance monitoring data, and historical version evolution data are first collected uniformly. Time alignment is then performed to ensure consistency across different sources on a unified time scale. Missing data is filled in, and outliers are removed, resulting in a standardized code dataset. Based on this, program analysis is performed on the standardized code dataset to construct an abstract syntax tree to describe code structure relationships. A control flow graph is also built to reflect the program execution path, and data dependencies are established by combining the definitions and usage relationships between variables. Furthermore, metrics such as code complexity, function call depth, loop nesting levels, number of branch paths, and memory access counts are extracted and mapped to the same numerical range to construct a code state vector.
[0031] Subsequently, multiple execution results were continuously collected during system operation. The code state vectors corresponding to different time points were arranged in chronological order to form a code state time series. Furthermore, based on execution time fluctuations, path branch changes, and memory access dispersion, the execution state at each time point was uniformly mapped to obtain a code state uncertainty time series. This uncertainty time series can reflect the fluctuation characteristics of the system at different operational stages, thus providing a foundation for subsequent dynamic modeling.
[0032] Based on this, autocorrelation analysis is performed on the time series of code state uncertainty to determine the delay time parameter and embedding dimension parameter. Then, phase space reconstruction is performed based on the determined parameters to transform the original time series into a multidimensional trajectory sequence. At the same time, the degree of correlation between different code units is quantified by combining function call relationship and data dependency relationship, and a code structure correlation matrix is constructed so that the subsequent modeling process can reflect the coupling relationship between code structures.
[0033] Furthermore, a manifold space representation is constructed based on the trajectory sequence of code state uncertainty. The neighborhood structure is determined by analyzing the distance relationship between each trajectory point, and local neighborhood points are selected in the manifold space to construct a local tangent space. The trajectory sequence is mapped to the corresponding tangent space to obtain the tangent space representation sequence of code state uncertainty. In this process, a code structure correlation matrix is introduced to constrain the components of each dimension in the tangent space representation sequence, so that the dimensions with structural correlation remain consistent during the change process, thereby obtaining the evolutionary representation of code state uncertainty tangent space under structural constraints.
[0034] After obtaining the tangent space evolutionary representation, an improved manifold tangent space network model is constructed to process the tangent space representation sequence. This network models the changes within the neighborhood through local linear fitting and integrates the overall change trend across time through global nonlinear fusion, thus obtaining a code state uncertainty evolution model. This model can describe the evolution of the code's running state over time, providing a foundation for subsequent optimization decisions.
[0035] During the optimization phase, different code optimization operations are applied as input conditions to the current code state. The future state is deduced through an evolutionary model to obtain the uncertainty change sequence of the code state corresponding to each optimization operation. By analyzing the change sequence, uncertainty convergence criteria and stability constraints are constructed to select the optimization operation sequence that can continuously reduce uncertainty and stabilize the change process. The sequence is then combined in chronological order to form the code optimization path.
[0036] In actual execution, the source code is structurally adjusted and restructured according to the generated optimization path. Each optimization operation is gradually applied to the code structure to obtain the optimized target code. At the same time, the execution time, branch path and memory access indicators before and after optimization are compared and analyzed. It can be observed that the fluctuation of the code running state is reduced, the execution process tends to be stable, and the overall system performance is more balanced.
[0037] As can be seen from the above implementation process, this invention achieves dynamic control of the code optimization process by modeling and evolutionarily analyzing the uncertainty of the code's running state, enabling the optimization path to have clear convergence characteristics and avoiding the optimization instability problem caused by relying on experience or local search in traditional methods. At the same time, by introducing manifold tangent space representation and structural constraint mechanism, the model can simultaneously characterize local changes and global trends, improving the ability to express complex code behavior, thereby achieving stable and efficient code optimization results in practical applications.
[0038] Table 1 Performance Comparison Analysis of Code Optimization Methods
[0039] As shown in Table 1, the method of this invention outperforms existing methods in several key performance indicators. Regarding average execution time, the method of this invention is 86.4 milliseconds, which is approximately 32.8% lower than traditional static optimization methods, approximately 25.1% lower than rule-based optimization methods, and approximately 15.9% lower than machine learning-based methods, demonstrating the advantage of this invention in execution efficiency.
[0040] Regarding performance volatility, the method of this invention achieves only 7.2%, significantly lower than other methods, indicating that this invention effectively suppresses uncertainties during code execution and makes the system more stable. In terms of memory access frequency, the method of this invention reduces it to 29,865 times, approximately 34% less than traditional methods, demonstrating that this invention effectively reduces resource access overhead by optimizing code structure and data dependencies.
[0041] Regarding the number of branch paths, the method of this invention reduces them to 198, indicating a simpler code structure and clearer execution paths, which helps improve overall running efficiency. In terms of convergence stability score, the method of this invention achieves 9.1, higher than other methods, demonstrating that this invention can guarantee stable convergence during the path selection optimization process.
[0042] The aforementioned performance improvement is mainly due to the introduction of a code state uncertainty modeling mechanism in this invention, which unifies the modeling of execution time fluctuations, path differences, and memory access discreteness, and describes their evolution through manifold tangent space representation. At the same time, by combining structural constraints and global nonlinearity, it achieves accurate prediction of code running state and dynamic decision-making for optimized paths, thereby improving the overall code optimization effect and stability.
[0043] The above are merely preferred embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A software code optimization method based on big data, characterized in that, Includes the following steps: Collect multi-source data of the software code to be optimized, preprocess the multi-source data, and obtain a standardized code dataset; Perform program analysis on standardized code datasets, construct abstract syntax trees, control flow graphs and data dependencies, extract code features and construct code state vectors; A code state time series is constructed based on the code state vector, and a code state uncertainty time series is calculated. Adaptive phase space reconstruction is performed on the time series of code state uncertainty to obtain the trajectory series of code state uncertainty, and a code structure correlation matrix is constructed. Based on the trajectory sequence of code state uncertainty, a manifold space representation of code state uncertainty is constructed and mapped to the local tangent space. Combined with the code structure correlation matrix, the evolutionary representation of the tangent space of code state uncertainty under structural constraints is obtained. Based on the tangent space evolution representation of code state uncertainty, an improved manifold tangent space network model is constructed to obtain the code state uncertainty evolution model; State deduction is performed based on the code state uncertainty evolution model to obtain the code state uncertainty change sequence corresponding to each code optimization operation; Based on the sequence of uncertain changes in code state, a sequence of code optimization operations is selected, a code optimization path is generated, and structural adjustments and refactoring are performed to obtain the optimized target code and the results of performance indicator changes.
2. The software code optimization method based on big data according to claim 1, characterized in that, The multi-source data includes source code text data, compilation intermediate representation data, runtime performance monitoring data, and historical version evolution data. The preprocessing includes time alignment, missing value completion, and outlier removal.
3. The software code optimization method based on big data according to claim 1, characterized in that, The construction of the code state vector includes: Lexical and syntactic analysis are performed on the source code text data in the standardized code dataset, and an abstract syntax tree is constructed based on the syntactic rules; Construct a control flow graph based on the control structures and statement execution order relationships in the abstract syntax tree; Data dependencies are constructed based on the variable definition and usage relationships and function call relationships in the abstract syntax tree; The code complexity and branch path count metrics are calculated based on the control flow graph, the memory access count metrics are calculated based on data dependencies, the function call depth metrics are calculated based on function call relationships, and the loop nesting level metrics are calculated based on the loop structure in the abstract syntax tree. The metrics of code complexity, function call depth, nested loop level, number of branch paths, and memory access frequency are uniformly converted to the same numerical range. The metrics are then weighted and combined according to fixed weights to obtain a multidimensional feature sequence. A code state vector is constructed by arranging the values of each indicator based on a multidimensional feature sequence.
4. The software code optimization method based on big data according to claim 1, characterized in that, The generation of the code state uncertainty time series includes: Based on the code state vector and the sampling results of multiple runs, the code state vector values at each time point are recorded according to a uniform sampling time interval and arranged in chronological order to construct a code state time series. Based on the code state time series, the execution time value, branch path number value and memory access count value corresponding to each moment are extracted, and the execution time series, branch path series and memory access series are formed in chronological order respectively. Based on the execution time series, the execution time fluctuation at each time point is calculated; based on the branch path series, the path branch difference at each time point is calculated; and based on the memory access series, the memory access dispersion at each time point is calculated. Based on the execution time fluctuation, path branch difference, and memory access dispersion, the code state uncertainty value at each moment is obtained; Arrange the code state uncertainty values at each time point in chronological order to construct a time series of code state uncertainty.
5. The software code optimization method based on big data according to claim 1, characterized in that, The construction of the code structure association matrix includes: Based on the time series of code state uncertainty, the autocorrelation values corresponding to different time intervals are calculated, and the autocorrelation values are normalized and the delay time parameter is selected. Based on the time series of code state uncertainty and the delay time parameter, we construct the reconstruction vector sequence under different embedding dimensions, calculate the distance change between adjacent reconstruction vectors in the reconstruction vector sequence, and select the embedding dimension parameter. Based on the delay time parameter and the embedding dimension parameter, the phase space of the code state uncertainty time series is reconstructed to obtain the code state uncertainty trajectory sequence; Based on function call relationships and data dependencies, the connection relationships between different code units are quantified to obtain a code structure association matrix.
6. The software code optimization method based on big data according to claim 1, characterized in that, The generation of the code state uncertainty tangent space evolution representation includes: Based on the trajectory sequence of code state uncertainty, the distance between the reconstruction vectors at each time step is calculated, and the neighborhood set of each reconstruction vector is determined based on the distance value, thus constructing a manifold space representation of code state uncertainty. Based on the code state uncertainty manifold space representation, multiple adjacent reconstruction vectors are selected from the neighborhood set corresponding to each reconstruction vector, the difference between the adjacent reconstruction vector and the current reconstruction vector is calculated, and a linear combination is performed based on the difference to obtain the local tangent space corresponding to each reconstruction vector. Based on the local tangent space, each reconstruction vector in the code state uncertainty trajectory sequence is mapped to the corresponding local tangent space. By calculating the projection values of each reconstruction vector in the local tangent space and arranging the projection values in chronological order, a code state uncertainty tangent space representation sequence is constructed. Based on the code structure association matrix, the numerical values of each dimension in the code state uncertainty tangent space representation sequence are weighted, and the connection relationship in the code structure association matrix is applied to the numerical values of each dimension in the tangent space representation sequence to obtain the code state uncertainty tangent space representation sequence after structural constraints. Based on the code state uncertainty tangent space representation sequence after structural constraints, the difference between corresponding values at adjacent time points is calculated in chronological order to obtain the code state uncertainty tangent space evolution representation.
7. The software code optimization method based on big data according to claim 1, characterized in that, The generation of the code state uncertainty evolution model includes: Based on the tangent space evolution representation of code state uncertainty under structural constraints, the tangent space vectors corresponding to each time step are arranged in chronological order to construct the tangent space sequence. Based on the tangent space sequence, multiple neighboring tangent space vectors are selected in the neighborhood of the tangent space vector at each time step. The difference between the current tangent space vector and the neighboring tangent space vectors is calculated, and the difference is linearly combined to obtain the local linear fitting result at each time step. Based on the local linear fitting results, the local linear fitting results at each time point are arranged in chronological order to construct a local linear representation sequence. Based on the local linear representation sequence, nonlinear weighting is performed on the local linear representations corresponding to each time step. By assigning weights to the local linear representations corresponding to different time positions and performing weighted summation, a global nonlinearity is obtained. Based on the global nonlinearity fusion result, an improved manifold tangent space network model is constructed. The improved manifold tangent space network includes an input feature construction layer, a local linear fitting layer, a structural constraint fusion layer, a global nonlinear fusion layer, and a multi-layer stacked modeling layer. The output of the improved manifold tangent space network model is used as the code state uncertainty evolution model.
8. The software code optimization method based on big data according to claim 1, characterized in that, The generation of the code state uncertainty change sequence includes: Based on the code state uncertainty evolution model, the code state uncertainty value corresponding to the current code state is determined, and the code state uncertainty value is used as the initial state; Based on different code optimization operations, corresponding input state sequences are constructed for each initial state. Each input state sequence is input into the code state uncertainty evolution model, and iterative calculations are performed in chronological order to obtain the predicted values of code state uncertainty at each time step. Based on the predicted values of code state uncertainty at each time point, they are arranged in chronological order to form a sequence of code state uncertainty changes corresponding to each code optimization operation.
9. The software code optimization method based on big data according to claim 1, characterized in that, The generation of the performance index change results includes: Based on the code state uncertainty change sequence, the difference between the code state uncertainty values corresponding to adjacent time points is calculated, and a code state uncertainty convergence criterion is constructed based on the difference. Based on the uncertain change sequence of code state, the change rate value is obtained, and stability constraints are constructed based on the change rate value. Based on the convergence criterion and stability constraints of code state uncertainty, the sequences of code state uncertainty changes corresponding to different code optimization operations are screened to obtain the sequences of code optimization operations that satisfy the convergence constraints of code state uncertainty. Based on the code optimization operation sequence, each code optimization operation is arranged in chronological order to generate a code optimization path; Based on the code optimization path, the source code is structurally adjusted and refactored. Each code optimization operation in the code optimization path is applied to the source code in sequence to obtain the optimized target code. Based on the optimized target code, obtain the corresponding execution time, number of branch paths, and number of memory accesses, compare them with the corresponding values before optimization, and output the results of performance metric changes.
10. A software code optimization system based on big data, executing the software code optimization method based on big data as described in any one of claims 1 to 9, characterized in that, include: The data acquisition and preprocessing module is used to collect multi-source data of the software code to be optimized and preprocess it to obtain a standardized code dataset. The program analysis and state construction module is used to analyze standardized code datasets and construct code state vectors. The uncertainty modeling module is used to construct time series of uncertainties in code states; The phase space reconstruction and structural modeling module is used to reconstruct the phase space and build the code structure association matrix. The manifold tangent space representation module is used to construct an evolutionary representation of code state uncertainty in the tangent space; The evolution model building module is used to construct an improved manifold tangent space network model and obtain an evolution model of code state uncertainty. The state deduction module is used to generate sequences of uncertain changes in code state; The optimization decision and execution module is used to generate code optimization paths and output the optimized target code and performance metric changes.