Optimization method and device of log module Trace_Log in web page rendering engine
By setting the Trace_Log module to an empty class and function in the source code of the Blink web rendering engine, its calls were optimized, which solved the problem of excessive resource consumption, reduced library size and memory usage, and saved CPU time.
Patent Information
- Application Number
- CN202111213521.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-19
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-10-19
AI Technical Summary
Existing web page rendering engines consume a lot of resources, especially in embedded devices, which increases library size, memory usage, and CPU time.
By setting the classes and functions of the Trace_Log module to empty in the source code of the web rendering engine Blink, the calls to the Trace_Log module are optimized after compilation. This includes steps such as modifying macro definitions, disabling startup, deleting source files, and simulating perftto library calls, thereby reducing the dependency on Trace_Log.
The library size has been reduced, memory usage and CPU time have been decreased, and resource utilization has been optimized, especially in embedded devices.
Smart Images

Figure CN114003834B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of web page rendering, and in particular to an optimization method and device for a log module Trace_Log in a web page rendering engine. Background Art
[0002] Blink is an open source web rendering engine, equivalent to a software operating platform. It needs to be able to correctly render and display various existing web pages, and be able to provide assistance to developers in the process of developing new web pages. Therefore, Blink has a set of Trace_Log log modules that can track the running status of Blink, so that it can monitor the current web page status and help developers correctly run and optimize the web page.
[0003] The working principle of the Trace_Log log module is to mark all the key nodes of Blink's running status in the source code, especially the key nodes that can indicate the running status of the program, and insert a piece of code commonly known as tracing points. This piece of code can record the running status of the program, especially whether the program has errors, and can output the usage in different ways when needed. Because a piece of code is inserted into the source code, it will be compiled into the library, which will increase the size of the library, and at the same time increase memory usage and CPU time when the program is running. Summary of the invention
[0004] The main purpose of the present invention is to provide a method and device for optimizing a log module Trace_Log in a web page rendering engine, so as to solve the problem of excessive resource occupation of the web page rendering engine in the prior art.
[0005] To achieve the above objective, according to one aspect of the present invention, there is provided a method for optimizing a log module Trace_Log in a web page rendering engine, comprising: obtaining source code of a web page rendering engine Blink, wherein the source code of the web page rendering engine includes a log module Trace_Log, a class in the log module called by the source code of the web page rendering engine is set to an empty class, and a function in the log module called by the source code of the web page rendering engine is set to an empty function; and compiling the source code of the web page rendering engine to obtain the web page rendering engine used in an embedded device.
[0006] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: modifying the macro definition in the source code of the web page rendering engine to an empty call, so that the key node marking the running status in the web page rendering engine calls the empty Trace_Log function.
[0007] Optionally, before obtaining the source code of the web page rendering engine Blink, the method also includes: turning off the startup of the log module Trace_Log: modifying the StartupTracingController class so that the log module Trace_Log is not started when the StartupTracingController class is initialized or called, and modifying the services related to the log module Trace_Log so that it is not started when the page rendering engine Blink is initialized.
[0008] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: deleting an unused source file of a log module Trace_Log in the source code of the web page rendering engine Blink.
[0009] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: modifying a specific class in the log module Trace_Log to an empty class, so that when the web page rendering engine Blink uses the specific class in the log module Trace_Log, an empty function is called.
[0010] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: simulating the call of the web page rendering engine Blink to the class in the perftto library, and deleting the call of the web page rendering engine Blink to the class in the perftto library, wherein the class of the simulated call is an empty class.
[0011] Optionally, deleting the call of the web page rendering engine Blink to the class in the perftto library includes: modifying the template file of mojo to delete the call to the perftto library.
[0012] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: modifying the service registration process of Blink and deleting calls related to the resource_coordinator service.
[0013] Optionally, before obtaining the source code of the web page rendering engine Blink, the method further includes: modifying the tracking log output function in Blink so that it does not call the log module Trace_Log.
[0014] To achieve the above-mentioned purpose, according to one aspect of the present invention, there is provided an optimization device for a log module Trace_Log in a web page rendering engine, comprising: an acquisition unit, used to acquire the source code of the web page rendering engine Blink, wherein the source code of the web page rendering engine includes the log module Trace_Log, the class called by the source code of the web page rendering engine in the log module is set to an empty class, and the function called by the source code of the web page rendering engine in the log module is set to an empty function; and a compilation unit, used to compile the source code of the web page rendering engine to obtain the web page rendering engine used in an embedded device.
[0015] Optionally, the device of the present application may also include: an optimization unit, which is used to modify the macro definition in the source code of the web page rendering engine Blink to an empty call before obtaining the source code of the web page rendering engine, so that the key node marking the running status in the web page rendering engine calls the empty Trace_Log function.
[0016] Optionally, the optimization unit is also used to turn off the startup of the log module Trace_Log before obtaining the source code of the web page rendering engine Blink: modify the StartupTracingController class so that the log module Trace_Log is not started when the StartupTracingController class is initialized or called, and modify the services related to the log module Trace_Log so that they are not started when the page rendering engine Blink is initialized.
[0017] Optionally, the optimization unit is further configured to delete an unused source file of the log module Trace_Log from the source code of the web page rendering engine Blink before obtaining the source code of the web page rendering engine Blink.
[0018] Optionally, the optimization unit is further used to modify the unique class in the log module Trace_Log to an empty class before obtaining the source code of the web page rendering engine Blink, so that the web page rendering engine Blink calls an empty function when using the unique class in the log module Trace_Log.
[0019] Optionally, the optimization unit is also used to simulate the call of the web rendering engine Blink to the class in the perftto library before obtaining the source code of the web rendering engine Blink, and delete the call of the web rendering engine Blink to the class in the perftto library, wherein the class simulated calling is an empty class.
[0020] Optionally, the optimization unit is also used to modify the template file of the mojo to delete the call to the perftto library.
[0021] Optionally, the optimization unit is further used to modify the service registration process of Blink before obtaining the source code of the web page rendering engine Blink, and delete calls related to the resource_coordinator service.
[0022] By applying the technical solution of the present invention, the source code of the web page rendering engine Blink is obtained, wherein the source code of the web page rendering engine includes a log module Trace_Log, and the class called by the source code of the web page rendering engine in the log module is set to an empty class, and the function called by the source code of the web page rendering engine in the log module is set to an empty function; the source code of the web page rendering engine is compiled to obtain the web page rendering engine used in an embedded device, and the modified empty class or empty function will be optimized by the compiler during the compilation and linking process of Blink, so that there will be no call to the Trace_Log log module in the generated library, so after optimization, the purpose of reducing the library size, reducing memory usage, and saving CPU time can be achieved, thereby solving the problem of more resource usage of the web page rendering engine in the prior art.
[0023] In addition to the above-described purposes, features and advantages, the present invention has other purposes, features and advantages. The present invention will be further described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:
[0025] Figure 1 It is a flowchart of an optional optimization method of a log module Trace_Log in a web page rendering engine according to an embodiment of the present application;
[0026] Figure 2 is a schematic diagram of an optional workflow of a log module according to an embodiment of the present application;
[0027] Figure 3 is a schematic diagram of an optional workflow of a log module according to an embodiment of the present application; and,
[0028] Figure 4 It is a schematic diagram of an optional optimization device of a log module Trace_Log in a web page rendering engine according to an embodiment of the present application. DETAILED DESCRIPTION
[0029] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0030] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the present invention described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0033] According to one aspect of the embodiments of the present application, a method embodiment of a method for optimizing a log module Trace_Log in a web page rendering engine is provided. Figure 1 is a flowchart of an optional optimization method of the log module Trace_Log in the web page rendering engine according to an embodiment of the present application, such as Figure 1 As shown, the method may include the following steps:
[0034] Step S101, obtaining the source code of the web page rendering engine Blink, the source code of the web page rendering engine includes a log module Trace_Log, the class in the log module called by the source code of the web page rendering engine is set to an empty class, and the function in the log module called by the source code of the web page rendering engine is set to an empty function;
[0035] Step S102, compile the source code of the web page rendering engine to obtain the web page rendering engine used in the embedded device.
[0036] By applying the technical solution of the present invention, the source code of the web page rendering engine Blink is obtained, wherein the source code of the web page rendering engine includes a log module Trace_Log, the class called by the source code of the web page rendering engine in the log module is set to an empty class, and the function called by the source code of the web page rendering engine in the log module is set to an empty function; the source code of the web page rendering engine is compiled to obtain the web page rendering engine used in the embedded device, and the modified empty class or empty function will be optimized by the compiler during the compilation and linking process of Blink, so that there will be no call to the Trace_Log log module in the generated library, so after optimization, the purpose of reducing the library size, reducing memory usage, and saving CPU time can be achieved, thereby solving the problem of more resource usage of the web page rendering engine in the prior art.
[0037] The working process of the Trace_Log log module is as follows: Figure 2 As shown in the figure, the second part from the left is the macro definition in the Trace_Log log module. Because there are a large number of key nodes in Blink that need to mark the running status of Blink, there are a large number of places where macro definitions are called in the source code. If the macro definition is deleted, many places need to be modified, and the existing modifications cannot be reused during future upgrades and merges, so as to reduce a large number of modifications. Figure 2 The third and fourth parts are the main implementation parts of the Trace_Log log module, which also occupy the library size after compilation, the memory size and CPU time at runtime. In other words, not calling this part can achieve the purpose of reducing the library size, reducing memory usage and saving CPU time.
[0038] However, on embedded platforms with limited system resources, such as set-top boxes or TVs, the Trace_Log module increases the library size, occupies Flash space, and increases runtime resources, taking up memory space and CPU time. At the same time, the embedded platform only renders and displays some specific web pages, and does not need to monitor the status of the web pages. In addition, web pages can be developed on non-embedded platforms, and there is no need to track the operation of web pages. Therefore, Blink can be customized and optimized and ported to embedded platforms, and its Trace_Log module can be optimized to the minimum. The process of the optimized Trace_Log module is as follows: Figure 3 As shown:
[0039] Figure 3 The middle part is the modified macro definition, etc., and the right part is the empty function or empty class added to the Trace_Log log module. After the modification, the empty class or empty function will be optimized by the compiler during the compilation and linking process of Blink. In this way, there will be no call to the Trace_Log log module in the generated library. Therefore, after optimization, the purpose of reducing the library size, reducing memory usage, and saving CPU time can be achieved.
[0040] In order to fully track the status of web pages, Blink needs to add Trace_Log functions in a large number of places. In addition, the Trace_Log function can have different parameters according to different scenarios. Therefore, Blink uses some macro definitions to handle different scenarios. Therefore, the first step is to modify these macro definitions to call empty Trace_Log functions. Empty functions can reduce the size of the library, the size of the runtime memory, and the CPU time. For example, the original macro definition inserts a code that defines variables and calls the interface of the Trace_Log log module. After modifying it to an empty function macro definition, these operations can be directly reduced.
[0041] There are more than ten macro definition modifications in this way, and the modifications are made in the base and v8 modules. Base is the basic library of Blink, and v8 has its own Trace macro definition, so both need to be modified. After the modification, the call to the Trace_Log log module can be greatly reduced, but the Trace_Log log module will still be started, although not many logs are recorded. Therefore, the second step is to modify the startup class and service of the Trace_Log log module so that it does not start the Trace_Log log module. First, modify the StartupTracingController class so that it does not start the Trace_Log log module when initialized or called, and then modify the services related to the Trace_Log log module so that it is not started when Blink is initialized.
[0042] Although the startup of the Trace_Log logging module is turned off, most of the source code in the logging module is still compiled into the Blink library. Therefore, in the third step, you need to delete the unused Trace_Log logging module source files in the Blink compilation file, such as trace_buffer, trace_config, trace_event_filter, etc.
[0043] After Blink does not compile most of the source files of the Trace_Log logging module, because Trace_Log calls exist in large numbers throughout the Blink source code, and many parameters when calling macro definitions are classes unique to the Trace_Log logging module, such as ConvertableToTraceFormat and its subclass TracedValue. Therefore, the fourth step is to modify the classes unique to the Trace_Log logging module to empty classes. After this modification, when the classes unique to the Trace_Log logging module are used in Blink, empty functions will be called and they will be optimized during compilation, thus reducing the library size and reducing memory usage and CPU time at runtime.
[0044] When calling the Trace_Log logging module, Blink not only uses the classes unique to the Trace_Log logging module, but also uses the classes in the perftto library. Therefore, the fifth step simulates the classes in the perftto library to be empty and deletes the calls to the perftto library, such as the simulated classes in the perftto library.
[0045] There are many places to modify the perftto library calls, among which the mojo module in Blink is the most complicated. Therefore, the sixth step is to modify the mojo template file and delete all the perftto library calls. For example, delete the interface that calls the perftto library in the mojo class definition template wrapper_class_definition.tmpl.
[0046] This has modified most of Blink's dependencies on the Trace_Log logging module, but the resource_coordinator service in Blink is deeply dependent on the Trace_Log logging module. Therefore, in the seventh step, modify Bblink's service registration process and delete calls related to the resource_coordinator service.
[0047] Some modules in Blink also print trace logs to the Trace_Log log module, such as angle, v8, net, skia, etc. Therefore, the eighth step is to modify the trace log output function of these modules in Blink so that they do not call the Trace_Log log module.
[0048] Through the above eight steps of source code processing, Blink can optimize the Trace_Log log module to be very small, which can reduce the library size, reduce the memory usage at runtime, and also save CPU time.
[0049] The present invention reduces the library size by about 1M, reduces the memory usage during runtime, especially the stack memory, and also saves CPU time.
[0050] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0051] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment 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 this 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, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0052] According to another aspect of the embodiments of the present application, a device for implementing the above method is also provided. Figure 4 is a schematic diagram of an optional optimization device for a log module Trace_Log in a web page rendering engine according to an embodiment of the present application, such as Figure 4 As shown, the device may include:
[0053] The acquisition unit 41 is used to acquire the source code of the web page rendering engine Blink, wherein the source code of the web page rendering engine includes a log module Trace_Log, and the class called by the source code of the web page rendering engine in the log module is set to an empty class, and the function called by the source code of the web page rendering engine in the log module is set to an empty function;
[0054] The compiling unit 42 is used to compile the source code of the web page rendering engine to obtain the web page rendering engine used in the embedded device.
[0055] Optionally, the device of the present application may also include: an optimization unit, which is used to modify the macro definition in the source code of the web page rendering engine Blink to an empty call before obtaining the source code of the web page rendering engine Blink, so that the key node marking the running status in the web page rendering engine calls the empty Trace_Log function.
[0056] Optionally, the optimization unit is also used to turn off the startup of the log module Trace_Log before obtaining the source code of the web page rendering engine Blink: modify the StartupTracingController class so that the log module Trace_Log is not started when the StartupTracingController class is initialized or called, and modify the services related to the log module Trace_Log so that they are not started when the page rendering engine Blink is initialized.
[0057] Optionally, the optimization unit is further configured to delete an unused source file of the log module Trace_Log from the source code of the web page rendering engine Blink before obtaining the source code of the web page rendering engine Blink.
[0058] Optionally, the optimization unit is further used to modify the unique class in the log module Trace_Log to an empty class before obtaining the source code of the web page rendering engine Blink, so that the web page rendering engine Blink calls an empty function when using the unique class in the log module Trace_Log.
[0059] Optionally, the optimization unit is further used to simulate the call of the web rendering engine Blink to the class in the perftto library and delete the call of the web rendering engine Blink to the class in the perftto library before obtaining the source code of the web rendering engine Blink, wherein the class of the simulated call is an empty class.
[0060] Optionally, the optimization unit is also used to modify the template file of the mojo to delete the call to the perftto library.
[0061] Optionally, the optimization unit is further used to modify the service registration process of Blink before obtaining the source code of the web page rendering engine Blink, and delete calls related to the resource_coordinator service.
[0062] Unless otherwise specifically stated, the relative arrangement of the parts and steps described in these embodiments, numerical expressions and numerical values do not limit the scope of the present invention. At the same time, it should be understood that, for ease of description, the sizes of the various parts shown in the accompanying drawings are not drawn according to the actual proportional relationship. The technology, method and equipment known to ordinary technicians in the relevant field may not be discussed in detail, but in appropriate cases, the technology, method and equipment should be regarded as a part of the authorization specification. In all examples shown and discussed here, any specific value should be interpreted as being merely exemplary, rather than as a limitation. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once a certain item is defined in an accompanying drawing, it does not need to be further discussed in subsequent drawings.
[0063] For ease of description, spatially relative terms such as "above", "above", "on the upper surface of", "above", etc. may be used here to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" can include both "above" and "below". The device can also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatially relative descriptions used here are interpreted accordingly.
[0064] In the description of the present invention, it is necessary to understand that the directions or positional relationships indicated by directional words such as "front, back, up, down, left, right", "lateral, vertical, perpendicular, horizontal" and "top, bottom" are usually based on the directions or positional relationships shown in the drawings. They are only for the convenience of describing the present invention and simplifying the description. Unless otherwise specified, these directional words do not indicate or imply that the devices or elements referred to must have a specific direction or be constructed and operated in a specific direction. Therefore, they cannot be understood as limiting the scope of protection of the present invention. The directional words "inside and outside" refer to the inside and outside relative to the contours of each component itself.
[0065] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for optimizing the log module Trace_Log in a web page rendering engine, characterized in that: include: Obtaining source code of a web page rendering engine Blink, wherein the source code of the web page rendering engine Blink includes a log module Trace_Log, a class in the log module called by the source code of the web page rendering engine Blink is set to an empty class, and a function in the log module called by the source code of the web page rendering engine Blink is set to an empty function; Compile the source code of the web page rendering engine Blink to obtain the web page rendering engine Blink used in the embedded device; Before obtaining the source code of the web page rendering engine Blink, the method further includes: Modify the macro definition in the source code of the web page rendering engine Blink to an empty call, so that the key node marking the running state in the web page rendering engine Blink calls the empty Trace_Log function; Disable the startup of the log module Trace_Log: modify the StartupTracingController class so that the log module Trace_Log is not started when the StartupTracingController class is initialized or called, and modify the services related to the log module Trace_Log so that they are not started when the web rendering engine Blink is initialized; Delete the unused source file of the log module Trace_Log in the source code of the web rendering engine Blink; Modify the unique class in the log module Trace_Log to an empty class, so that when the web page rendering engine Blink uses the unique class in the log module Trace_Log, an empty function is called; Simulate the call of the web page rendering engine Blink to the class in the perftto library, and delete the call of the web page rendering engine Blink to the class in the perftto library, wherein the class simulated to be called is an empty class; Delete the call of the web page rendering engine Blink to the class in the perftto library, including: Modify the mojo template file and delete the call to the perftto library.
2. The method according to claim 1, characterized in that Before obtaining the source code of the web page rendering engine Blink, the method further includes: Modify the service registration process of the web rendering engine Blink and delete the calls related to the resource_coordinator service.
3. The method according to claim 1, characterized in that Before obtaining the source code of the web page rendering engine Blink, the method further includes: Modify the trace log output function in the web rendering engine Blink so that it does not call the log module Trace_Log.
4. An optimization device for a log module Trace_Log in a web page rendering engine, characterized in that: The method according to claim 1, comprising: an acquisition unit, configured to acquire source code of a web page rendering engine Blink, wherein the source code of the web page rendering engine Blink includes a log module Trace_Log, a class in the log module called by the source code of the web page rendering engine Blink is set to an empty class, and a function in the log module called by the source code of the web page rendering engine Blink is set to an empty function; The compiling unit is used to compile the source code of the web page rendering engine Blink to obtain the web page rendering engine Blink used in the embedded device.
Citation Information
Patent Citations
Improving web sites performance using edge servers in fog computing architecture
CN104798071A
Python-based R.java file optimization method and system
CN106648638A
Method and device for shielding SDK dangerous call
CN109032687A
Code compiling method and device, computer device and storage medium
CN109828759A
Instruction optimization method and device
CN112905180A
