Program code optimization using iterative application of machine learning model
A computing device may insert a library function into a set of code. The computing device may use the library function to capture one or more metrics associated with execution of the set of code in a testing environment. The computing device may evaluate the processing times to identify a portion of the set of code with a processing time that is highest compared to processing times of other portions of the set of code. The computing device may subdivide the portion of the set of code into subdivided portions of the set of code. The computing device may train a machine learning model, utilizing the subdivided portions of the set of code, to obtain a trained model. The computing device may recommend, using the trained machine learning model, optimization code to improve the processing time as the set of code is modified.
1 . A computer-implemented method for optimizing computer code, the computer-implemented method comprising:
modifying a set of code by inserting a library function into the set of code;
executing, in a testing environment, the set of code with the library function;
capturing, using the library function, one or more metrics associated with execution of the set of code in the testing environment,
the one or more metrics being captured during the execution of the set of code;
iteratively analyzing the set of code to identify, based on the one or more metrics, a portion of the set of code with a processing time that is highest compared to processing times of other portions of the set of code,
the portion of the set of code being identified to improve processing times of the set of code;
iteratively training a machine learning model, utilizing training data associated with the set of code, to obtain a trained machine learning model; and
iteratively recommending, using the trained machine learning model, optimization code to improve the processing time as the set of code is being modified,
wherein iteratively recommending the optimization code comprises generating the optimization code.
2 . The computer-implemented method of claim 1 , wherein inserting the library function comprises:
wrapping the set of code into library code of the library function by:
inserting a first portion of the library code prior to the set of code, and
inserting a second portion of the library code after the set of code.
3 . The computer-implemented method of claim 1 , wherein iteratively recommending the optimization code comprises:
generating a recommendation, for the optimization code, using stepwise refinements to identify the optimization code that reduces the processing time.
4 . The computer-implemented method of claim 1 , wherein iteratively recommending the improvement code comprises:
generating, using a large language model, optimization code to replace the set of code.
5 . The computer-implemented method of claim 1 , wherein training the machine learning model comprises:
training a large language model utilizing the subdivided portions of the code.
6 . The computer-implemented method of claim 1 , wherein identifying a portion of the set of code comprises:
identifying a code loop.
7 . The computer-implemented method of claim 1 , wherein identifying a portion of the set of code comprises:
identifying a machine learning inference.
8 . A computer program product comprising:
one or more computer readable storage media, and program instructions collectively stored on the one or more computer readable storage media, the program instructions comprising:
program instructions to modify a set of code by inserting performance monitoring code of a library function into the set of code running in a testing environment;
program instructions to execute the set of code;
program instructions to capture, using the performance monitoring code, performance metrics associated with execution of the set of code;
program instructions to iteratively analyze a plurality of code blocks of the set of code identify, based on the performance metrics, a code block, of the plurality of code blocks, with a processing time that is highest among processing times of the plurality of code blocks,
the plurality of code blocks being iteratively analyzed to improve a processing time of the set of code;
program instructions to iteratively train a machine learning model, utilizing training data associated with the set of code, to obtain a trained machine learning model; and
program instructions to generate, using the trained machine learning model, optimization code to improve the processing time of the set of code.
9 . The computer program product of claim 8 , wherein the program instructions to generate the recommendation comprise:
program instructions to generate, using a large language model, the optimization code to replace the set of code.
10 . The computer program product of claim 8 , wherein the program instructions to generate the recommendation comprise:
program instructions to generate the optimization code using stepwise refinements to reduce the processing time of the set of code.
11 . The computer program product of claim 8 , wherein the program instructions to capture the performance metrics comprise:
program instructions to obtain processing time data per lines of the set of code.
12 . The computer program product of claim 8 , wherein the set of code is a first set of code,
wherein the machine learning model is trained using the training data, that includes the first set of code, to generate recommendations to reduce processing times for code associated with the first set of code, and
wherein the program instructions further comprise program instructions to generate, using the trained machine learning model, a recommendation for a second set of code to reduce a processing time of the second set of code.
13 . The computer program product of claim 8 , wherein the processing time includes a processing time used by an application software associated with the set of code.
14 . The computer program product of claim 8 , wherein the processing time includes a processing time used by an operating system associated with the set of code.
15 . The computer program product of claim 8 , wherein the performance metrics include the processing time, a memory usage, and a central processing unit usage.
16 . A system comprising:
one or more devices configured to:
modify a set of code by inserting performance monitoring code into a set of code;
execute the set of code with the performance monitoring code;
capture, using the performance monitoring code, performance metrics associated with execution of the set of code;
iteratively analyze a plurality of code blocks of the set of code to identify, based on the performance metrics, a code block, of the plurality of code blocks, with a processing time that is highest among processing times of the plurality of code blocks,
the plurality of code blocks being iteratively analyzed to reduce processing times of the set of code;
iteratively train a machine learning model, utilizing training data associated with the set of code, to obtain a trained machine learning model;
iteratively generate, using the trained machine learning model, optimization code that reduces the processing time; and
cause the optimization code to replace the set of code to reduce the processing time.
17 . The system of claim 16 , wherein the processing time includes a clock time used by an application software associated with the set of code.
18 . The system of claim 16 , wherein the machine learning model includes a large language model, and
wherein the one or more devices are further configured:
generate, using the large language model, a recommendation to divide the set of code to reduce the processing time.
19 . The system of claim 18 , wherein the one or more devices, to generate the optimization code, are further configured to:
generate, using the large language model, the optimization code to replace the set of code.
20 . The system of claim 16 , wherein the one or more devices are further configured to:
store the code block and the performance metrics in a data repository;
obtain the code block and the performance metrics from the data repository; and
train the machine learning model, using the code block and the performance metrics obtained from the data repository, to obtain the trained machine learning model,
wherein the trained machine language model is trained to predict improvements to code.