Method, device and equipment for optimizing runtime IOS code and storage medium of runtime IOS code
The exchange of technical statistics and comparison of the objective function execution data of iOS applications through IOS methods, filtering and optimizing functions of different categories, solving the problem of difficulty in code optimization of iOS applications at runtime, and achieving the effect of improving response speed and execution efficiency.
Patent Information
- Application Number
- CN202411523591.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-18
AI Technical Summary
There are difficulties in optimizing codes for iOS applications at runtime. The existing technology cannot effectively optimize targetedly based on the actual operation of the application, resulting in unpredictable optimization results and cannot guarantee the improvement of response speed and execution efficiency.
Through the IOS method exchange technology, the execution data of all objective functions in each life cycle of the view controller is counted and recorded, the threshold data is compared with the preset, the functions of different categories are selected, and the different categories are compared according to the preset optimization strategy. function is code-optimized.
It realizes targeted code optimization at the function level, improves the response speed and execution efficiency of IOS applications, and ensures the predictability and effectiveness of optimization results.
Smart Images

Figure CN119473500A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of R&D and design technology, and is applied to IOS execution code optimization scenarios during program runtime, and in particular to a runtime IOS code optimization method, device, equipment and storage medium thereof. Background Art
[0002] Since the first iOS version was released in 2008, there have been several iOS programming methods, including Delegate, Block, and Responsive. Among them, Block-based asynchronous programming callback is the most widely used asynchronous programming method in iOS. However, this programming method also has many disadvantages, including nested traps, complex error handling, easy to forget to call the completion handler, conditional execution becomes very difficult, it becomes very difficult to return results from independent calls, execution in the wrong thread, thread freeze, jamming, and difficulty in locating multi-threaded crashes.
[0003] Such a large number of programming problems increase the difficulty of optimizing IOS code. The optimization operation when the IOS application is not running is relatively simpler than the optimization operation when it is running. However, if the optimization operation is only performed when the IOS program is not running, there is often a problem of insufficient confidence in the optimization, and it is impossible to perform targeted code optimization based on the actual operation of the IOS application. The optimization results are unpredictable, and there is no guarantee that the response speed and execution efficiency of the IOS application can be improved. Summary of the invention
[0004] The purpose of the embodiments of the present application is to propose a runtime IOS code optimization method, device, equipment and storage medium thereof, so as to realize targeted code optimization in combination with the actual operation of the IOS application and improve the response speed and execution efficiency of the IOS application.
[0005] In order to solve the above technical problems, the embodiment of the present application provides a runtime IOS code optimization method, which adopts the following technical solution:
[0006] A runtime IOS code optimization method comprises the following steps:
[0007] By using the IOS method exchange technology, the execution data corresponding to all target functions in each life cycle of the view controller are counted and recorded, wherein the execution data includes the number of executions, the execution start time and the execution completion time;
[0008] Compare the execution data corresponding to all objective functions with the preset threshold data;
[0009] According to the comparison results, different categories of functions are screened out from all objective functions;
[0010] According to different preset optimization strategies, code optimization is performed on different categories of functions.
[0011] Furthermore, before executing the step of counting and recording the execution data corresponding to all target functions in each life cycle of the view controller through the IOS method exchange technology, the method also includes:
[0012] Obtain a functional code block for recording the number of executions, execution start time, and execution completion time, and set it as a target code block;
[0013] The target code blocks are added one by one to all the target functions to obtain updated target functions corresponding to all the target functions.
[0014] Furthermore, before executing the step of comparing the execution data corresponding to all objective functions respectively with the preset threshold data, the method further includes:
[0015] Step 401, selecting different objective functions from all objective functions in turn as the current function;
[0016] Step 402, performing duration calculation according to the execution start time and execution completion time of each execution of the current function, to obtain the actual execution duration corresponding to each execution of the current function;
[0017] Step 403, performing a cumulative average operation according to the actual execution time corresponding to each execution of the current function and the number of executions corresponding to the current function, to obtain the average execution time corresponding to the current function;
[0018] Step 404, repeatedly executing steps 401 to 403, to obtain the average execution time corresponding to all objective functions.
[0019] Furthermore, the step of comparing the execution data corresponding to all objective functions with preset threshold data includes:
[0020] Compare the execution times corresponding to all objective functions with the preset number threshold;
[0021] The preset number threshold includes a first number threshold and a second number threshold, and the first number threshold is greater than the second number threshold. The step of screening out functions of different categories from all objective functions according to the comparison result includes:
[0022] If the execution count of the current function is greater than the first threshold, the current function belongs to the hot function category;
[0023] If the execution times corresponding to the current function are within a closed number range interval formed by the first number threshold and the second number threshold, the current function belongs to the common function category;
[0024] If the execution times corresponding to the current function are less than the second threshold of times, the current function belongs to the cold spot function category.
[0025] Furthermore, the step of comparing the execution data corresponding to all objective functions with preset threshold data also includes:
[0026] Compare the average execution time corresponding to all objective functions with the preset execution time threshold;
[0027] The step of screening out functions of different categories from all target functions according to the comparison result also includes:
[0028] If the average execution time corresponding to the current function exceeds the execution time threshold, the current function is a function with excessively long execution time;
[0029] If the average execution time corresponding to the current function does not exceed the execution time threshold, the current function belongs to a function with an execution time exceeding the threshold.
[0030] Furthermore, the step of performing code optimization on functions of different categories respectively according to different preset optimization strategies includes:
[0031] Use the preset first optimization strategy to optimize the code of hotspot functions;
[0032] Use the preset second optimization strategy to optimize the code of common functions;
[0033] Use the preset third optimization strategy to optimize the code of the cold spot function;
[0034] Use the preset fourth optimization strategy to optimize the code of functions that take too long to execute;
[0035] Use the preset fifth optimization strategy to optimize the code of functions with long execution time.
[0036] Furthermore, before executing the step of performing code optimization on functions of different categories according to different preset optimization strategies, the method further includes:
[0037] All target functions are preliminarily clustered to obtain hot functions with too long execution time, common functions with too long execution time, cold functions with too long execution time, hot functions with too long execution time, common functions with too long execution time, and cold functions with too long execution time;
[0038] The step of performing code optimization on functions of different categories according to different preset optimization strategies also includes:
[0039] Use the preset first comprehensive optimization strategy to optimize the code of hotspot functions that take too long to execute;
[0040] Use the preset second comprehensive optimization strategy to optimize the code of common functions that take too long to execute;
[0041] Use the preset third comprehensive optimization strategy to optimize the code of cold spot functions with too long execution time;
[0042] Use the preset fourth comprehensive optimization strategy to optimize the code of hotspot functions with long execution time;
[0043] Use the preset fifth comprehensive optimization strategy to optimize the code of common functions with long execution time;
[0044] The preset sixth comprehensive optimization strategy is used to optimize the code of cold spot functions with long execution time.
[0045] In order to solve the above technical problems, the embodiment of the present application also provides a runtime IOS code optimization device, which adopts the following technical solution:
[0046] A runtime IOS code optimization device, comprising:
[0047] An execution data statistics module is used to count and record the execution data corresponding to all target functions in each life cycle of the view controller through the IOS method exchange technology, wherein the execution data includes the number of executions, the execution start time and the execution completion time;
[0048] A data comparison module is used to compare the execution data corresponding to all objective functions with the preset threshold data;
[0049] Function screening module, used to screen out different categories of functions from all target functions based on the comparison results;
[0050] The separate optimization modules are used to optimize the codes of different categories of functions according to different preset optimization strategies.
[0051] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0052] A computer device includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the runtime IOS code optimization method described above when executing the computer-readable instructions.
[0053] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0054] A computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the runtime IOS code optimization method as described above.
[0055] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0056] The runtime IOS code optimization method described in the embodiment of the present application, through IOS method exchange technology, counts and records the execution data corresponding to all target functions in each life cycle of the view controller; compares the execution data corresponding to all target functions with preset threshold data; based on the comparison results, screens out different categories of functions from all target functions; and performs code optimization on different categories of functions according to different preset optimization strategies. The present application identifies the execution data corresponding to all target functions through IOS method interaction technology, compares the execution data corresponding to all target functions with preset threshold data, so as to achieve the purpose of screening out different categories of functions from all target functions, and facilitates the subsequent use of different optimization strategies for code optimization processing of different categories of functions, and realizes targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0058] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0059] Figure 2 is a flowchart of an embodiment of a runtime IOS code optimization method according to the present application;
[0060] Figure 3It is a flowchart of a specific embodiment of adding and introducing a target code block in the runtime IOS code optimization method described in this application;
[0061] Figure 4 It is a flowchart of a specific embodiment of calculating the average execution time corresponding to all target functions in the runtime IOS code optimization method described in this application;
[0062] Figure 5 It is a flowchart of a specific embodiment of classifying all target functions according to the number of executions in the runtime IOS code optimization method described in this application;
[0063] Figure 6 It is a flowchart of a specific embodiment of classifying all target functions according to execution time in the runtime IOS code optimization method described in this application;
[0064] Figure 7 It is a structural diagram of an embodiment of a runtime IOS code optimization device according to the present application;
[0065] Figure 8 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0066] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0067] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0068] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0069] like Figure 1As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0070] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0071] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.
[0072] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .
[0073] It should be noted that the runtime IOS code optimization method provided in the embodiment of the present application is generally executed by a terminal device, and accordingly, the runtime IOS code optimization device is generally arranged in the terminal device.
[0074] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0075] Continue to refer Figure 2 , shows a flow chart of an embodiment of a runtime IOS code optimization method according to the present application. The runtime IOS code optimization method comprises the following steps:
[0076] Step 201 , using the iOS method exchange technology, count and record the execution data corresponding to all target functions in each life cycle of the view controller.
[0077] The execution data includes the number of executions, the execution start time and the execution completion time, and all the target functions, that is, all the implemented functions.
[0078] In this embodiment, the IOS method exchange technology, for example: exchange the pointer of IMP, the pointer of IMP is used to point to the implementation address of the function. Specifically, first obtain the original class and the first function to be exchanged, and obtain the target class and the second function to be exchanged, then obtain the implementation address of the first function and the second function, and finally use the exchange function to exchange.
[0079] In this embodiment, the program running under the IOS system is mainly realized by combining the continuous generation of the view controller in the IOS system. Through the IOS method interaction technology, the total number of life cycles of the view controller can be counted. The life cycle of the view controller includes the initialization and creation of the view controller, loading the view, the view loading is completed, the view is about to be displayed, the view display is completed, the view is about to disappear, the view disappears and the view controller is destroyed, among which:
[0080] Initialization and creation, used to allocate memory for the view controller and perform necessary initialization settings;
[0081] Load view, which is used to create and set the root view of the view controller;
[0082] The view is loaded and used to initialize the view and add subviews, configure interface elements, set data sources and agents, etc.
[0083] The view is about to be displayed, which is used to perform some interface updates and preparations when the view is about to be displayed on the screen, such as loading data, registering notifications, etc., to prepare for the display of the view;
[0084] View display completion is used to perform operations related to user interaction and start animations when the view has been rendered on the screen, such as starting a timer, executing logic processing after page jump, starting page animation, etc. This stage is a critical period to ensure a smooth user experience;
[0085] The view is about to disappear, which is used to save data or perform other cleanup operations when the view is about to be removed from the screen, such as canceling network requests, stopping ongoing animations, saving user input, etc. This is an important part of ensuring data consistency and application stability;
[0086] View disappearance is completed, which is used to release resources and stop no longer needed operations when the view has been removed from the screen, such as releasing memory, stopping timers, etc. This stage helps reduce memory leaks and improve application performance;
[0087] The destruction of the view controller is used to release resources.
[0088] Each execution action in the above life cycle corresponds to at least one target function. For example, initialization and resource release each correspond to only one target function and can only be executed once. However, for example, adding a subview and loading data may involve multiple target functions and multiple executions according to actual business needs.
[0089] Through the IOS method exchange technology, the execution data corresponding to all target functions in each life cycle of the view controller is counted and recorded, so as to facilitate the subsequent execution optimization of the function code in the IOS system according to the execution data corresponding to all target functions.
[0090] Step 202: compare the execution data corresponding to all the objective functions with the preset threshold data.
[0091] Specifically, the execution data is compared with preset threshold data. For example, the execution data includes the number of executions, the execution start time and the execution completion time. The comparison can be performed separately according to the three dimensions of the number of executions, the execution start time and the execution completion time and the threshold data preset for each dimension. Furthermore, assuming that the execution data also includes the execution setting time and the actual execution time of each objective function, the execution delay time of each objective function is calculated according to the execution setting time and the actual execution time. The execution delay time can also be compared with the preset delay time threshold, that is, the execution data corresponding to all objective functions in step 202 are compared with the preset threshold data. The specific comparison method is to compare separately according to the specific data dimensions.
[0092] Step 203: According to the comparison result, functions of different categories are screened out from all the target functions.
[0093] Through step 202 and step 203, the execution data corresponding to all the target functions are compared with the preset threshold data to achieve the purpose of screening out functions of different categories from all the target functions, so as to facilitate the subsequent code optimization processing using different optimization strategies for functions of different categories.
[0094] Step 204: Optimize the codes of functions of different categories according to different preset optimization strategies.
[0095] In this embodiment, the preset different optimization strategies include performing at least one optimization operation on the code, such as branch elimination, loop folding, instruction merging, constant folding, constant propagation, invalid code elimination, integer division optimization, expression simplification, loop fusion, inlining, invariant expression elimination, strength reduction, and loop unrolling.
[0096] In this embodiment, the execution data corresponding to all target functions in each life cycle of the view controller are counted and recorded through the IOS method exchange technology; the execution data corresponding to all target functions are compared with the preset threshold data; according to the comparison results, different categories of functions are screened out from all target functions; according to different preset optimization strategies, different categories of functions are optimized. This application uses the IOS method interaction technology to identify the execution data corresponding to all target functions, and compare the execution data corresponding to all target functions with the preset threshold data, so as to achieve the purpose of screening out different categories of functions from all target functions, so as to facilitate the subsequent code optimization processing of different categories of functions using different optimization strategies, and realize targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0097] Continue to refer Figure 3 In some optional implementations, a step of adding and introducing a target code block is also included before step 201. Figure 3 It is a flowchart of a specific embodiment of adding and introducing a target code block in the runtime IOS code optimization method described in this application, comprising the following steps:
[0098] Step 301, obtaining a functional code block for recording execution times, execution start time and execution completion time, and setting it as a target code block;
[0099] Step 302: Add the target code blocks to all the target functions one by one to obtain updated target functions corresponding to all the target functions.
[0100] By adding the target code blocks to all the target functions one by one, the execution data corresponding to each target function can be fully and accurately recorded when the iOS application is actually running.
[0101] Continue to refer Figure 4 In some optional implementations, before step 202, a step of calculating the average execution time corresponding to all objective functions is also included. Figure 4 It is a flowchart of a specific embodiment of calculating the average execution time corresponding to all target functions in the runtime IOS code optimization method described in this application, including the following steps:
[0102] Step 401, selecting different objective functions from all objective functions in turn as the current function;
[0103] Step 402, performing duration calculation according to the execution start time and execution completion time of each execution of the current function, to obtain the actual execution duration corresponding to each execution of the current function;
[0104] Step 403, performing a cumulative average operation according to the actual execution time corresponding to each execution of the current function and the number of executions corresponding to the current function, to obtain the average execution time corresponding to the current function;
[0105] Step 404, repeatedly executing steps 401 to 403, to obtain the average execution time corresponding to all objective functions.
[0106] By obtaining the average execution time corresponding to all objective functions, it is convenient to optimize and classify all objective functions from the dimension of execution time.
[0107] Continue to refer Figure 5 , Figure 5 It is a flowchart of a specific embodiment of classifying all target functions according to the number of executions in the runtime IOS code optimization method described in this application, comprising the following steps:
[0108] Step 501, comparing the execution times corresponding to all objective functions with a preset times threshold;
[0109] The preset number threshold includes a first number threshold and a second number threshold, and the first number threshold is greater than the second number threshold.
[0110] Step 502: If the execution count of the current function is greater than the first threshold, the current function belongs to the hotspot function category;
[0111] Step 503, if the execution times corresponding to the current function are within the closed number range interval formed by the first number threshold and the second number threshold, then the current function belongs to the common function category;
[0112] Specifically, the closed number range interval, for example: the first number threshold is 300 times, the second number threshold is 100 times, then the number range interval [100, 300] is a closed number range interval, and (100, 300) is a non-closed number range interval, and the closed number range interval includes the first number threshold and the second number threshold.
[0113] Step 504: If the execution times corresponding to the current function are less than the second threshold, the current function belongs to the cold spot function category.
[0114] Continue to refer Figure 6 , Figure 6It is a flowchart of a specific embodiment of classifying all target functions according to execution time in the runtime IOS code optimization method described in this application, comprising the following steps:
[0115] Step 601, comparing the average execution time corresponding to all objective functions with a preset execution time threshold;
[0116] Step 602: If the average execution time corresponding to the current function exceeds the execution time threshold, the current function is a function with excessively long execution time;
[0117] Step 603: If the average execution time corresponding to the current function does not exceed the execution time threshold, the current function is a function with an execution time exceeding the threshold.
[0118] All objective functions are classified through different classification dimensions to achieve code optimization of the objective functions from the perspective of multiple classification dimensions, making the optimization more comprehensive and multi-dimensional.
[0119] In this embodiment, the steps of performing code optimization on functions of different categories according to different preset optimization strategies include: using a preset first optimization strategy to perform code optimization on hot spot functions; using a preset second optimization strategy to perform code optimization on ordinary functions; using a preset third optimization strategy to perform code optimization on cold spot functions; using a preset fourth optimization strategy to perform code optimization on functions with excessively long execution time; and using a preset fifth optimization strategy to perform code optimization on functions with excessively long execution time.
[0120] In this embodiment, before executing the step of performing code optimization on functions of different categories according to different preset optimization strategies, the method also includes: performing preliminary clustering and sorting of all target functions to obtain hot spot functions with excessive execution time, ordinary functions with excessive execution time, cold spot functions with excessive execution time, hot spot functions with excessive execution time, ordinary functions with excessive execution time, and cold spot functions with excessive execution time.
[0121] Correspondingly, the step of performing code optimization on functions of different categories respectively according to different preset optimization strategies also includes: adopting the preset first comprehensive optimization strategy to perform code optimization on hot spot functions with excessive execution time; adopting the preset second comprehensive optimization strategy to perform code optimization on ordinary functions with excessive execution time; adopting the preset third comprehensive optimization strategy to perform code optimization on cold spot functions with excessive execution time; adopting the preset fourth comprehensive optimization strategy to perform code optimization on hot spot functions with excessive execution time; adopting the preset fifth comprehensive optimization strategy to perform code optimization on ordinary functions with excessive execution time; adopting the preset sixth comprehensive optimization strategy to perform code optimization on cold spot functions with excessive execution time.
[0122] Specifically, in this embodiment, a comprehensive optimization strategy is also provided for the reclassified comprehensive function category to achieve full code optimization of the target function, ensure that the optimization is fully combined with the actual runtime execution data, and perform targeted code optimization at the target function level, thereby improving the response speed and execution efficiency of the IOS running program.
[0123] This application uses IOS method exchange technology to count and record the execution data corresponding to all target functions in each life cycle of the view controller; compares the execution data corresponding to all target functions with preset threshold data; based on the comparison results, screens out different categories of functions from all target functions; and optimizes the code of different categories of functions according to different preset optimization strategies. This application uses IOS method interaction technology to identify the execution data corresponding to all target functions, and compares the execution data corresponding to all target functions with preset threshold data, so as to achieve the purpose of screening out different categories of functions from all target functions, which is convenient for the subsequent code optimization processing of different categories of functions using different optimization strategies, and realizes targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0124] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0125] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0126] In the embodiment of the present application, the execution data corresponding to all target functions in each life cycle of the view controller are counted and recorded through the IOS method exchange technology; the execution data corresponding to all target functions are compared with the preset threshold data; according to the comparison results, different categories of functions are screened out from all target functions; according to different preset optimization strategies, different categories of functions are optimized for code. The present application uses the IOS method interaction technology to identify the execution data corresponding to all target functions, and compare the execution data corresponding to all target functions with the preset threshold data, so as to achieve the purpose of screening out different categories of functions from all target functions, so as to facilitate the subsequent code optimization processing of different categories of functions using different optimization strategies, and realize targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0127] Further references Figure 7 , as a response to the above Figure 2 The present application provides an embodiment of a runtime IOS code optimization device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0128] like Figure 7 As shown, the runtime IOS code optimization device 700 described in this embodiment includes: an execution data statistics module 701, a data comparison module 702, a function screening module 703 and a respective optimization module 704. Among them:
[0129] An execution data statistics module 701 is used to count and record the execution data corresponding to all target functions in each life cycle of the view controller through the IOS method exchange technology, wherein the execution data includes the number of executions, the execution start time and the execution completion time;
[0130] The data comparison module 702 is used to compare the execution data corresponding to all the target functions with the preset threshold data;
[0131] A function screening module 703 is used to screen out functions of different categories from all target functions according to the comparison result;
[0132] The separate optimization module 704 is used to perform code optimization on functions of different categories according to different preset optimization strategies.
[0133] This application uses IOS method exchange technology to count and record the execution data corresponding to all target functions in each life cycle of the view controller; compares the execution data corresponding to all target functions with preset threshold data; based on the comparison results, screens out different categories of functions from all target functions; and optimizes the code of different categories of functions according to different preset optimization strategies. This application uses IOS method interaction technology to identify the execution data corresponding to all target functions, and compares the execution data corresponding to all target functions with preset threshold data, so as to achieve the purpose of screening out different categories of functions from all target functions, which is convenient for the subsequent code optimization processing of different categories of functions using different optimization strategies, and realizes targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0134] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0135] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0136] To solve the above technical problems, the present application also provides a computer device. Figure 8 , Figure 8 This is a basic structural block diagram of the computer device in this embodiment.
[0137] The computer device 8 includes a memory 8a, a processor 8b, and a network interface 8c which are interconnected through a system bus. It should be noted that: Figure 8 Only a computer device 8 having a component memory 8a, a processor 8b, and a network interface 8c is shown, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), a digital processor (DSP), an embedded device, etc.
[0138] The computer device may be a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with the user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0139] The memory 8a includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 8a can be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 8a can also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 8a can also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 8a is generally used to store the operating system and various application software installed on the computer device 8, such as a computer-readable instruction of a runtime IOS code optimization method, etc. In addition, the memory 8a can also be used to temporarily store various types of data that have been output or are to be output.
[0140] The processor 8b may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 8b is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 8b is used to run computer-readable instructions or process data stored in the memory 8a, such as computer-readable instructions for running the runtime IOS code optimization method.
[0141] The network interface 8c may include a wireless network interface or a wired network interface. The network interface 8c is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0142] The computer device proposed in this embodiment belongs to the field of research and development design technology, and is applied to the IOS execution code optimization scenario when the program is running. This application uses IOS method exchange technology to count and record the execution data corresponding to all target functions in each life cycle of the view controller; compare the execution data corresponding to all target functions with the preset threshold data; according to the comparison results, filter out different categories of functions from all target functions; according to different preset optimization strategies, perform code optimization on different categories of functions. This application uses IOS method interaction technology to identify the execution data corresponding to all target functions, and compare the execution data corresponding to all target functions with the preset threshold data, so as to achieve the purpose of filtering out different categories of functions from all target functions, which is convenient for the subsequent use of different optimization strategies for code optimization processing of different categories of functions, and realizes targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0143] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by a processor to enable the processor to perform the steps of the runtime IOS code optimization method as described above.
[0144] The computer-readable storage medium proposed in this embodiment belongs to the field of research and development design technology, and is applied to the IOS execution code optimization scenario when the program is running. This application uses IOS method exchange technology to count and record the execution data corresponding to all target functions in each life cycle of the view controller; compare the execution data corresponding to all target functions with the preset threshold data; according to the comparison results, filter out different categories of functions from all target functions; according to different preset optimization strategies, perform code optimization on different categories of functions respectively. This application uses IOS method interaction technology to identify the execution data corresponding to all target functions respectively, and compare the execution data corresponding to all target functions respectively with the preset threshold data, so as to achieve the purpose of filtering out different categories of functions from all target functions, which is convenient for the subsequent use of different optimization strategies for code optimization processing of different categories of functions, and realizes targeted optimization at the function level, thereby improving the response speed and execution efficiency of IOS running programs.
[0145] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0146] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A runtime IOS code optimization method, characterized in that: The steps include: By using the IOS method exchange technology, the execution data corresponding to all target functions in each life cycle of the view controller are counted and recorded, wherein the execution data includes the number of executions, the execution start time and the execution completion time; Compare the execution data corresponding to all objective functions with the preset threshold data; According to the comparison results, different categories of functions are screened out from all objective functions; According to different preset optimization strategies, code optimization is performed on different categories of functions.
2. The runtime IOS code optimization method according to claim 1, characterized in that: Before executing the step of counting and recording the execution data corresponding to all target functions in each life cycle of the view controller by using the IOS method exchange technology, the method further includes: Obtain a functional code block for recording the number of executions, execution start time, and execution completion time, and set it as a target code block; The target code blocks are added one by one to all the target functions to obtain updated target functions corresponding to all the target functions.
3. The runtime IOS code optimization method according to claim 1, characterized in that: Before performing the step of comparing the execution data corresponding to all objective functions respectively with the preset threshold data, the method further includes: Step 401, selecting different objective functions from all objective functions in turn as the current function; Step 402, performing duration calculation according to the execution start time and execution completion time of each execution of the current function, to obtain the actual execution duration corresponding to each execution of the current function; Step 403, performing a cumulative average operation according to the actual execution time corresponding to each execution of the current function and the number of executions corresponding to the current function, to obtain the average execution time corresponding to the current function; Step 404, repeatedly executing steps 401 to 403, to obtain the average execution time corresponding to all objective functions.
4. The runtime IOS code optimization method according to claim 1 or 3, characterized in that: The step of comparing the execution data corresponding to all objective functions respectively with preset threshold data includes: Compare the execution times corresponding to all objective functions with the preset number threshold; The preset number threshold includes a first number threshold and a second number threshold, and the first number threshold is greater than the second number threshold. The step of screening out functions of different categories from all objective functions according to the comparison result includes: If the execution count of the current function is greater than the first threshold, the current function belongs to the hot function category; If the execution times corresponding to the current function are within a closed number range interval formed by the first number threshold and the second number threshold, the current function belongs to the common function category; If the execution times corresponding to the current function are less than the second threshold of times, the current function belongs to the cold spot function category.
5. The runtime IOS code optimization method according to claim 3, characterized in that: The step of comparing the execution data corresponding to all objective functions respectively with the preset threshold data also includes: Compare the average execution time corresponding to all objective functions with the preset execution time threshold; The step of screening out functions of different categories from all target functions according to the comparison result also includes: If the average execution time corresponding to the current function exceeds the execution time threshold, the current function is a function with excessively long execution time; If the average execution time corresponding to the current function does not exceed the execution time threshold, the current function belongs to a function with an execution time exceeding the threshold.
6. The runtime IOS code optimization method according to claim 1, characterized in that: The step of performing code optimization on functions of different categories respectively according to different preset optimization strategies includes: Use the preset first optimization strategy to optimize the code of hotspot functions; Use the preset second optimization strategy to optimize the code of common functions; Use the preset third optimization strategy to optimize the code of the cold spot function; Use the preset fourth optimization strategy to optimize the code of functions that take too long to execute; Use the preset fifth optimization strategy to optimize the code of functions with long execution time.
7. The runtime IOS code optimization method according to claim 1, characterized in that: Before executing the step of respectively optimizing the codes of functions of different categories according to different preset optimization strategies, the method further includes: All target functions are preliminarily clustered to obtain hot functions with too long execution time, common functions with too long execution time, cold functions with too long execution time, hot functions with too long execution time, common functions with too long execution time, and cold functions with too long execution time; The step of performing code optimization on functions of different categories according to different preset optimization strategies also includes: Use the preset first comprehensive optimization strategy to optimize the code of hotspot functions that take too long to execute; Use the preset second comprehensive optimization strategy to optimize the code of common functions that take too long to execute; Use the preset third comprehensive optimization strategy to optimize the code of cold spot functions with too long execution time; Use the preset fourth comprehensive optimization strategy to optimize the code of hotspot functions with long execution time; Use the preset fifth comprehensive optimization strategy to optimize the code of common functions with long execution time; The preset sixth comprehensive optimization strategy is used to optimize the code of cold spot functions with long execution time.
8. A runtime IOS code optimization device, characterized in that: include: An execution data statistics module is used to count and record the execution data corresponding to all target functions in each life cycle of the view controller through the IOS method exchange technology, wherein the execution data includes the number of executions, the execution start time and the execution completion time; A data comparison module is used to compare the execution data corresponding to all objective functions with the preset threshold data; Function screening module, used to screen out different categories of functions from all target functions based on the comparison results; The separate optimization modules are used to optimize the codes of different categories of functions according to different preset optimization strategies.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the runtime IOS code optimization method as described in any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the runtime IOS code optimization method according to any one of claims 1 to 7.