Application optimization method and device, equipment and readable storage medium
By comparing the parameter and structure information of global functions and basic functions in the application, filtering for mismatch situations and replacing them when conditions are met, the operation exceptions caused by the update of basic library functions are solved, and the stability of the application is improved .
Patent Information
- Application Number
- CN202411252247.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-06
- Publication Date
- 2024-12-27
AI Technical Summary
Due to the update iteration of the basic library functions, the application's global functions do not match the corresponding basic library functions, resulting in abnormal operation and affecting the stability of the application.
Before replacing the global function with the corresponding basic function, analyze and compare the parameter and structure information, filter out mismatch situations, and replace them when the preset conditions are met to reduce the chance of abnormal operation.
Improves the stability of the application when running in different versions of the basic function library environments, and reduces the risk of call failure.
Smart Images

Figure CN119201222A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and specifically relates to an application optimization method, device, electronic device and readable storage medium. Background Art
[0002] There are various basic library functions in the operating system, and the basic library functions are used to provide the caller with corresponding functions in the operating system.
[0003] At present, each application can develop its own global function. On the basis of being able to achieve the same functions as the basic library function, the global function can also achieve more functions, thus better meeting the needs of the application. Therefore, the application can replace the corresponding basic library function with the global function developed by itself to give the application more functions.
[0004] Since the basic library functions are constantly updated and iterated, sometimes there will be a problem that the global function implementation of the application does not match the implementation of the corresponding basic library function, resulting in operational anomalies such as call failure, which in turn affects the normal implementation of the function functions and reduces the operational stability of the application. Summary of the invention
[0005] The present invention aims to provide an application optimization method, device, electronic device and readable storage medium, which at least solve the problems in the prior art.
[0006] In order to solve the above-mentioned technical problems, the present invention is achieved as follows:
[0007] In a first aspect, an embodiment of the present invention provides a method for optimizing an application program, the method comprising:
[0008] Obtaining the global functions corresponding to the application program, and determining basic functions matching the global functions from the basic function library of the operating system;
[0009] In the case where it is detected that the parameters of the global function are consistent with the parameters of the basic function, determining first information of a structure of the global function and second information of a structure of the basic function;
[0010] When the first information and the second information meet a preset condition, the basic function is replaced by the global function, so that when the application executes the basic function, the replaced global function is called for execution.
[0011] In a second aspect, an embodiment of the present invention further provides an application optimization device, the device comprising:
[0012] An acquisition module is used to acquire the global functions corresponding to the application program, and to determine the basic functions matching the global functions from the basic function library of the operating system;
[0013] A structure information module, used for determining first information of a structure of the global function and second information of a structure of the basic function when it is detected that the parameters of the global function are consistent with the parameters of the basic function;
[0014] A replacement module is used to replace the basic function with the global function when the first information and the second information meet preset conditions, so that when the application executes the basic function, the replaced global function is called for execution.
[0015] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.
[0016] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0017] In an embodiment of the present invention, before replacing a global function with a corresponding basic function, an analysis and comparison of the information of the global function and the corresponding basic function can be performed. Specifically, whether the parameters of the global function are consistent with the parameters of the basic function is first detected. If they are consistent, whether the first information of the structure of the global function and the second information of the structure of the basic function meet the preset conditions is detected. If the preset conditions are met, it can be determined that there is no risk in the replacement operation, thereby realizing risk screening before replacement. The embodiment of the present invention can screen out the situation where the global function and the corresponding basic function do not match, and when it is determined after screening that the function replacement is unlikely to cause an operation abnormality, the global function and the corresponding basic function are replaced, thereby reducing the probability of operation abnormalities such as call failures caused by mismatches between global functions and basic functions when the application is running in the environment of different versions of basic function libraries, thereby improving the operation stability of the application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 is a flowchart of a method for optimizing an application program provided by an embodiment of the present invention;
[0019] Figure 2 is a flowchart of another method for optimizing an application program provided by an embodiment of the present invention;
[0020] Figure 3 It is an overall flow chart of an application optimization method provided by an embodiment of the present invention;
[0021] Figure 4 is a block diagram of an application optimization device provided by an embodiment of the present invention;
[0022] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0023] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0024] Figure 1 is a flowchart of a method for optimizing an application program provided by an embodiment of the present invention. Figure 1 As shown, the method may include:
[0025] Step 101, obtaining the global functions corresponding to the application program, and determining basic functions matching the global functions from the basic function library of the operating system.
[0026] In an embodiment of the present invention, the basic function library may be a function library provided by an operating system, and the basic function library may generally include a large number of basic functions, which may be called and used by application programs to implement corresponding functions. There are many types of basic function libraries, such as glibc, musl, ulibc, etc. The basic function library provides an IFUNC mechanism, which allows multiple implementations to be created for a certain function, and selects the function according to actual conditions at runtime, that is, the IFUNC mechanism allows a function to have multiple different versions of implementations, and multiple different versions of implementations provide the same function. In one implementation, the IFUNC mechanism can decide which version of the function to use according to the capabilities of the hardware at runtime.
[0027] Specifically, the application can develop a global function for its own runtime call to replace the corresponding basic function according to actual needs. The global function not only implements the same functions as the corresponding basic function, but also has more abundant additional functions, thus meeting the increasingly rich functional needs of the application. Since the basic function library has been iteratively developed in multiple versions, if the global function of the application is directly replaced with the corresponding basic function, when the application runs in the environment of different versions of the basic function library, there may be a problem that the implementation of the global function does not match the basic function, resulting in runtime errors.
[0028] In order to solve this problem, an embodiment of the present invention can analyze and compare the global function and the corresponding basic function before replacing the global function with the corresponding basic function, so as to realize risk screening and screen out the situations where the global function and the corresponding basic function do not match. When it is determined after screening that the function replacement is unlikely to cause operation abnormalities, the global function and the corresponding basic function are replaced. This reduces the probability of operation abnormalities such as call failure due to mismatch between global functions and basic functions when the application is running in an environment with different versions of basic function libraries, and improves the operation stability of the application.
[0029] Among them, the similarity between basic functions and global functions is that both implement the same function functionality. The difference is that basic functions are functions provided by the basic function library of the operating system, and their function implementation is used to meet the environmental requirements of the operating system; while global functions are functions provided by applications, which are often written by the developers of the application themselves, and their function implementation is used to meet the specific operating requirements of the application in the operating system.
[0030] For example, suppose that the basic function library of the operating system provides a basic function A for implementing the averaging function. The developer performs secondary development for the averaging function in the application and implements the global function A'. The application needs to use the average value result of the floating point type. Based on this requirement, the global function A', on the basis of implementing the averaging, also determines whether the calculated average value result is of the floating point type. If so, it is used, otherwise it is discarded. Then, before using the global function A' to replace the basic function A, the embodiment of the present invention can analyze and compare the global function A' with the corresponding basic function A, thereby implementing risk screening.
[0031] In this step, the global function can be a functional function provided by the application. The implementation of the global function is used to meet the running requirements of the application in the operating system. The purpose of the global function is to replace the corresponding basic function in the basic function library to implement the corresponding function function, so that when the subsequent application needs to implement the function function of the basic function, it can call the replaced global function for execution. The embodiment of the present invention can first find the global function waiting to be replaced in the application, and match the corresponding basic function to be replaced from the basic function library for the global function. If the match is successful, the subsequent step 102 is judged. If the match fails, the replacement process is exited.
[0032] Step 102: when it is detected that the parameters of the global function are consistent with the parameters of the basic function, determine first information of a structure of the global function and second information of a structure of the basic function.
[0033] In an embodiment of the present invention, for a group of corresponding global functions and basic functions, the parameters of the global function and the parameters of the corresponding basic function can be obtained respectively, and then the parameters of the global function and the parameters of the corresponding basic function can be compared. When the parameters of the global function are consistent with the parameters of the corresponding basic function, the next step of judgment is performed. When the parameters of the global function are inconsistent with the parameters of the corresponding basic function, it is determined that the global function implemented by the application and the corresponding basic function in the basic function library are different, and for this replacement operation, it is prompted that the replacement cannot be performed.
[0034] Specifically, in one case, to determine whether the parameters of the corresponding global function and basic function are consistent, first, when the number of parameters of the global function and the basic function are the same, determine whether the definition names and parameter meanings of all parameters of the global function are consistent with the definition names and parameter meanings of all parameters of the corresponding basic function. If they are consistent, the parameters of the global function are considered to be consistent with the parameters of the corresponding basic function. If the number of parameters of the global function and the basic function are inconsistent, or the definition name and / or parameter meaning of a parameter of the global function is different from that of the corresponding basic function, then the parameters of the global function are considered to be inconsistent with the parameters of the corresponding basic function.
[0035] In another case, to determine whether the parameters of the corresponding global function and basic function are consistent, first, when the number of parameters of the global function and the basic function are the same, it can be determined whether the parameter meanings of all parameters of the global function are consistent with the parameter meanings of all parameters of the corresponding basic function. If they are consistent, the parameters of the global function are considered to be consistent with the parameters of the corresponding basic function. If the number of parameters of the global function and the basic function are inconsistent, or the parameter meaning of a parameter of the global function is different from that of the corresponding basic function, the parameters of the global function are considered to be inconsistent with the parameters of the corresponding basic function.
[0036] In another case, to determine whether the parameters of the corresponding global function and basic function are consistent, first, when the number of parameters of the global function and the basic function is consistent, a semantic analysis can be performed based on a third-party synonym dictionary to determine whether the parameter meanings corresponding to all the parameters of the global function are consistent with the parameter meanings of all the parameters of the corresponding basic function. If they are consistent, the parameters of the global function are considered to be consistent with the parameters of the corresponding basic function. When the parameter meanings of the parameters of the global function are consistent with the parameter meanings of the parameters of the corresponding basic function, but the parameter names of some parameters of the global function are inconsistent with the parameter names of the parameters of the corresponding basic function, after replacing the basic function with the global function, the parameter names of some parameters of the replaced global function are uniformly modified to be consistent with the parameter names in the parameters of the corresponding basic function, so that the application can smoothly call the global function for execution.
[0037] The parameter name can be a character name of the parameter, such as int begin, int start, int end, etc. The parameter meaning is the result of functional analysis of the parameter. For example, the parameter names of the parameter int begin and the parameter int start are different, but after comparing the parsed parameters int begin and int start through the synonym dictionary, it is found that the corresponding parameters have the same meaning, both of which are parameters meaning "start". The parameter names and parameter meanings of the parameter int begin and the parameter int end are different. The parameter int begin is a parameter meaning "start", and the parameter int end is a parameter meaning "end". In this case, only when the int begin parameter of the global function is inconsistent with the int start parameter of the corresponding basic function, the basic function is replaced with the global function, and "begin" in the replaced global function is uniformly replaced with "start".
[0038] Optionally, the parameters of the global function and the parameters of the basic function include: one or more of the function type and structure member information.
[0039] Specifically, the parameters of global functions and basic functions include parameters such as function type and structure member information, where a structure (struct) refers to a data structure, which is a type of aggregate data type in C language. Structures can be declared as variables, pointers, or arrays, etc., to implement more complex data structures. Structures are also a collection of elements, which are called members of the structure. These members can be of different types and are generally accessed by name. When comparing the structures in the parameters of global functions and basic functions, the structure members can be compared, including the comparison of member contents and the comparison of the number of members. If there are differences in the member contents of the structure and the number of members included in the structure, it is considered that the global function implemented by the application is different from the basic function in the basic function library, and a prompt is given that the replacement cannot be performed.
[0040] Furthermore, when it is detected that the parameters of the global function are consistent with the parameters of the basic function, the first information of the structure of the global function and the second information of the structure of the basic function can be obtained to perform subsequent comparison of the information of the structures of the respective functions.
[0041] Step 103: When the first information and the second information meet a preset condition, the basic function is replaced by the global function, so that when the application executes the basic function, the replaced global function is called for execution.
[0042] In an embodiment of the present invention, after obtaining the first information of the structure of the global function and the second information of the structure of the basic function, the structural information of the two can be compared. When the first information and the second information meet the preset conditions, it can be determined that the probability of the replacement operation causing an exception is small, that is, the basic function is replaced by the global function. After the replacement, when the subsequent application is running, the global function can be called instead of the basic function to implement the function function. Since the implementation of the global function can better meet the running requirements of the application in the operating system, it can improve the running stability of the application in the operating system. When the first information and the second information do not meet the preset conditions, it is determined that the replacement operation has risks, and the replacement is stopped or a prompt of the risk is issued.
[0043] Optionally, the first information includes: the capacity of the first allocated space for the structure of the global function; the second information includes: the capacity of the second allocated space for the structure of the basic function, and step 103 may specifically include:
[0044] Sub-step 1031: when the capacity of the first allocation space is consistent with the capacity of the second allocation space, determine whether the first information and the second information meet a preset condition, and use the global function to replace the basic function.
[0045] Sub-step 1032: When the capacity of the first allocation space and the capacity of the second allocation space are inconsistent, otherwise, a risk reminder is issued, wherein the risk reminder is used to indicate that there is an operational abnormality in using the global function to replace the basic function.
[0046] Specifically, for sub-steps 1031-1032, in the process of running the function, a storage space of corresponding size can be allocated for the structure of the function, and the capacity of the storage space allocated for the structure specifically refers to: the size occupied by the structure in the storage medium (such as memory). The capacity of the allocated space of the structure is determined by the number of members included in the structure, and the capacity of the allocated space of the structure is positively correlated with the number of members included in the structure. Therefore, in one implementation, the preset conditions may include: the capacity of the storage space allocated for the structure of the global function is consistent with the capacity of the storage space allocated for the structure of the basic function. This is because if the storage space capacity allocated for each of the two structures is inconsistent, the data ranges that the two functions can access will be inconsistent. If, due to this difference, the application does not have enough application space when accessing data, it will cause program errors and affect the running stability of the application.
[0047] Specifically, the capacity of the first allocated space is consistent with the capacity of the second allocated space, which means that the size occupied by the first allocated space in the storage medium is completely consistent with the size occupied by the second allocated space in the storage medium.
[0048] For example, for a structure struct stu{char ch1; int i; double b; char ch2}, it includes 3 members, the int type member requires 4 bytes, the char type member requires 1 byte, and the double type member requires 8 bytes. The capacity of the storage space allocated for the structure can be 14 bytes. It should be noted that the size of the storage space allocated for the structure can be calculated by calling the sizeof() function. For the above structure, the return value after calling the sizeof() function is 14 bytes.
[0049] It should be noted that, when the capacity of the first allocated space and the capacity of the second allocated space are inconsistent, the embodiment of the present invention can stop the replacement operation or issue a risk reminder. The risk reminder is used to indicate that there is a risk of abnormal operation when using a global function to replace a basic function. The risk reminder can prompt the user, and the user can choose to accept the risk reminder, stop the replacement operation, or ignore the risk reminder according to actual needs.
[0050] In summary, in an embodiment of the present invention, before the replacement of a global function with a corresponding basic function, an analysis and comparison of the information of the global function and the corresponding basic function can be performed. Specifically, whether the parameters of the global function are consistent with the parameters of the basic function is first detected. If they are consistent, whether the first information of the structure of the global function and the second information of the structure of the basic function meet the preset conditions is detected. If the preset conditions are met, it can be determined that there is no risk in the replacement operation, thereby realizing risk screening before replacement. The embodiment of the present invention can screen out the situation where the global function and the corresponding basic function do not match, and when it is determined after screening that the function replacement is unlikely to cause an operation abnormality, the global function and the corresponding basic function are replaced, thereby reducing the probability of operation abnormalities such as call failures caused by mismatches between global functions and basic functions when the application is running in the environment of different versions of basic function libraries, thereby improving the operation stability of the application.
[0051] Figure 2 It is a flowchart of the steps of another application optimization method provided by an embodiment of the present invention. Figure 2 include:
[0052] Step 201, calling a viewing command to obtain a symbol table recording function names.
[0053] Step 202: determine the function with the name type of FUNC and the binding identifier of GLOBAL in the symbol table as the global function.
[0054] In an embodiment of the present invention, for steps 201-202, first, the symbol table recording all the function names of the application can be retrieved through the compiled binary view command, and then the function with the name type of FUNC (FUNC is a generic delegate type used to represent a method with specified parameters and return types) and the binding identifier of GLOBAL (the GLOBAL identifier is used to define a function as a global variable) in the symbol table is determined as a global function of the application.
[0055] Step 203: Obtain the function name of the global function.
[0056] Step 204 , determining the basic functions in the basic function library whose names are consistent with the function names of the global functions as basic functions that match the global functions.
[0057] In the embodiment of the present invention, for steps 203-204, the function name of the function is also recorded in the symbol table, so the function name of the global function can be obtained therefrom, and the basic function in the basic function library whose name is consistent with the function name of the global function is determined as the basic function matching the global function. The basic function in the basic function library whose name is inconsistent with the function name of the global function is ignored.
[0058] For example, the symbol table records the function names of various functions in a list form, and one of the global functions is getaddrinfo(struct addrinfo*). If there is a basic function named getaddrinfo(structaddrinfo*) in the basic function library, then the basic function getaddrinfo(struct addrinfo*) is a function whose name is consistent with the function name of the global function getaddrinfo(struct addrinfo*), and the two match successfully.
[0059] In another implementation, if the global function and the basic function both implement the same function functionality but their function names are inconsistent, it can also be considered that the global function and the basic function match each other.
[0060] Step 205 : when it is detected that the parameters of the global function are consistent with the parameters of the basic function, determine first information of the structure of the global function and second information of the structure of the basic function.
[0061] This step may be specifically referred to as the above step 102, which will not be described in detail here.
[0062] Step 206: When the first information and the second information meet a preset condition, use the global function to replace the basic function.
[0063] This step may be specifically referred to as the above step 103, which will not be described in detail here.
[0064] Optionally, after step 206, the following steps may also be included:
[0065] Step 207: When the application needs to implement a function corresponding to the basic function, call the global function for execution.
[0066] In an embodiment of the present invention, after the basic function is replaced by the global function, the subsequent application can call the global function to implement the corresponding function function instead of calling the basic function. Since the global function is a function specially developed for the application, the matching system resources can be allocated according to the execution characteristics of the application at runtime. Therefore, the execution effect of the replaced function is better.
[0067] In one example, for example, the application implements a global function getaddrinfo(structaddrinfo*), in which sizeof(struct addrinfo) is allocated. The getaddrinfo function is used to implement a service for obtaining an Internet Protocol (IP) address, struct addrinfo* is a parameter pointer, and struct addrinfo is a structure.
[0068] In the basic function library, the basic functions getaddrinfo(struct addrinfo*) and freeaddrinfo(struct addrinfo*) are implemented. Sizeof(struct aibuf) is allocated in getaddrinfo. The freeaddinfo function is used to release the IP address. The struct aibuf structure contains the structaddrinfo structure. The freeaddinfo function uses data other than struct addrinfo in the aibuf structure.
[0069] For the above two functions, it can be seen that the function names of the two functions are the same, both getaddrinfo(structaddrinfo*). However, there are differences in the internal space allocation of the two functions, which are specifically reflected in the allocation and use of structure parameters. Specifically, the capacity of the allocated space of the application's global function getaddrinfo(struct addrinfo*) is used for the struct addrinfo structure, and the capacity of the allocated space of the basic function getaddrinfo(struct addrinfo*) of the basic function library is used for the struct aibuf structure. Since the two structures struct addrinfo and struct aibuf are different, the space capacity allocated by the two functions for their respective structures is also different. In addition, the basic function library also implements a freeaddrinfo function. The freeaddrinfo function will use the parameters of the structaibuf structure except struct addrinfo. If the application does not allocate the correct data when calling the getaddrinfo function, an error will occur when using the members of aibuf in the freeaddrinfo function.
[0070] Based on the analysis of the embodiment of the present invention, the first step is to first determine the basic function getaddrinfo (struct addrinfo *) matching the global function getaddrinfo (struct addrinfo *) from the basic function library of the operating system.
[0071] In the second step, when the function names of the two functions (getaddrinfo(struct addrinfo*)) are consistent, the function parameters of the two functions can be further checked. It can be seen that the function parameters of the two functions are consistent, that is, the function parameters of the two functions are member variables in the same structure struct addrinfo*.
[0072] In the third step, when the function parameters of the two functions are consistent (the function type and structure are consistent), the capacity of the space allocated by the two functions for their respective structures can be compared. It is found that the capacity of the space allocated by the application's global function getaddrinfo(structaddrinfo*) is used for the struct addrinfo structure, and the capacity of the space allocated by the basic function getaddrinfo(struct addrinfo*) of the basic function library is used for the struct aibuf structure. Since the two structures struct addrinfo and struct aibuf are different, the space capacity allocated by the two functions for their respective structures is also different. At this time, a risk reminder can be issued. The risk reminder is used to indicate that there is a risk in using global functions to replace basic functions.
[0073] Optionally, the method may further include:
[0074] Step 208: When it is detected that the parameters of the global function are inconsistent with the parameters of the basic function, stop replacing the basic function with the global function.
[0075] In an embodiment of the present invention, when it is detected that the parameters of the global function are inconsistent with the parameters of the basic function, the replacement of the global function with the basic function is stopped to avoid system crashes caused by incompatibility after the replacement, as well as potential risks such as data access errors.
[0076] Reference Figure 3 , which shows an overall flow chart of an application optimization method, including:
[0077] S1. Get the global functions of the application.
[0078] S2. Find the basic function corresponding to the global function in the basic function library.
[0079] S3. Determine whether the global function and the corresponding basic function have the same name. If not, end.
[0080] If so, execute S4 to determine whether the parameters of the global function and the corresponding basic function are consistent; if not, execute S5 to stop the replacement operation.
[0081] If they are consistent, execute S6 to determine whether the space capacity allocated by the global function for the structure is consistent with the space capacity allocated by the corresponding basic function for the structure; if they are inconsistent, execute S7 to issue a risk warning.
[0082] If they are consistent, execute S8 and perform a replacement operation.
[0083] In summary, in an embodiment of the present invention, before the replacement of a global function with a corresponding basic function, an analysis and comparison of the information of the global function and the corresponding basic function can be performed. Specifically, whether the parameters of the global function are consistent with the parameters of the basic function is first detected. If they are consistent, whether the first information of the structure of the global function and the second information of the structure of the basic function meet the preset conditions is detected. If the preset conditions are met, it can be determined that there is no risk in the replacement operation, thereby realizing risk screening before replacement. The embodiment of the present invention can screen out the situation where the global function and the corresponding basic function do not match, and when it is determined after screening that the function replacement is unlikely to cause an operation abnormality, the global function and the corresponding basic function are replaced, thereby reducing the probability of operation abnormalities such as call failures caused by mismatches between global functions and basic functions when the application is running in the environment of different versions of basic function libraries, thereby improving the operation stability of the application.
[0084] Figure 4 is a block diagram of an application optimization device provided by an embodiment of the present invention, such as Figure 4 As shown, the device comprises:
[0085] The acquisition module 301 is used to acquire the global functions corresponding to the application program, and determine the basic functions matching the global functions from the basic function library of the operating system;
[0086] A structure information module 302, for determining first information of a structure of the global function and second information of a structure of the basic function when it is detected that the parameters of the global function are consistent with the parameters of the basic function;
[0087] The replacement module 303 is used to replace the basic function with the global function when the first information and the second information meet a preset condition, so that when the application executes the basic function, the replaced global function is called for execution.
[0088] Optionally, the acquisition module 301 includes:
[0089] A symbol table submodule, used for calling a viewing command to obtain a symbol table recording the function names of the application program;
[0090] A submodule is determined, which is used to determine the function with a name type of FUNC and a binding identifier of GLOBAL in the symbol table as the global function.
[0091] Optionally, the acquisition module 301 includes:
[0092] Obtain a submodule, used to obtain the function name of the global function;
[0093] The first comparison submodule is used to determine the basic function in the basic function library whose name is consistent with the function name of the global function as the basic function matching the global function.
[0094] Optionally, the first information includes: the capacity of a first allocated space for the structure of the global function; the second information includes: the capacity of a second allocated space for the structure of the basic function;
[0095] The structure information module 302 includes:
[0096] a second comparison submodule, configured to determine, when the capacity of the first allocation space is consistent with the capacity of the second allocation space, whether the first information and the second information meet a preset condition, and replace the basic function with the global function;
[0097] The third comparison submodule is used to issue a risk warning when the capacity of the first allocation space is inconsistent with the capacity of the second allocation space, wherein the risk warning is used to indicate that there is an operational abnormality in replacing the basic function with the global function.
[0098] Optionally, the device further comprises:
[0099] An execution module is used to call the global function for execution when the application needs to implement a function corresponding to the basic function.
[0100] Optionally, the device further comprises:
[0101] The stopping module is used to stop the replacement of the basic function by the global function when it is detected that the parameters of the global function are inconsistent with the parameters of the basic function.
[0102] Optionally, the parameters of the global function and the parameters of the basic function include: one or more of function type and structure member information.
[0103] In summary, in an embodiment of the present invention, before the replacement of a global function with a corresponding basic function, an analysis and comparison of the information of the global function and the corresponding basic function can be performed. Specifically, whether the parameters of the global function are consistent with the parameters of the basic function is first detected. If they are consistent, whether the first information of the structure of the global function and the second information of the structure of the basic function meet the preset conditions is detected. If the preset conditions are met, it can be determined that there is no risk in the replacement operation, thereby realizing risk screening before replacement. The embodiment of the present invention can screen out the situation where the global function and the corresponding basic function do not match, and when it is determined after screening that the function replacement is unlikely to cause an operation abnormality, the global function and the corresponding basic function are replaced, thereby reducing the probability of operation abnormalities such as call failures caused by mismatches between global functions and basic functions when the application is running in the environment of different versions of basic function libraries, thereby improving the operation stability of the application.
[0104] The optimization device of the application in the embodiment of the present invention can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a palm computer, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc. The non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present invention.
[0105] The application optimization device in the embodiment of the present invention may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present invention.
[0106] The application optimization device provided in the embodiment of the present invention can implement each process implemented by the application optimization device in the method embodiment, and will not be described again here to avoid repetition.
[0107] Optionally, an embodiment of the present invention further provides an electronic device, including a processor, a memory, and a program or instruction stored in the memory and executable on the processor. When the program or instruction is executed by the processor, each process of the optimization method embodiment of the above-mentioned application is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0108] It should be noted that the electronic devices in the embodiments of the present invention include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0109] Figure 5 The present invention is a schematic diagram of the hardware structure of an electronic device.
[0110] The electronic device 1300 includes but is not limited to: a radio frequency unit 1301, a network module 1302, an audio output unit 1303, an input unit 1304, a sensor 1305, a display unit 1306, a user input unit 1307, an interface unit 1308, a memory 1309, and a processor 1310 and other components.
[0111] Those skilled in the art will appreciate that the electronic device 1300 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1310 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Figure 5 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0112] It should be understood that in an embodiment of the present invention, the input unit 1304 may include a graphics processor (GPU) 13041 and a microphone 13042, and the graphics processor 13041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1306 may include a display panel 13061, and the display panel 13061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1307 includes a touch panel 13071 and at least one of other input devices 13072. The touch panel 13071 is also called a touch screen. The touch panel 13071 may include two parts: a touch detection device and a touch controller. Other input devices 13072 may include, but are not limited to, a physical keyboard, function keys (such as a volume control button, a switch button, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0113] The memory 1309 can be used to store software programs and various data. The memory 1309 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1309 may include a volatile memory or a non-volatile memory, or the memory 1309 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 1309 in the embodiment of the present invention includes but is not limited to these and any other suitable types of memory.
[0114] The processor 1310 may include one or more processing units; optionally, the processor 1310 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1310.
[0115] An embodiment of the present invention also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the optimization method embodiment of the above-mentioned application are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0116] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A method for optimizing an application, characterized in that: Methods include: Obtaining the global functions corresponding to the application program, and determining basic functions matching the global functions from the basic function library of the operating system; In the case where it is detected that the parameters of the global function are consistent with the parameters of the basic function, determining first information of a structure of the global function and second information of a structure of the basic function; When the first information and the second information meet a preset condition, the basic function is replaced by the global function, so that when the application executes the basic function, the replaced global function is called for execution.
2. The method according to claim 1, characterized in that The global functions included in the acquisition application include: Calling a viewing command to obtain a symbol table recording the function names of the application; The function with the name type of FUNC and the binding identifier of GLOBAL in the symbol table is determined as the global function.
3. The method according to claim 1, characterized in that Determining, from a basic function library, a basic function matching the global function comprises: Get the function name of the global function; A basic function in the basic function library whose name is consistent with the function name of the global function is determined as a basic function matching the global function.
4. The method according to claim 1, characterized in that: The first information includes: the capacity of the first allocation space of the structure of the global function; the second information includes: the capacity of the second allocation space of the structure of the basic function; The step of replacing the basic function with the global function when the first information and the second information meet a preset condition comprises: In a case where the capacity of the first allocation space is consistent with the capacity of the second allocation space, determining that the first information and the second information meet a preset condition, and replacing the basic function with the global function; Otherwise, a risk reminder is issued, wherein the risk reminder is used to indicate that there is an operational abnormality in using the global function to replace the basic function.
5. The method according to claim 1, characterized in that Also includes: When it is detected that the parameters of the global function are inconsistent with the parameters of the basic function, the replacement of the basic function by the global function is stopped.
6. The method according to claim 1 or 5, characterized in that: The parameters include: function type, structure member information or one or more thereof.
7. An application optimization device, characterized in that: include: An acquisition module, used for acquiring the global functions corresponding to the application program, and determining basic functions matching the global functions from the basic function library of the operating system; A structure information module, used for determining first information of a structure of the global function and second information of a structure of the basic function when it is detected that the parameters of the global function are consistent with the parameters of the basic function; A replacement module is used to replace the basic function with the global function when the first information and the second information meet preset conditions, so that when the application executes the basic function, the replaced global function is called for execution.
8. The device according to claim 7, characterized in that The first information includes: the capacity of the first allocation space of the structure of the global function; the second information includes: the capacity of the second allocation space of the structure of the basic function; The structure information module includes: a second comparison submodule, configured to determine, when the capacity of the first allocation space is consistent with the capacity of the second allocation space, whether the first information and the second information meet a preset condition, and replace the basic function with the global function; The third comparison submodule is used to issue a risk warning when the capacity of the first allocation space is inconsistent with the capacity of the second allocation space, wherein the risk warning is used to indicate that there is an operational abnormality in replacing the basic function with the global function.
9. An electronic device, characterized in that: The invention comprises a processor, a memory and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the optimization method of the application program as described in any one of claims 1 to 6.
10. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by a processor, the steps of the optimization method of the application program according to any one of claims 1 to 6 are implemented.