Instant compiling optimization method and device, computer equipment and readable storage medium
By dynamically generating optimization strategies through hotspot prediction models and AI models, the resource allocation imbalance problem of traditional JIT compilation technology in the changes of hardware status and the evolution of code features is solved, and program performance and resource utilization are improved, especially reducing energy consumption in resource-constrained environments.
Patent Information
- Application Number
- CN202511056204.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-29
- Publication Date
- 2025-09-16
AI Technical Summary
Traditional JIT compilation technology cannot dynamically adapt to changes in hardware status and the evolution of code features, resulting in an imbalance in compilation resource allocation and failure of optimization strategies, causing loss of program performance and system resource utilization.
A hotspot prediction model is used to distinguish valid hotspot codes from invalid high-frequency codes. An optimization strategy is dynamically generated through the AI model to concentrate resources on optimizing valid hotspot codes and avoid over-compilation of invalid high-frequency codes.
It improves the operating efficiency of the target program, reduces resource consumption and invalid computing overhead, and significantly reduces energy consumption in resource-constrained scenarios such as edge devices and mobile terminals.
Smart Images

Figure CN120653257A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer software technology, and is applicable to the fields of financial technology and medical health, and in particular to a just-in-time compilation optimization method, apparatus, computer equipment, and readable storage medium. Background Art
[0002] With the rapid development of mobile internet, edge computing, and heterogeneous hardware architectures, program runtime environments are becoming increasingly complex and volatile, placing increasing demands on Just-in-Time (JIT) compilation technology for dynamic optimization efficiency and resource adaptation capabilities. Currently, mainstream JIT compilation systems rely primarily on preset static rules and heuristic optimization strategies. Hotspot identification is based on simple statistics of execution frequency, and optimization decisions rely on manually summarized hardware adaptation experience. However, there's a perception-response gap between traditional JIT compilation's optimization decisions and the runtime environment. Static rules and heuristic strategies are unable to dynamically adapt to changes in hardware status and the evolution of code features, leading to imbalanced compilation resource allocation and ineffective optimization strategies, ultimately resulting in a double loss of program performance and system resource utilization. Summary of the Invention
[0003] In view of this, the present application provides a just-in-time compilation optimization method, apparatus, computer equipment and readable storage medium, the main purpose of which is to solve the problem that there is a perception\response gap between the optimization decision of traditional JIT compilation and the runtime environment, and static rules and heuristic strategies cannot dynamically adapt to hardware status changes and code feature evolution, resulting in imbalanced compilation resource allocation and failure of optimization strategies, and ultimately causing double loss of program performance and system resource utilization.
[0004] According to a first aspect of the present application, a just-in-time compilation optimization method is provided, the method comprising:
[0005] Start the program running environment and compile and run the target program code according to the initial compilation strategy;
[0006] Collecting code behavior features and corresponding environment features generated when the target program code is run, and inputting the normalized code behavior features and environment features into a hotspot prediction model;
[0007] Determining a code category corresponding to the target program code based on the hotspot prediction model, and optimizing the initial compilation strategy according to the environmental characteristics when the code category is a valid hotspot code to obtain an optimized compilation strategy, wherein the code category includes the valid hotspot code and the invalid high-frequency code;
[0008] Compile and run the target program code according to the optimized compilation strategy.
[0009] According to a second aspect of the present application, a just-in-time compilation optimization device is provided, the device comprising:
[0010] The startup module is used to start the program running environment and compile and run the target program code according to the initial compilation strategy;
[0011] A collection module, configured to collect code behavior features and corresponding environment features generated when the target program code is run, and input the normalized code behavior features and environment features into a hotspot prediction model;
[0012] an optimization module for determining a code category corresponding to the target program code based on the hotspot prediction model, and optimizing the initial compilation strategy according to the environmental characteristics to obtain an optimized compilation strategy when the code category is a valid hotspot code, the code category including the valid hotspot code and the invalid high-frequency code;
[0013] The running module is used to compile and run the target program code according to the optimized compilation strategy.
[0014] According to a third aspect of the present application, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.
[0015] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods in the first aspect are implemented.
[0016] By means of the above technical solution, the present application provides a just-in-time compilation optimization method, device, computer equipment and readable storage medium. The embodiment of the present application distinguishes valid hotspot code from invalid high-frequency code through a hotspot prediction model, avoids the over-compilation of invalid high-frequency code by traditional JIT, and optimizes the effective hotspot code by concentrating resources. This solves the problem that traditional static strategies in the fields of financial technology and medical health cannot grasp the optimization focus and resource mismatch, and improves the operating efficiency of the target program. At the same time, by dynamically generating optimization strategies through AI models, while aggressively optimizing effective hotspot codes to improve performance, it can avoid excessive resource consumption caused by over-optimization, especially in resource-constrained scenarios such as edge devices and mobile terminals, which can significantly reduce energy consumption and reduce invalid computing overhead.
[0017] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0019] Figure 1 A schematic diagram of a just-in-time compilation optimization method provided in an embodiment of the present application is shown;
[0020] Figure 2 A schematic diagram of the structure of a just-in-time compilation optimization system provided in an embodiment of the present application is shown;
[0021] Figure 3 Shown Figure 1 A schematic flow chart of a specific implementation of step S20;
[0022] Figure 4 Shown Figure 1 A schematic flow chart of a specific implementation of step S30;
[0023] Figure 5 A schematic structural diagram of a just-in-time compilation optimization device provided in an embodiment of the present application is shown;
[0024] Figure 6 A schematic structural diagram of another just-in-time compilation optimization device provided in an embodiment of the present application is shown;
[0025] Figure 7 A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0026] The following describes in detail embodiments of the present application, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and are not to be construed as limiting the present application.
[0027] Those skilled in the art will understand that, unless otherwise stated, the singular forms "a," "an," "said," and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of this application refers to the presence of the stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.
[0028] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in common dictionaries should be understood to have meanings consistent with their meanings in the context of the prior art and will not be interpreted in an idealized or overly formal sense unless specifically defined as herein.
[0029] Those skilled in the art will appreciate that the term "terminal" as used herein includes both devices that are wireless signal receivers, i.e., devices that only have wireless signal receivers without transmission capabilities, and devices that have receiving and transmitting hardware capable of performing two-way communication over a two-way communication link. Such devices may include: cellular or other communication devices with single-line displays, multi-line displays, or cellular or other communication devices without multi-line displays; PCS (Personal Communications Service) devices that may combine voice, data processing, fax, and / or data communication capabilities; PDAs (Personal Digital Assistants) that may include a radio frequency receiver, a pager, Internet / Intranet access, a web browser, a notepad, a calendar, and / or a GPS (Global Positioning System) receiver; and conventional laptop and / or palmtop computers or other devices that have and / or include a radio frequency receiver. As used herein, a "terminal" may be portable, transportable, installed in a vehicle (air, sea, and / or land), or adapted and / or configured to operate locally, and / or in a distributed manner, at any other location on Earth and / or in space. As used herein, a "terminal" may also be a communication terminal, an Internet access terminal, or a music / video playback terminal, such as a PDA, an MID (Mobile Internet Device), and / or a mobile phone with music / video playback capabilities, or a device such as a smart TV or a set-top box.
[0030] The program runtime environment refers to the sum of the hardware and software required to support program execution, providing basic services such as resource allocation, process management, and memory scheduling. The hardware environment includes physical components such as the CPU (instruction set architecture, such as x86 and ARM), memory (RAM), and storage devices (hard drives / SSDs).
[0031] The initial compilation strategy is the basic compilation process and optimization rules used by the compiler when converting source code into executable code, which determines the efficiency of the compilation process and the performance of the executable code.
[0032] The embodiment of the present application provides a just-in-time compilation optimization method, such as Figure 1 As shown, the method includes:
[0033] S10: Start the program running environment and compile and run the target program code according to the initial compilation strategy.
[0034] In the embodiment of the present application, the instant compilation optimization method provided by the present application is applicable to the instant compilation optimization system, such as Figure 2 As shown, the system includes a real-time data acquisition module, an AI intelligent decision-making engine, an adaptive compilation optimizer, and an effect feedback closed-loop system.
[0035] The data acquisition module, as the data input, collects code behavior characteristics and corresponding environmental characteristics generated when executing the target program code. This information is then passed to the AI intelligent decision engine, providing a data foundation for policy generation. The AI intelligent decision engine, as the control center, uses the feature data input by the data acquisition module and a pre-trained model to analyze the optimal strategy for the current compilation task and generate specific compilation optimization instructions. The AI intelligent decision engine sends a one-way policy instruction control flow to the adaptive compilation optimizer to guide the compilation process, and a one-way model update control flow to the performance feedback closed-loop system, triggering iterative training of the decision model using feedback data. The adaptive compilation optimizer receives the policy instructions from the AI decision engine and, based on the initial compilation strategy, dynamically optimizes the source code to generate the target program code. The performance metrics of the compiled target code are fed back to the performance feedback closed-loop system. The performance feedback closed-loop system receives the execution result data output by the adaptive compilation optimizer and compares it with a preset performance benchmark to evaluate the effectiveness of the current strategy. Based on the model update signal from the AI intelligent decision engine, the evaluation results are converted into model training data, which feeds back into the AI decision engine's parameter tuning.
[0036] In this step, the required runtime environment type is first determined based on the development language and dependencies of the target program code. For example, interpreted languages require corresponding interpreter versions, such as Python 3.9 and Node.js 16.x. Compiled languages require a compiler and linker. Furthermore, cross-platform programs may rely on virtual machines or containers. Furthermore, the environment is verified to be correctly installed, and dependent components are loaded and environment variables initialized. Next, the target program code is compiled according to the initial compilation strategy. Specifically, the compilation toolchain is selected, such as make+GCC for C++, javac for Java, and webpack for front-end code. Compilation parameters are then configured, such as the optimization level, debug mode, and macro definitions. Finally, the output path and format are set, such as the executable file storage directory and the temporary directory for intermediate files. After compilation is complete, the target program is executed. In actual operation, in the fintech field, the target program code may be high-frequency trading detection code, algorithmic stock selection code, or robo-advisory code. In the healthcare field, the target program code may be image analysis code, medication reminder code, etc. This application does not limit the specific functions of the target program code.
[0037] S20 , collecting code behavior features and corresponding environment features generated when the target program code is run, and inputting the normalized code behavior features and environment features into a hotspot prediction model.
[0038] In the embodiment of the present application, the system is as follows Figure 3 As shown, by executing the following steps S21 to S22, a data acquisition probe is used to capture the dynamic features of the target program during runtime in real time. The probe tool can use tools such as the dynamic instrumentation tool Pin, the performance analysis tool Perf, etc. The probe tool is embedded in the running process of the target program to achieve low-intrusive real-time data capture. During the actual operation process, key indicators reflecting the running status of the code can be collected as code behavior features, such as function call stack depth, instruction execution sequence, variable life cycle and number of loop iterations. Furthermore, indicators reflecting the system environment performance can be collected as environmental features, such as CPU cache hit rate, branch prediction failure rate, GPU computing unit utilization. Then, the collected feature data is standardized to eliminate the dimensional differences between different features and provide data of a unified scale for subsequent analysis.
[0039] S21. Collect the code behavior characteristics and corresponding environmental characteristics generated when the target program code is running based on the data acquisition probe. The code behavior characteristics include but are not limited to the function call stack depth, instruction execution sequence, variable life cycle and loop iteration number. The environmental characteristics include but are not limited to the CPU cache hit rate, branch prediction failure rate, and GPU computing unit utilization.
[0040] In this step, the code behavior characteristics and corresponding environmental characteristics generated by the target program code during runtime are collected based on data acquisition probes. Code behavior characteristics include but are not limited to function call stack depth, instruction execution sequence, variable lifecycle, and loop iteration count. The function call stack depth is used to record the level of nested function calls during program execution, reflecting the complexity of the call relationship of code execution. For example, the call stack depth of a recursive function increases with the number of iterations. The instruction execution sequence is a chronological record of the sequence of machine instructions executed by the CPU and can be used to analyze the execution path of the code. The variable lifecycle tracks the complete process of a variable from declaration, assignment, to destruction, including creation time, number of modifications, memory usage changes, etc., reflecting the data processing logic. The number of loop iterations is a statistical calculation of the actual number of executions of various loops to evaluate the efficiency of code repetitive execution. Environmental characteristics include but are not limited to CPU cache hit rate, branch prediction failure rate, and GPU computing unit utilization. The CPU cache hit rate refers to the proportion of data successfully retrieved from the cache when the CPU accesses data. A low hit rate leads to frequent memory access and reduced execution speed. The branch prediction failure rate is the percentage of times the CPU incorrectly predicts the direction of a conditional branch. A high failure rate can cause interruptions in the instruction pipeline and increase latency. GPU compute unit utilization is the actual percentage of GPU cores used for parallel computing. Low utilization indicates that computing resources are underutilized.
[0041] S22. Use Min-Max normalization technology to normalize the numerical features in code behavior features and environmental features, and use unique hot encoding technology to normalize the categorical features in code behavior features and environmental features.
[0042] The original units and value ranges of different numerical features may vary greatly. For example, the function call stack depth may be between 0-100, while the CPU cache hit rate may be between 0%-100%, and the number of loop iterations may even reach tens of thousands. These features have different dimensions and magnitudes. If used directly for model training or analysis, features with a large value range will dominate the calculation, masking the influence of features with a small value range. Min-Max normalization is a linear normalization method that scales the original numerical features to a fixed interval, usually [0,1], retaining the original distribution of the data. It is suitable for scenarios where the relative size relationship between features needs to be maintained. In the processing of code behavior and environmental features, the specific implementation steps are as follows:
[0043] Assume that the collected numerical feature data set is X={x1,x2,…,x n}, where x irepresents the eigenvalue of the i-th sample. Then, the minimum and maximum values of each feature dimension are calculated respectively, and normalized using the following formula 1 to obtain the normalized result.
[0044]
[0045] Among them, min(X) is the minimum value, max(X) is the maximum value, and x i ′ is the normalized result.
[0046] Min-Max normalization scales all features to the range [0, 1], aligning them to the same magnitude. This avoids analysis bias caused by dimensional differences and ensures that all features are equally weighted in subsequent processing. This provides a more reliable and effective data foundation for subsequent analysis of code behavior and environmental characteristics.
[0047] S30. Determine the code category corresponding to the target program code based on the hotspot prediction model, and when the code category is a valid hotspot code, optimize the initial compilation strategy according to the environmental characteristics to obtain an optimized compilation strategy. The code category includes valid hotspot code and invalid high-frequency code.
[0048] In the embodiment of the present application, the system is as follows Figure 4 As shown, steps S31 to S33 are executed below. By comparing code behavior characteristics with core function indicators and combining hardware resource sensitivity analysis, the code is divided into two categories: effective hotspot code and invalid high-frequency code. Core function relevance assesses the relevance of the code to the core functions of the program, while resource sensitivity reflects the impact of code execution on the hardware environment. Combining the two can accurately identify code areas that are truly worth optimizing.
[0049] S31. Determine the code category corresponding to the target program code based on the hotspot prediction model.
[0050] In this step, by comparing code behavior characteristics with core function indicators and combining them with hardware resource sensitivity analysis, the code is classified into two categories: valid hotspot code and invalid high-frequency code, providing a decision basis for subsequent compilation optimization. Specifically, the system first compares the code behavior characteristics with multiple preset core function indicators, determines the comparison results corresponding to each core function indicator, and then determines the correlation between the target program code and the core function based on the comparison results. If the correlation is greater than or equal to a preset correlation threshold, the target program code is determined to be potentially valid hotspot code; otherwise, it is determined to be potentially invalid high-frequency code. For potentially valid hotspot code and potentially invalid high-frequency code, the target program code's resource sensitivity to hardware resources during execution is determined. Resource sensitivity indicates the fluctuation range of environmental characteristics during the execution of the target program code. If the resource sensitivity is less than the preset amplitude threshold and the target program code is potentially invalid high-frequency code, the target program code is classified as invalid high-frequency code. If the resource sensitivity is greater than or equal to the preset amplitude threshold and the target program code is potentially valid hotspot code, the target program code is classified as valid hotspot code. Furthermore, low-sensitivity potentially valid hotspot codes and high-sensitivity potentially invalid, high-frequency codes can be further verified through manual validation to precisely determine the code category corresponding to the target program code. For the mobile app startup process, the model can identify the core interface rendering path as a high-value hotspot, prioritizing compilation resources while filtering out high-frequency, low-impact code such as log printing to reduce ineffective compilation overhead. For example, in the online payment system in the fintech sector, the core function is user authentication. The code that obtains user ID information and compares it with the public security database directly impacts this core authentication function and is closely correlated with core functional indicators, making it preliminarily identified as a potentially valid hotspot. Furthermore, this code is highly sensitive to network and database performance and ultimately identified as a valid hotspot. The code that logs authentication operations, however, is solely responsible for recording information and has a low correlation with core authentication functional indicators. It is preliminarily identified as a potentially invalid, high-frequency code and, due to its low sensitivity to hardware resources, is ultimately identified as an invalid, high-frequency code.
[0051] S32: When the code category is a valid hotspot code, the initial compilation strategy is optimized according to the environmental characteristics to obtain an optimized compilation strategy.
[0052] S33: When the code category is invalid high-frequency code, stop the process of optimizing the initial compilation strategy, and continue to perform lightweight compilation on the target program code according to the initial compilation strategy.
[0053] In steps S32 and S33, when the code is identified as valid hotspot code, the system dynamically generates adaptation parameters based on runtime environment characteristics and implements aggressive optimizations on the compilation strategy, significantly improving code execution efficiency under specific hardware environments. Specifically, the system generates adaptation parameters based on real-time environment characteristics. These parameters include, but are not limited to, vectorization instruction parameters, loop unrolling factors, and task allocation ratios. For example, if GPU compute unit utilization is detected below 30%, the GPU task allocation ratio can be increased to 50%, thereby fully unleashing the hardware's computing potential. Furthermore, based on the generated adaptation parameters, the system performs aggressive optimization adjustments on the initial compilation strategy, ultimately resulting in an optimized compilation strategy. These aggressive optimization adjustments include, but are not limited to, enabling vectorized compilation, performing register reallocation, function inlining, and strengthening branch prediction. For example, loop operations can be converted to vector operations or hardware-specific instruction sets can be used instead of general algorithms to maximize code performance. If the code is identified as invalid high-frequency code, the system halts the optimization process and instead adopts a lightweight compilation strategy. This approach avoids wasting compilation resources on code with minimal performance impact while ensuring stable underlying performance. For example, in heterogeneous computing scenarios, when the policy detects low GPU load, it can automatically trigger GPU-accelerated branch optimizations. In contrast, traditional JIT technology relies on manually annotated hardware tags, which is less flexible and efficient.
[0054] S40: Compile and run the target program code according to the optimized compilation strategy.
[0055] In an embodiment of the present application, after the system completes the compilation and execution of the target program code according to the optimized compilation strategy, it automatically collects feedback data. This feedback data specifically includes the code behavior characteristics and corresponding environmental characteristics generated when the target program code is run after the optimized compilation strategy is used to compile and execute the target program code. Based on the collected feedback data, the system will then carry out compilation testing. Compilation testing covers two core aspects: one is numerical consistency testing, which is used to verify the consistency of the calculation results of the optimized code with the original logic. The other is control flow anomaly detection, which is used to identify whether abnormal execution paths are introduced during the optimization process. After the test is completed, if the test results of both tests indicate a pass, a test result indicating a valid result is generated. Conversely, if the test result of any one of the tests indicates a fail, a test result indicating an invalid result is generated. The system will package the compilation test results and the corresponding optimized compilation strategy into training samples and store them in a training set. The core function of this training set is to provide data support for parameter optimization of the hotspot prediction model, and to continuously improve the model's recognition accuracy of hotspot code by continuously accumulating samples. Furthermore, when the test results of the compilation test indicate that the optimization is effective, the compilation strategy is optimized again. When the detection result of the compilation detection indicates that the optimization is invalid, the compilation strategy is rolled back to the compilation strategy used in the last compilation and execution of the target program code.
[0056] In addition, the system establishes a dynamic weight adjustment mechanism for samples in the training set. Specifically, for samples with valid compilation detection results, the reward weight of the features associated with the corresponding compilation strategy is increased, strengthening the positive impact of the strategy in subsequent model training. For samples with invalid detection results, the penalty coefficient of the features associated with the corresponding compilation strategy is increased, weakening the negative impact of the strategy in model training. Through this reward / penalty mechanism, the training set can more accurately guide the parameter iteration of the hotspot prediction model, gradually improving the effectiveness and reliability of strategy optimization.
[0057] The method provided in the embodiment of the present application uses a hotspot prediction model to distinguish between valid hotspot code and invalid high-frequency code, avoiding the over-compilation of invalid high-frequency code by traditional JIT. At the same time, it focuses resources on optimizing valid hotspot code, solving the problems of traditional static strategies that fail to grasp the key points and resource mismatch, and improving the operating efficiency of the target program. At the same time, through the dynamic generation of optimization strategies through AI models, while aggressively optimizing valid hotspot code to improve performance, it avoids excessive resource consumption caused by over-optimization. Especially in resource-constrained scenarios such as edge devices and mobile terminals, it can significantly reduce energy consumption and reduce invalid computing overhead.
[0058] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a real-time compilation optimization device, such as Figure 5As shown, the system includes: a starting module 501 , a collection module 502 , an optimization module 503 , and an operation module 504 .
[0059] The startup module 501 is used to start the program running environment and compile and run the target program code according to the initial compilation strategy;
[0060] The acquisition module 502 is used to collect code behavior features and corresponding environment features generated when the target program code is run, and input the normalized code behavior features and environment features into the hotspot prediction model;
[0061] The optimization module 503 is configured to determine a code category corresponding to the target program code based on the hotspot prediction model, and when the code category is a valid hotspot code, optimize the initial compilation strategy according to the environmental characteristics to obtain an optimized compilation strategy, wherein the code category includes the valid hotspot code and the invalid high-frequency code;
[0062] The running module 504 is used to compile and run the target program code according to the optimization compilation strategy.
[0063] In a specific application scenario, the optimization module 503 is used to compare the code behavior characteristics with multiple preset core function indicators, determine the comparison results corresponding to each core function indicator, and determine the correlation between the target program code and the core function based on the comparison results corresponding to each core function indicator; if the correlation is higher than or equal to the preset correlation threshold, the target program code is determined to be a potential valid hotspot code, otherwise, the target program code is determined to be a potential invalid high-frequency code; for the potential valid hotspot code and the potential invalid high-frequency code, the resource sensitivity of the target program code to the hardware resources during operation is determined, and the resource sensitivity is used to indicate the fluctuation amplitude of the environmental characteristics when the target program code is executed; if the resource sensitivity is lower than the preset amplitude threshold and is a potential invalid high-frequency code, the code category corresponding to the target program code is determined to be an invalid high-frequency code; if the resource sensitivity is higher than or equal to the preset amplitude threshold and is a potential valid hotspot code, the code category corresponding to the target program code is determined to be a valid hotspot code.
[0064] In a specific application scenario, the optimization module 503 is used to generate adaptation parameters based on the environmental characteristics, and the adaptation parameters include but are not limited to vectorized instruction parameters, loop expansion factors and task allocation ratios; based on the adaptation parameters, the initial compilation strategy is aggressively optimized to obtain the optimized compilation strategy, wherein the aggressive optimization adjustment includes but is not limited to enabling vectorized compilation, performing register reallocation, function inlining and branch prediction enhancement.
[0065] In specific application scenarios, such as Figure 6 As shown, the device further includes: a feedback module 505.
[0066] In a specific application scenario, the feedback module 505 is used to collect feedback data after the target program code is compiled and run according to the optimized compilation strategy. The feedback data is the code behavior characteristics and corresponding environmental characteristics generated when the target program code is run after the target program code is compiled and run using the optimized compilation strategy; based on the feedback data, compilation detection is performed, and the compilation detection results and the corresponding optimized compilation strategy are stored as training samples in a training set. The compilation detection includes numerical consistency detection and control flow anomaly detection. The training set is used to optimize the model parameters of the hotspot prediction model; when the detection result of the compilation detection indicates that the optimization is effective, the compilation strategy is optimized again; when the detection result of the compilation detection indicates that the optimization is invalid, the compilation strategy is rolled back to the compilation strategy of the last compilation and running of the target program code.
[0067] In a specific application scenario, the feedback module 505 is used to, for the training samples stored in the training set, if the compilation detection result corresponding to the training sample indicates valid, increase the reward weight of the feature corresponding to the corresponding compilation strategy; if the compilation detection result corresponding to the training sample indicates invalid, increase the penalty coefficient of the feature corresponding to the corresponding compilation strategy.
[0068] In a specific application scenario, the acquisition module 502 is used to collect the code behavior characteristics and corresponding environmental characteristics generated when the target program code is running based on the data acquisition probe. The code behavior characteristics include but are not limited to the function call stack depth, instruction execution sequence, variable life cycle and number of loop iterations, and the environmental characteristics include but are not limited to CPU cache hit rate, branch prediction failure rate, and GPU computing unit utilization; the Min-Max normalization technology is used to normalize the numerical features in the code behavior characteristics and the environmental characteristics, and the one-hot encoding technology is used to normalize the categorical features in the code behavior characteristics and the environmental characteristics.
[0069] In a specific application scenario, the optimization module 503 is further configured to stop the process of optimizing the initial compilation strategy when the code category is the invalid high-frequency code, and continue to perform lightweight compilation on the target program code according to the initial compilation strategy.
[0070] The device provided in the embodiment of the present application uses a hotspot prediction model to distinguish between valid hotspot codes and invalid high-frequency codes, thereby avoiding over-compilation of invalid high-frequency codes by traditional JIT, and at the same time optimizing the valid hotspot codes by concentrating resources, solving the problem that traditional static strategies cannot grasp the key points and resource mismatch, and improving the operating efficiency of the target program. At the same time, by dynamically generating optimization strategies through AI models, while aggressively optimizing valid hotspot codes to improve performance, excessive resource consumption caused by over-optimization is avoided, especially in resource-constrained scenarios such as edge devices and mobile terminals, which can significantly reduce energy consumption and reduce invalid computing overhead. It should be noted that for other corresponding descriptions of the functional units involved in the just-in-time compilation optimization device provided in the embodiment of the present application, please refer to Figure 1 and Figure 2 The corresponding description in will not be repeated here.
[0071] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Figure 7 , Figure 7 This is a basic structural block diagram of the computer device in this embodiment.
[0072] like Figure 7 As shown, a schematic diagram of the internal structure of a computer device. The computer device includes a processor, a non-volatile storage medium, a memory and a network interface connected via a system bus. Among them, the non-volatile storage medium of the computer device stores an operating system, a database and computer-readable instructions, and the database may store a control information sequence. When the computer-readable instructions are executed by the processor, the processor can implement a real-time compilation optimization method. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute a real-time compilation optimization method. The network interface of the computer device is used to connect and communicate with a terminal. Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0073] In this embodiment, the processor is used to execute Figure 5The memory stores the program code and various data required to execute the specific functions of the startup module 501, acquisition module 502, optimization module 503, and operation module 504. The network interface is used to transmit data between user terminals or servers. The memory in this embodiment stores the program code and data required to execute all submodules in the just-in-time compilation and optimization device. The server can call the server's program code and data to execute the functions of all submodules.
[0074] The present invention also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the steps of the just-in-time compilation optimization method of any of the above embodiments.
[0075] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When executed, the program can include the processes in the above-described method embodiments. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0076] Those skilled in the art will appreciate that the steps, measures, and schemes in the various operations, methods, and processes discussed in this application may be interchanged, modified, combined, or deleted. Furthermore, other steps, measures, and schemes in the various operations, methods, and processes discussed in this application may also be interchanged, modified, rearranged, decomposed, combined, or deleted. Furthermore, steps, measures, and schemes in the prior art that are similar to those disclosed in this application may also be interchanged, modified, rearranged, decomposed, combined, or deleted.
[0077] The above description is only part of the implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A just-in-time compilation optimization method, characterized in that: include: Start the program running environment and compile and run the target program code according to the initial compilation strategy; Collecting code behavior features and corresponding environment features generated when the target program code is run, and inputting the normalized code behavior features and environment features into a hotspot prediction model; Determining a code category corresponding to the target program code based on the hotspot prediction model, and optimizing the initial compilation strategy according to the environmental characteristics when the code category is a valid hotspot code to obtain an optimized compilation strategy, wherein the code category includes the valid hotspot code and the invalid high-frequency code; Compile and run the target program code according to the optimized compilation strategy.
2. The method according to claim 1, characterized in that Determining the code category corresponding to the target program code based on the hotspot prediction model includes: Comparing the code behavior characteristics with a plurality of preset core function indicators, determining a comparison result corresponding to each core function indicator, and determining a correlation between the target program code and the core function based on the comparison result corresponding to each core function indicator; If the correlation degree is higher than or equal to a preset correlation degree threshold, the target program code is determined to be a potential valid hotspot code; otherwise, the target program code is determined to be a potential invalid high-frequency code; For the potentially valid hotspot code and the potentially invalid high-frequency code, determining resource sensitivity of the target program code to hardware resources during execution, the resource sensitivity being used to indicate a fluctuation range of the environmental characteristics when the target program code is executed; If the resource sensitivity is lower than a preset amplitude threshold and is a potential invalid high-frequency code, determining that the code category corresponding to the target program code is an invalid high-frequency code; If the resource sensitivity is greater than or equal to the preset amplitude threshold and the target program code is a potential valid hotspot code, the code category corresponding to the target program code is determined to be a valid hotspot code.
3. The method according to claim 1, characterized in that The optimizing the initial compilation strategy according to the environmental characteristics to obtain an optimized compilation strategy includes: generating adaptation parameters based on the environmental characteristics, the adaptation parameters including but not limited to vectorized instruction parameters, loop unrolling factors, and task allocation ratios; Based on the adaptation parameters, the initial compilation strategy is radically optimized and adjusted to obtain the optimized compilation strategy, wherein the radical optimization adjustment includes but is not limited to enabling vectorized compilation, performing register reallocation, function inlining, and branch prediction enhancement.
4. The method according to claim 1, wherein The method further comprises: After the target program code is compiled and run according to the optimization compilation strategy, feedback data is collected, wherein the feedback data is code behavior characteristics and corresponding environmental characteristics generated when the target program code is compiled and run according to the optimization compilation strategy; Based on the feedback data, compile detection is performed, and the compile detection results and the corresponding optimized compile strategy are stored as training samples in a training set, wherein the compile detection includes numerical consistency detection and control flow anomaly detection, and the training set is used to optimize the model parameters of the hotspot prediction model; When the detection result of the compilation detection indicates that the optimization is effective, optimizing the compilation strategy again; When the detection result of the compilation detection indicates that the optimization is invalid, the compilation strategy is rolled back to the compilation strategy used in the last compilation and execution of the target program code.
5. The method according to claim 4, characterized in that The method further comprises: For the training samples stored in the training set, if the compilation detection result corresponding to the training sample indicates valid, the reward weight of the feature corresponding to the corresponding compilation strategy is increased; if the compilation detection result corresponding to the training sample indicates invalid, the penalty coefficient of the feature corresponding to the corresponding compilation strategy is increased.
6. The method according to claim 1, wherein The collecting of code behavior features and corresponding environment features generated when the target program code is running, and normalizing the code behavior features and the environment features, includes: Collecting, based on a data acquisition probe, code behavior characteristics and corresponding environmental characteristics generated when the target program code is running, wherein the code behavior characteristics include but are not limited to function call stack depth, instruction execution sequence, variable life cycle, and loop iteration number; and the environmental characteristics include but are not limited to CPU cache hit rate, branch prediction failure rate, and GPU computing unit utilization; The Min-Max normalization technique is used to normalize the numerical features in the code behavior features and the environmental features, and the one-hot encoding technique is used to normalize the categorical features in the code behavior features and the environmental features.
7. The method according to claim 1, characterized in that After determining the code category corresponding to the target program code based on the hotspot prediction model, the method also includes: when the code category is the invalid high-frequency code, stopping the process of optimizing the initial compilation strategy, and continuing to lightweight compile the target program code according to the initial compilation strategy.
8. A real-time compilation optimization device, characterized in that: include: The startup module is used to start the program running environment and compile and run the target program code according to the initial compilation strategy; A collection module, configured to collect code behavior features and corresponding environment features generated when the target program code is run, and input the normalized code behavior features and environment features into a hotspot prediction model; an optimization module for determining a code category corresponding to the target program code based on the hotspot prediction model, and optimizing the initial compilation strategy according to the environmental characteristics to obtain an optimized compilation strategy when the code category is a valid hotspot code, the code category including the valid hotspot code and the invalid high-frequency code; The running module is used to compile and run the target program code according to the optimized compilation strategy.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.