Code optimization method and device, equipment, medium and product

By recording and analyzing the execution results of code branches in the operating system, and performing on-demand reversal during the compilation stage, the performance loss caused by excessive jumps in the application is solved, thus improving the application's running performance.

CN119292607APending Publication Date: 2025-01-10BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411365662.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-10

AI Technical Summary

Technical Problem

Excessive jump operations in applications lead to performance degradation, and existing technologies make it difficult to know the execution results of code branches in advance during the compilation stage to reduce jumps.

Method used

By running the target application in the operating system, the execution results of the code branches are recorded, and the results are reversed as needed during the compilation phase to generate target code, thereby reducing the number of jumps.

Benefits of technology

It reduces the performance loss caused by application navigation and improves application performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119292607A_ABST
    Figure CN119292607A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a code optimization method and device, equipment, a medium and a product.The method comprises the steps that a code branch operation result of a target application is obtained; determining a to-be-inverted target branch based on the jump state of the code branch in the code branch operation result; and performing instruction inversion on the target branch to generate a target code corresponding to the target application. By implementing the technical scheme disclosed by the invention, the number of skipping times in the running process of the application program is reduced, and the running performance of the application is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to code optimization methods, devices, equipment, media and products. Background Art

[0002] With the development of computer technology, various applications have emerged, such as social applications, office applications, entertainment applications, etc. The functions that can be realized by the application are based on code programs, and the code programs have multiple code branches for jumping.

[0003] At present, in the running environment of an application, a jump instruction corresponding to a code branch (such as the instruction corresponding to an IF statement, the instruction corresponding to a comparison statement) actually performs a judgment operation and a jump operation. When the condition result obtained by the jump instruction is True, a jump will occur. However, the jump operation is not necessarily executed. If there are too many jump operations in the application, it will cause additional performance loss in the application. Summary of the invention

[0004] In view of this, the present disclosure provides a code optimization method, apparatus, device, medium and product to solve the problem of high application performance loss caused by too many jumps.

[0005] In a first aspect, the present disclosure provides a code optimization method, including: obtaining a code branch running result of a target application; determining a target branch to be reversed based on the jump status of the code branch in the code branch running result; performing instruction reversal on the target branch to generate a target code corresponding to the target application.

[0006] In the second aspect, the present disclosure provides a code optimization device, including: an acquisition module, used to obtain the code branch running results of the target application; a target branch determination module, used to determine the target branch to be reversed based on the jump status of the code branch in the code branch running results; and a reversal module, used to perform instruction reversal on the target branch to generate a target code corresponding to the target application.

[0007] In a third aspect, the present disclosure provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the code optimization method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0008] In a fourth aspect, the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the code optimization method of the first aspect or any corresponding embodiment thereof.

[0009] In a fifth aspect, the present disclosure provides a computer program product, including computer instructions, which are used to enable a computer to execute the code optimization method of the first aspect or any corresponding embodiment thereof.

[0010] The code optimization method, device, equipment, medium and product provided by the embodiments of the present disclosure obtain the code branch running results of the target application, and determine the jump distribution results of each code branch according to the jump status of each code branch in the code branch running results. Therefore, in the compilation stage, the jump distribution results can be used to jump the code branch on demand, reducing the extra jumps of the code branch during the running process, thereby reducing the performance loss of the application program due to the jump, and improving the running performance of the application. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the specific embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0012] Figure 1 is a flowchart of a code optimization method according to an embodiment of the present disclosure;

[0013] Figure 2 is a flowchart of another code optimization method according to an embodiment of the present disclosure;

[0014] Figure 3 is a flowchart of obtaining code branch running results according to an embodiment of the present disclosure;

[0015] Figure 4 is a flowchart of another code optimization method according to an embodiment of the present disclosure;

[0016] Figure 5 is a schematic diagram of a code branch reversal according to an embodiment of the present disclosure;

[0017] Figure 6 is a structural block diagram of a code optimization device according to an embodiment of the present disclosure;

[0018] Figure 7 It is a schematic diagram of the hardware structure of the computer device of the embodiment of the present disclosure. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, rather than all the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.

[0020] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0021] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0022] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0023] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0024] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0025] In the running environment of the application, a jump instruction corresponding to a code branch (such as the instruction corresponding to the IF statement, the instruction corresponding to the comparison statement) actually performs a judgment operation and a jump operation. When the condition result obtained by the jump instruction is True, a jump will occur. However, the jump operation is not necessarily executed. If there are too many jump operations in the application, it will cause additional performance loss in the application.

[0026] However, if you want to reduce the jump operations of code branches, you need to make the jump instructions corresponding to the code branches produce False results as much as possible. However, the distribution of the running results of each code branch is difficult to know in advance during the compilation stage.

[0027] Based on this, the embodiment of the present disclosure runs the target application in the operating system in advance to record the running results of the code branches of the target application, and then uses the recorded running results of the code branches to perform on-demand reversal during the next compilation to reduce the number of jumps generated by the code branches in the target application.

[0028] According to an embodiment of the present disclosure, a code optimization method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0029] In this embodiment, a code optimization method is provided, which can be used in computer devices, such as computers, tablet computers, etc. Figure 1 is a flowchart of a code optimization method according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:

[0030] Step S101, obtaining the code branch running result of the target application.

[0031] The functions that the target application can achieve are developed based on programming languages, and each function has a corresponding program code library. The functions of the target application are implemented based on the main code line, and the code branches are branches that constitute the main code line, which are used to support the implementation of the functions of the main code line.

[0032] The code branch running result is the result obtained by compiling or running the code branch. Specifically, the running environment of the target application is deployed according to the type of the target application, and the target application is deployed to the running environment for compilation and running, so that the running results of all code branches can be collected.

[0033] Step S102, determining a target branch to be reversed based on the jump status of the code branch in the code branch execution result.

[0034] The jump status is used to indicate whether a jump will occur when executing the instruction corresponding to the code branch. Taking the code branch composed of IF statements as an example, if the condition result in the IF statement is True, it will jump to the corresponding code block for execution, otherwise it will be executed in sequence. The actual execution process of the code branch will be recorded in the code branch running results, and the jump status of the code branch can be obtained by parsing the actual execution process.

[0035] The target branch to be inverted is a code branch with a higher jump frequency. If the jump frequency of a code branch is greater than the non-jump frequency, it can be determined that the code branch has a higher jump frequency and is determined as the target branch to be inverted.

[0036] Step S103, performing instruction reversal on the target branch to generate target code corresponding to the target application.

[0037] The target code is the final code used to implement the target application. For the target branch with a high jump frequency, determine its jump condition and non-jump condition, and reverse the instructions corresponding to the jump condition and the instructions corresponding to the non-jump condition. When the target branch is executed again, it will be executed sequentially without jumping. Adjust the code of the target application according to the instruction reversal of the target branch to obtain the target code.

[0038] The code optimization method provided in this embodiment obtains the code branch running results of the target application, and determines the jump distribution results of each code branch according to the jump status of each code branch in the code branch running results. Therefore, the jump distribution results can be used to jump the code branch on demand during the compilation stage, reducing the extra jumps of the code branch during the running process, thereby reducing the performance loss of the application due to the jump, and improving the running performance of the application.

[0039] In this embodiment, a code optimization method is provided, which can be used in computer devices, such as computers, tablet computers, etc. Figure 2 is a flowchart of a code optimization method according to an embodiment of the present disclosure, such as Figure 2 As shown, the process includes the following steps:

[0040] Step S201, obtaining the code branch running result of the target application.

[0041] Specifically, the above step S201 may include:

[0042] Step S2011, in response to the installation operation for the target application, the target application is installed into a preset operating system, and a running log module is provided in the preset operating system.

[0043] The preset operating system is a pre-compiled operating system, in which a running log module is provided, and the running log code module is a code block for recording the running log. Specifically, the preset operating system is obtained based on the native operating system installed by the target application. Taking the Android operating system as an example, the source code of the Android operating system is modified to add a code block for recording the running log in the source code, and the updated operating system code is compiled to obtain an operating system configured with a running log module.

[0044] The installation operation is an operation by a technician to deploy a target application. The preset operating system is deployed in the computer device. When the technician installs the target application into the preset operating system, the computer device can respond to the technician's installation operation and install the target application into the preset operating system according to the installation operation.

[0045] Step S2012, running the target application in the preset operating system, and recording the code branch running results through the running log module.

[0046] When it is detected that the target application has been successfully installed in the preset operating system, the target application is started so that the target application runs in the preset operating system, such as Figure 3 The preset operating system is provided with a running log module. During the running process of the target application, the running log module in the preset operating system can monitor the running status of the target application in real time and record the running results of each code branch of the target application.

[0047] In some optional implementations, the above step S201 further includes: exporting the code branch running result to obtain an export file corresponding to the code branch running result.

[0048] After obtaining the code running results of the target application, the code branch running results are extracted from them, and the form in which the code branch running results are output is determined, such as printing to the console, writing to a file, storing in a database, etc. Of course, other output methods can also be used, which are not specifically limited here.

[0049] Configure export information in the preset operating system of the computer device, and export the code branch running results according to the export information. The export information may include the form of the export file (such as CSV, JSON, XML, etc.) and the save path. Specifically, Figure 3 As shown, when it is necessary to export the code branch running results, the corresponding export operation is performed according to the output form of the code branch running results and the form of the export file, and the export file of the generated code branch running results is saved to the specified path.

[0050] In the above implementation, by exporting the code branch running results, it is convenient to perform on-demand reversal of the code branch according to the code branch running results in the next compilation stage.

[0051] Step S202: Determine the target branch to be reversed based on the jump status of the code branch in the code branch execution result. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0052] Step S203, perform instruction reversal on the target branch to generate target code corresponding to the target application. Figure 1Step S103 of the illustrated embodiment will not be described in detail here.

[0053] The code optimization method provided in this embodiment integrates a running log module in a preset operating system, so that when the target application is run on the preset operating system, the running results of all code branches are collected through the running log module, thereby realizing the pre-acquisition of the running results of the code branches, so that the jump distribution of the code branches can be determined based on the running results of the code branches.

[0054] In this embodiment, a code optimization method is provided, which can be used in computer devices, such as computers, tablet computers, etc. Figure 4 is a flowchart of a code optimization method according to an embodiment of the present disclosure, such as Figure 4 As shown, the process includes the following steps:

[0055] Step S301, obtain the code branch running results of the target application. For details, see Figure 2 Step S201 of the illustrated embodiment will not be described in detail here.

[0056] Step S302: determining a target branch to be reversed based on the jump status of the code branch in the code branch execution result.

[0057] Specifically, the above step S302 includes:

[0058] Step S3021, obtaining the current execution branch of the target application.

[0059] The current execution branch is the code branch currently traversed. The target application has a corresponding application package, which contains code for supporting the implementation of various functions of the target application. Specifically, the application package of the target application is stored in the storage space of the computer device. The computer device can access the application package of the target application and traverse all the codes in the application package to obtain the various execution branches of the target application in turn.

[0060] Step S3022, finding the current execution branch from the code branch execution result, and determining the jump state of the current execution branch in the code branch execution result.

[0061] The jump status is used to characterize whether a code branch has jumped during operation. The code branch operation results record the operation results of each code branch, and the jump status of the code branch is determined by the operation results. For any currently traversed execution branch, the computer device can read the code branch operation results recorded by the operation log module, and query the operation results of the current execution branch from them to determine the jump status of the current execution branch.

[0062] Step S3023, determining whether the currently executed branch meets the reversal condition according to the jump status.

[0063] The reversal condition is a pre-set condition for the reversal to occur. The number of jumps of the current execution branch in the code branch running result is counted to determine the jump distribution result of the current execution branch in the code branch running result. Then, combined with the jump distribution result of the current execution branch, determine whether the current execution branch needs to be reversed. If the current execution branch meets the reversal condition, execute step S3024, otherwise, continue to traverse the application package of the target application to obtain the next code branch, and determine whether the next code branch meets the reversal condition until the application package is traversed.

[0064] In some optional implementations, the reversal condition is determined based on a first probability of a jump occurring in the currently executed branch and a second probability of a non-jump occurring, and the above step S3023 includes:

[0065] Step a1: if the first probability is greater than the second probability, it is determined that the currently executed branch meets the reversal condition.

[0066] Step a2: If the first probability is less than the second probability, it is determined that the currently executed branch does not satisfy the reversal condition.

[0067] When the first probability is greater than the second probability, it means that the number of jumps in the code branch running result of the current execution branch is greater than the number of non-jumps. Since too many jumps will affect the running performance of the target application, at this time, in order to reduce the number of jumps, it is necessary to perform a reversal operation on the current execution branch, that is, the current execution branch meets the reversal condition.

[0068] When the first probability is less than the second probability, it means that the number of jumps in the code branch running result of the current execution branch is less than the number of non-jumps. At this time, there is no need to reverse the current execution branch, that is, the current execution branch does not meet the reversal condition.

[0069] In the above implementation, by comparing the first probability and the second probability, it is determined whether the current execution branch meets the reversal condition, thereby enabling the current execution branch to be reversed as needed, so that the jump of the current execution branch is more in line with the actual scenario of the target application.

[0070] Step S3024: If the current execution branch meets the reversal condition, the current execution branch is determined as the target branch to be reversed.

[0071] If the current execution branch meets the reversal condition, it means that the probability of the current execution branch jumping is relatively high. In order to reduce the number of jumps of the current execution branch, the current execution branch needs to be reversed. At this time, the current execution branch is determined as the target branch to be reversed, so that the reversal operation can be performed on the current execution branch so that it can be executed sequentially.

[0072] like Figure 5 As shown, taking the case where the instruction of the currently executed branch is True and the reversal operation is performed as an example, when the probability that the instruction of the currently executed branch is True is greater than the probability that the instruction is False, it is determined that the currently executed branch meets the reversal condition; when the probability that the instruction of the currently executed branch is True is less than the probability that the instruction is False, it is determined that the currently executed branch does not meet the reversal condition, and continues to traverse other code branches in the application package to determine in turn whether each code branch in the target application meets the reversal condition.

[0073] Step S303, performing instruction reversal on the target branch to generate target code corresponding to the target application.

[0074] Specifically, the above step S303 includes:

[0075] Step S3031, obtaining the jump instructions and non-jump instructions corresponding to the target branch.

[0076] The target branch is a code branch with a jump probability greater than a non-jump probability, that is, the target branch has both jump instructions and non-jump instructions. When a jump instruction is satisfied, the code block corresponding to the jump instruction is executed, and when a non-jump instruction is satisfied, the code block corresponding to the non-jump instruction is executed.

[0077] The target branch is generated based on the code and has a corresponding code structure. By parsing the code structure corresponding to the target branch, the conditional judgment statement and jump statement in the code corresponding to the target branch can be determined, and the jump instruction and non-jump instruction corresponding to the target branch can be determined based on the conditional judgment statement and jump statement.

[0078] Step S3032, invert the jump instruction into a non-jump instruction.

[0079] In order to reduce the number of jumps of the target branch during operation, the target branch instruction is reversed, that is, the jump instruction is reversed into a non-jump instruction, so that when the target branch is executed, it will be executed sequentially according to the non-jump instructions.

[0080] Step S3033, transforming the positions of the code block corresponding to the jump instruction and the code block corresponding to the non-jump instruction to obtain the target code.

[0081] After completing the reversal of the jump instruction and the non-jump instruction, the code blocks corresponding to the jump instruction and the non-jump instruction are adjusted to adjust the positions of the code blocks corresponding to the jump instruction and the code blocks corresponding to the non-jump instruction so that the instructions and the code blocks match. For each code branch in the application package that meets the reversal condition, the instruction reversal operation and the code block adjustment operation are performed, and the code after the instruction reversal and the code block adjustment is determined as the target code.

[0082] Step S304, compile the target code to generate an application package of the target application.

[0083] The target code is implemented based on the programming language, and different programming languages ​​have corresponding compilers. Specifically, the corresponding compiler is determined according to the programming language corresponding to the target code, and the compiler is used to compile the target code to obtain executable machine code. For example, for C or C++ target code, the gcc or clang compiler can be used to compile the code; for Java target code, the javac compiler can be used to compile the code.

[0084] By compiling the target code, one or more target files can be obtained, and multiple target files can be combined to generate an executable application. The executable application and its related resources (such as configuration files) are packaged to generate an application package. The application package of the target application obtained is deployed to the operating system for operation, so that the target application is executed in sequence according to the target code to realize the various functions of the target application.

[0085] The code optimization method provided in this embodiment determines whether the current execution branch meets the reversal condition in combination with the jump status. When the current execution branch meets the reversal condition, the current execution branch is reversed to reverse the jump instruction of the current execution branch into a non-jump instruction. At the same time, the code blocks corresponding to the jump instruction and the non-jump instruction are adjusted so that the current execution branch will no longer jump during the next compilation, thereby greatly reducing the number of jumps of the target application.

[0086] As a specific application example of the embodiment of the present disclosure, the above code optimization method is described in conjunction with a code example. The code example is as follows:

[0087] if(condition==0){

[0088] code a;

[0089] }else{

[0090] code b;

[0091] }.

[0092] After converting the above code into executable machine code, its actual execution process is as follows:

[0093] if-eqz condition:cond_a

[0094] code b;

[0095] return void;

[0096] :cond_a

[0097] code a;

[0098] return void.

[0099] When condition is 0, it jumps to cond_a and starts executing. That is, when condition is 0, the condition is True, and the IF instruction actually jumps once. if-eqz indicates whether it is 0, and the corresponding instruction is whether it is not 0: if-nez.

[0100] For an IF instruction that is often True, you only need to replace the instruction with the opposite instruction (such as if-eqz replaced by if-nez) to avoid jumping in most cases.

[0101] The code branch running results can be recorded when executing the application instructions corresponding to each code branch, and the instructions corresponding to the code branch can be reversed based on the jump distribution in the code branch running results. For example, in the above code, condition is 0 in most cases. If the instruction is replaced with if-nez at this time, this jump can be avoided. The target code after the instruction is reversed is as follows:

[0102] if-nez condition:cond_b

[0103] code a;

[0104] return void;

[0105] :cond_b

[0106] code b;

[0107] return void.

[0108] Each code branch in the target application that meets the reversal condition is reversed to obtain the target code corresponding to the target application. Then, the target code obtained after the reversal is compiled to obtain a new application package, so that the output new application package will be able to significantly reduce the extra jumps generated by the code branch, thereby improving the running performance of the target application.

[0109] In the present embodiment, a code optimization device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.

[0110] This embodiment provides a code optimization device, such as Figure 6 As shown, including:

[0111] The acquisition module 301 is used to obtain the code branch running result of the target application.

[0112] The target branch determination module 302 is used to determine the target branch to be reversed based on the jump status of the code branch in the code branch execution result.

[0113] The reversal module 303 is used to perform instruction reversal on the target branch and generate target code corresponding to the target application.

[0114] In some optional implementations, the acquisition module 301 includes:

[0115] The installation unit is used to install the target application into a preset operating system in response to an installation operation for the target application, wherein the preset operating system is provided with a running log module.

[0116] The operation recording unit is used to run the target application in the preset operating system and record the code branch operation results through the operation log module.

[0117] In some optional implementations, the acquisition module 301 further includes:

[0118] The export unit is used to export the code branch running results and obtain the export file corresponding to the code branch running results.

[0119] In some optional implementations, the target branch determination module 302 includes:

[0120] The branch acquisition unit is used to acquire the current execution branch of the target application.

[0121] The jump state determination unit is used to find the current execution branch from the code branch running result and determine the jump state of the current execution branch in the code branch running result.

[0122] The reversal judgment unit is used to determine whether the current execution branch meets the reversal condition according to the jump state.

[0123] The branch determination unit determines the current execution branch as a target branch to be reversed if the current execution branch meets the reversal condition.

[0124] In some optional implementations, the reversal condition is determined based on a first probability of a jump occurring in the currently executed branch and a second probability of a non-jump occurring, and the reversal determination unit includes:

[0125] The first determination unit is configured to determine that the currently executed branch satisfies a reversal condition if the first probability is greater than the second probability.

[0126] The second determination unit is configured to determine that the currently executed branch does not satisfy the reversal condition if the first probability is less than the second probability.

[0127] In some optional implementations, the above reversal module 303 includes:

[0128] The instruction fetch unit is used to fetch the jump instructions and non-jump instructions corresponding to the target branch.

[0129] A reversal unit is used to reverse jump instructions into non-jump instructions.

[0130] The conversion unit is used to convert the positions of the code blocks corresponding to the jump instructions and the code blocks corresponding to the non-jump instructions to obtain the target code.

[0131] In some optional embodiments, the above device further includes:

[0132] The compilation module is used to compile the target code and generate the application package of the target application.

[0133] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0134] The code optimization device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0135] The code optimization device provided by the embodiment of the present disclosure obtains the code branch running result of the target application, and determines the jump distribution result of each code branch according to the jump status of each code branch in the code branch running result. Therefore, in the compilation stage, the jump distribution result can be used to jump the code branch on demand, reducing the extra jumps of the code branch during the running process, thereby reducing the performance loss of the application program due to the jump, and improving the running performance of the application.

[0136] The present disclosure also provides a computer device having the above Figure 6 The code optimization device shown.

[0137] See also Figure 7 , Figure 7 is a schematic diagram of a computer device provided by an optional embodiment of the present disclosure, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0138] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0139] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0140] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0141] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0142] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.

[0143] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0144] The computer device also includes a communication interface, which is used for the computer device to communicate with other devices or a communication network.

[0145] The embodiments of the present disclosure also provide a computer-readable storage medium. The above-mentioned method according to the embodiments of the present disclosure can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium and downloaded through a network, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0146] A part of the present disclosure may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present disclosure through the operation of the computer. Those skilled in the art should understand that the existence of computer program instructions in computer-readable media includes, but is not limited to, source files, executable files, installation package files, etc., and accordingly, the way in which computer program instructions are executed by a computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to the computer.

[0147] Although the embodiments of the present disclosure have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A code optimization method, characterized in that: The method comprises: Get the code branch running results of the target application; Determining a target branch to be reversed based on the jump status of the code branch in the code branch execution result; Instructions of the target branch are reversed to generate target code corresponding to the target application.

2. The method according to claim 1, characterized in that The step of obtaining the code branch running result of the target application includes: In response to an installation operation for a target application, installing the target application into a preset operating system, wherein the preset operating system is provided with a running log module; The target application is run in the preset operating system, and the code branch running result is recorded through the running log module.

3. The method according to claim 2, characterized in that Also includes: Export the code branch running result to obtain an export file corresponding to the code branch running result.

4. The method according to claim 1, characterized in that: The step of determining the target branch to be reversed based on the jump state of the code branch in the code branch running result includes: Obtaining the current execution branch of the target application; Find the current execution branch from the code branch execution result, and determine the jump state of the current execution branch in the code branch execution result; Determine whether the currently executed branch satisfies a reversal condition according to the jump state; If the currently executed branch meets the reversal condition, the currently executed branch is determined as the target branch to be reversal.

5. The method according to claim 4, characterized in that The reversal condition is determined based on a first probability of the current execution branch jumping and a second probability of non-jumping; and determining whether the current execution branch satisfies the reversal condition according to the jump state includes: If the first probability is greater than the second probability, determining that the currently executed branch satisfies the reversal condition; If the first probability is less than the second probability, it is determined that the currently executed branch does not satisfy the reversal condition.

6. The method according to claim 1, characterized in that The step of performing instruction reversal on the target branch to generate target code corresponding to the target application includes: Obtain jump instructions and non-jump instructions corresponding to the target branch; Reversing the jump instruction into the non-jump instruction; The positions of the code block corresponding to the jump instruction and the code block corresponding to the non-jump instruction are transformed to obtain the target code.

7. The method according to any one of claims 1 to 6, characterized in that: Also includes: Compile the target code to generate an application package of the target application.

8. A code optimization device, characterized in that: The device comprises: The acquisition module is used to obtain the code branch running results of the target application; A target branch determination module, used to determine a target branch to be reversed based on the jump status of the code branch in the code branch operation result; The reversal module is used to perform instruction reversal on the target branch and generate target code corresponding to the target application.

9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the code optimization method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the code optimization method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the code optimization method according to any one of claims 1 to 7.