Component display method and related device
Drawing components and displaying interactive components on an off-screen canvas through a multi-thread mechanism solves the problems of main thread blocking and insufficient interactivity in the existing technology, achieving efficient component interaction and improving user experience.
Patent Information
- Application Number
- CN202410696833.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-13
AI Technical Summary
In the existing technology, drawing components through the canvas causes the main thread to be blocked, and the diversity and scalability of component interactions are low.
Using a multi-thread mechanism, the first thread and the second thread are used to perform tasks respectively. The second thread draws components based on the off-screen canvas, determines the page coordinate position of the interactive operation through the first thread, and displays the interactive components through the auxiliary document object model node. Avoid main thread blocking and improve interaction diversity and scalability.
It effectively avoids main thread blocking, improves the diversity and scalability of component interactions, shortens component loading time, and improves user experience.
Smart Images

Figure CN118642799A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a display method of a component and a related device. Background Art
[0002] Components are the most basic elements in a page. For example, a component can be a button, input box, drop-down selection, etc. The combination of components will also become a more complex component. Therefore, the page can interact with the user based on components.
[0003] In the related art, components can be drawn in a canvas by operating a canvas object, thereby generating component images in real time in a page, and interactive operations and redrawing can be achieved through a large amount of calculations.
[0004] However, this method will bring a lot of computational overhead, which will cause the main thread to block. Moreover, Canvas drawing operations are usually implemented through JavaScript code, such as drawing shapes, filling colors, applying gradients and textures, etc., which leads to low diversity and scalability of component interactions. Summary of the invention
[0005] In order to solve the above technical problems, the present application provides a component display method and related devices, which are used to improve the diversity and scalability of component interaction while avoiding blocking of the main thread.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] In one aspect, an embodiment of the present application provides a component display method, the method being applied to a device running a first thread and a second thread, the first thread and the second thread being different threads, the second thread being used to perform a task without interfering with the first thread, the method comprising:
[0008] In response to obtaining a first interaction operation for a user component, determining, through the first thread, a page coordinate position corresponding to the first interaction operation, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread;
[0009] Determine, by the second thread, from the user component, a target page area corresponding to the page coordinate position, wherein the target page area is one of the multiple page areas corresponding to the user component;
[0010] The auxiliary document object model node is moved to the target page area through the first thread, and the interactive component corresponding to the first interactive operation is displayed through the auxiliary document object model node. The auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
[0011] On the other hand, an embodiment of the present application provides a display device of a component, the device is built in a device running a first thread and a second thread, the first thread and the second thread are different threads, the second thread is used to perform a task without interfering with the first thread, the device includes: a page coordinate position determination unit, a target page area determination unit and an interactive component display unit;
[0012] The page coordinate position determining unit is configured to determine, in response to obtaining a first interactive operation for a user component, a page coordinate position corresponding to the first interactive operation through the first thread, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread;
[0013] The target page area determination unit is used to determine, through the second thread, a target page area corresponding to the page coordinate position from the user component, wherein the target page area is one of the multiple page areas corresponding to the user component;
[0014] The interactive component display unit is used to move the auxiliary document object model node to the target page area through the first thread, and display the interactive component corresponding to the first interactive operation through the auxiliary document object model node, the auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
[0015] On the other hand, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0016] The memory is used to store a computer program and transmit the computer program to the processor;
[0017] The processor is configured to execute the method described in the above aspects according to the instructions in the computer program.
[0018] On the other hand, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method described in the above aspects.
[0019] On the other hand, an embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method described in the above aspects.
[0020] It can be seen from the above technical solution that the display of components is no longer realized based on the main thread (or a single thread), but through multiple threads. Taking the first thread and the second thread as an example, the second thread can perform tasks without interfering with the first thread. Specifically, the user component is obtained by drawing the second thread based on the off-screen canvas, and in response to obtaining the first interactive operation for the user component, the page coordinate position corresponding to the first interactive operation is determined by the first thread. Through the second thread, according to the page coordinate position, from the multiple page areas corresponding to the user component, the target page area corresponding to the first interactive operation is determined. Through the first thread, the pre-established auxiliary document object model node is moved to the target page area, and the auxiliary document object model node is located in the upper layer of the off-screen canvas, so that the auxiliary document object model node can cover the content of the off-screen canvas located in the lower layer, and then the interactive component corresponding to the first interactive operation is displayed through the auxiliary document object model node, that is, the interaction with the document object model node is simulated on the off-screen canvas through the auxiliary document object model node.
[0021] Therefore, compared with redrawing user components and interactive components based on the canvas, it is more convenient to display interactive components through auxiliary document object model nodes, and document object model nodes include multiple types of interactive components, thereby improving the diversity and scalability of component interactions. Moreover, combined with the off-screen canvas, different tasks are performed by multiple threads respectively, which reduces the computing overhead of a single thread and avoids blocking the main thread. In addition, the off-screen canvas is decoupled from the first thread, that is, the off-screen canvas can be operated in the second thread, which reduces the amount of data transmitted between the first thread and the second thread, shortens the loading time of components, and improves the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 A display effect diagram of a user component in a tree structure provided in an embodiment of the present application;
[0024] Figure 2 A schematic diagram of an application scenario of a display method of a component provided in an embodiment of the present application;
[0025] Figure 3 A schematic diagram of a flow chart of a display method of a component provided in an embodiment of the present application;
[0026] Figure 4 An architectural diagram of a display method of a component provided in an embodiment of the present application;
[0027] Figure 5 A schematic diagram of a multi-threaded communication provided in an embodiment of the present application;
[0028] Figure 6 A schematic diagram of an application scenario of a component provided in an embodiment of the present application;
[0029] Figure 7 A schematic diagram of a loading time comparison provided in an embodiment of the present application;
[0030] Figure 8 A schematic diagram of memory comparison provided in an embodiment of the present application;
[0031] Fig. 9 A schematic diagram of thread overhead comparison provided in an embodiment of the present application;
[0032] Fig.10 A schematic diagram of the structure of a display device of a component provided in an embodiment of the present application;
[0033] Fig.11 A schematic diagram of the structure of a server provided in an embodiment of the present application;
[0034] Fig.12 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] The embodiments of the present application are described below in conjunction with the accompanying drawings.
[0036] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application 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 data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "corresponding to" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0037] In the related art, in order to deal with the problem of diversity of component interaction and low scalability caused by drawing components on canvas, the display of components can also be achieved by combining Document Object Model (DOM) nodes. Specifically, in the page, data is rendered as DOM nodes, and the component form is achieved by combining DOM nodes, such as combining multiple DOM nodes to obtain a tree structure for display, and finally converting the DOM nodes into pixels to achieve the display of components.
[0038] See also Figure 1 , which is a display effect diagram of a tree-structured user component provided by an embodiment of the present application. The tree-structured user component can display hierarchical information through a clear hierarchical structure, which is convenient for users to find corresponding nodes step by step according to the relationship between data. Its component structure can be expanded or collapsed, and can also provide interactive capabilities such as checking. Since there are many styles of DOM nodes, the diversity and scalability of component interaction can be improved.
[0039] However, as the amount of data increases, the number of DOM nodes increases. After each interaction with the user, such as user clicks, deletion of user controls, etc., the current page will recalculate all DOM nodes, which will not only consume a lot of loading time, but also use a large memory overhead to store DOM nodes, resulting in loading or scrolling jams, white screens, or even page freezes.
[0040] That is to say, no matter whether the method of combining DOM nodes or the method of drawing components through canvas is adopted, there are certain defects.
[0041] Based on this, an embodiment of the present application provides a component display method and related devices. After the user component is drawn through an off-screen canvas, when the user interacts with the user component, the pre-established auxiliary DOM node is moved to the target page area corresponding to the page coordinate position. The auxiliary DOM node is located in the upper layer of the off-screen canvas, so that the auxiliary DOM node can cover the content of the off-screen canvas located in the lower layer, and then the interactive component corresponding to this interaction is displayed through the auxiliary DOM node. That is, the interaction with the document object model node is simulated on the off-screen canvas through the auxiliary DOM node, so that the interactive component is displayed through the auxiliary DOM node, which can improve the diversity and scalability of component interaction.
[0042] In addition, with the off-screen canvas, different tasks are performed by multiple threads, which reduces the computing overhead of a single thread and avoids blocking the main thread. Moreover, the off-screen canvas is decoupled from the first thread, that is, the off-screen canvas can be operated on the second thread, which reduces the amount of data transmitted between the first thread and the second thread, shortens the loading time of components, and improves the user experience.
[0043] The display method of the components provided in this application can be applied to various fields, including but not limited to network media, e-commerce, online education, game development and design, software development, etc. Taking the network media field as an example, four application scenarios of the display method of the components provided in this application are described below.
[0044] Scenario 1: Content classification and navigation.
[0045] Online media platforms usually have a large amount of content, such as articles, videos, audio, etc., which can be classified by subject, type or source. User components can be used to display the classification structure of these contents, and through interaction with users, users can easily browse and navigate to the content of interest. In the process of interaction with users, the component display method provided by this application can be used to quickly display the interactive components corresponding to the interactive operation, thereby improving the user experience.
[0046] Scenario 2: tag and keyword management.
[0047] In content management, tags and keywords are very important components. Through the tree-structured user components, a hierarchical structure of tags and keywords can be constructed to facilitate the management, search and association of related content. For example, a blog platform can use a tree-structured user component to display and manage article tags, and users can view all articles related to the tag by clicking on the tag node. In the process of interacting with the user, the component display method provided in this application can be used to quickly display the interactive components corresponding to the interactive operation, thereby improving the user experience.
[0048] Scenario three, comment and reply management.
[0049] In some online media platforms, users can comment on content and reply to other users' comments. These comments and replies usually form a tree structure, that is, one comment can have multiple replies, and each reply can have its own sub-reply. The user component with a tree structure can be used to display the hierarchical structure of such comments and replies, so that users can clearly see the context of the entire conversation. The component display method provided in this application can quickly display the interactive components corresponding to the user's interactive operations, thereby improving the user experience.
[0050] Scene 4, video and audio playlist.
[0051] For video and audio streaming platforms, users may create customized playlists. User components can be used to display the hierarchical structure of these playlists, such as multiple playlists created by users, each of which contains multiple video or audio files. In this way, users can manage and play their media content more conveniently. The component display method provided in this application can quickly display the interactive components corresponding to the user's interactive operations, thereby improving the user experience.
[0052] It should be noted that the above application scenarios are only examples, and the display method of the components provided in this embodiment can also be applied to other scenarios, which are not limited here.
[0053] The device to which the component display method provided in the present application is applied may be a computer device having component display capability, such as a terminal device or a server.
[0054] Among them, the terminal devices can specifically be desktop computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The smart car-mounted devices can be car-mounted navigation terminals and car-mounted computers, etc. The portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc., but are not limited to these.
[0055] The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server or server cluster that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in this application.
[0056] In order to facilitate understanding of the display method of the component provided in the embodiment of the present application, the application scenario of the display method of the component is executored as a server as an example below.
[0057] See also Figure 2 , which is a schematic diagram of an application scenario of a display method of a component provided in an embodiment of the present application. Figure 2 As shown, the application scenario includes a terminal device 210, which runs two different threads, namely a first thread and a second thread. The second thread can perform tasks without interfering with the first thread, such as calculating the page area of its corresponding subcomponent on the page based on the page coordinate position.
[0058] The off-screen canvas is a canvas that is decoupled from the first thread, so that the canvas object can be operated by the second thread to draw a user component on the off-screen canvas, and a page is displayed on the screen 211 of the terminal device 210, where the page includes the user component so that the user can interact with the user component, such as moving the cursor to the user component, clicking the user component, scrolling the page, etc.
[0059] When a user targets a subcomponent (such as Figure 1 When the user management subcomponent 212 shown in the figure performs a first interactive operation (such as clicking the user management subcomponent 212), in response to obtaining the first interactive operation for the user component, the page coordinate position corresponding to the first interactive operation, that is, the coordinate position of the cursor on the page, is determined through the first thread.
[0060] Since the user component includes multiple sub-components, each of which occupies a page area in the page, it is necessary to determine the sub-component that interacts with the user based on the page coordinate position, that is, through the second thread, according to the page coordinate position, determine the target page area corresponding to the first interactive operation from the multiple page areas corresponding to the user component.
[0061] Through the first thread, a pre-established auxiliary DOM node is moved to the target page area, and the auxiliary DOM node is located in the upper layer of the off-screen canvas, so that the auxiliary DOM node can block the content of the off-screen canvas located in the lower layer, and then the interactive component corresponding to the first interactive operation is displayed through the auxiliary DOM node, such as adding color to the interactive component, that is, the interaction with the DOM node is simulated on the off-screen canvas through the auxiliary DOM node.
[0062] Therefore, compared with redrawing user components and interactive components based on the canvas, it is more convenient to display interactive components through auxiliary document object model nodes, and document object model nodes include multiple types of interactive components, thereby improving the diversity and scalability of component interactions. Moreover, combined with the off-screen canvas, different tasks are performed by multiple threads respectively, which reduces the computing overhead of a single thread and avoids blocking the main thread. In addition, the off-screen canvas is decoupled from the first thread, that is, the off-screen canvas can be operated in the second thread, which reduces the amount of data transmitted between the first thread and the second thread, shortens the loading time of components, and improves the user experience.
[0063] The display method of the component provided in the embodiment of the present application can be executed by the terminal device. However, in other embodiments of the present application, the server can also have similar functions as the terminal device, thereby executing the display method of the component provided in the embodiment of the present application, or the terminal device and the server can jointly execute the display method of the component provided in the embodiment of the present application, and this embodiment does not limit this.
[0064] A display method of a component provided by the present application is described in detail below through a method embodiment.
[0065] See also Figure 3 , which is a flow chart of the display method of the component provided in the embodiment of the present application. For the convenience of description, the following embodiment is still introduced by taking the execution subject of the display method of the component as a terminal device as an example. Figure 3 As shown, the display method of the component includes the following steps:
[0066] S301: In response to obtaining a first interaction operation for a user component, determining a page coordinate position corresponding to the first interaction operation through a first thread.
[0067] A first thread and a second thread are running in the terminal device, and the first thread and the second thread are different threads. In computer science, a thread is a process divided into two or more threads (instances), which are executed concurrently by a single processor (single thread) or multiple processors (multi-threads) or a multi-core processing system. The second thread can execute tasks without interfering with the first thread, that is, the second thread can execute tasks concurrently with the first thread. Thus, different tasks are executed by multiple threads respectively, which reduces the computing overhead of the main thread and avoids blocking of the main thread.
[0068] The embodiments of the present application do not specifically limit the threads, and those skilled in the art can set them according to actual needs. For example, the first thread is the main thread, and the second thread is the Web Worker thread, wherein the Web Worker thread is JavaScript (a scripting language) running in the background, independent of other scripts, and does not affect the performance of the page. The user can continue to interact with the user components in the page, such as clicking operations, selecting content operations, etc., while the Web Worker is running in the background.
[0069] In the related art, the Canvas object can be operated by the main thread to draw components in the canvas, but the canvas is generally coupled with the main thread, so the huge computing overhead brought by the Canvas will block the main thread. Although the computing overhead of the first thread can be shared by the second thread, the Canvas object cannot be operated in a non-main thread (such as a Web Worker thread). Specifically, the Canvas object is an element used to draw graphics in HyperText Markup Language 5 (HTML5). It relies on the DOM environment provided by the browser to work. For example, the drawing functions of the Canvas are all related to the DOM environment. <canvas>Tags are bound together, which means that the canvas application programming interface (Application Programming Interface, API) and DOM are coupled. Since the Web Worker thread runs in an environment isolated from the main thread, it cannot directly access the DOM, and therefore cannot directly operate the Canvas object, so the Web Worker thread cannot directly draw user components on the Canvas.
[0070] Therefore, if you want to combine canvas and multithreading, you need to serialize a large amount of data after the Web Worker thread completes the calculation, and send it to the main thread, which can only be used after deserialization by the main thread. In addition, the data transmission between multiple threads consumes a lot of time.
[0071] Based on this, the embodiment of the present application no longer uses canvas, but uses off-screen canvas (OffscreenCanvas) to realize the drawing of user components. Among them, the off-screen canvas is decoupled from the main thread. Due to this decoupling, the rendering of OffscreenCanvas is completely separated from the DOM, and the speed is slightly faster than that of ordinary Canvas, and this is only because there is no synchronization between the two. But more importantly, after separating the two, the off-screen canvas can be used in the Web Worker thread, so that there is no need to continuously transmit data between multiple threads, which shortens the time consumption.
[0072] Therefore, in the embodiment of the present application, the second thread can be used to draw on the off-screen canvas to obtain a drawn user component (User Interface, UI), and display the user component so that the user can interact with the user component. It should be noted that the user component displayed on the page may include multiple subcomponents, such as click controls, selection controls, etc., and the user can achieve different interactive functions through different subcomponents.
[0073] If the user performs a first interactive operation on the user component, the first interactive operation on the user component is obtained through the first thread in response. In response, it is used to indicate the conditions or states on which the executed operation depends. When the dependent conditions or states are met, the executed one or more operations may be in real time or have a set delay. Unless otherwise specified, there is no restriction on the execution order of the multiple operations executed.
[0074] The user component is drawn based on the second thread. The first thread cannot determine which component of the user component the subcomponent that interacts with the user is, but the first thread can determine the page coordinate position corresponding to the first interactive operation, that is, the position of the cursor on the page displaying the user component. The user interacts with the user component through the cursor. The first interactive operation is an interactive operation, such as a floating operation, a click operation, a scrolling operation, a size change operation, etc.
[0075] The embodiments of the present application do not specifically limit the method for obtaining the first interactive operation. For example, a component container is first established in the page. The component container is equivalent to the frame of the user component, which defines the scope of interaction and detection, so that the user component drawn on the canvas is displayed on the upper layer of the component container. When the user performs the first interactive operation with the user component, the first interactive operation is detected by the component container.
[0076] It is understandable that all data collected by this application (page coordinate position, component data, etc.) are collected with the consent and authorization of the object to which the data belongs (such as a user, organization or enterprise), and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0077] S302: Determine the target page area corresponding to the page coordinate position from the user component through the second thread.
[0078] Since the size of the off-screen canvas is mapped to the size of the page displaying the user component, the subcomponents drawn on the off-screen canvas correspond to a page area on the page. When the user performs a first interactive operation on the user component through the cursor, the position of the cursor on the page, that is, the page coordinate position, is determined through the first thread. The first thread can send the page coordinate position to the second thread for calculation through the second thread, thereby reducing the calculation overhead of the first thread and avoiding blocking of the first thread.
[0079] The area occupied by the page coordinate position on the off-screen canvas is determined by the second thread. For example, when the cursor clicks on a control, the page coordinate position corresponding to the cursor is just a point, but the control corresponds to a page area, that is, the area occupied by the control on the page. Since the size of the off-screen canvas has a mapping relationship with the size of the page displaying the user component, the target page area corresponding to the page coordinate position on the page can be determined based on it. The page includes multiple page areas, and different subcomponents correspond to different page areas. It is understandable that some page areas may not correspond to subcomponents. The target page area is one of the multiple page areas corresponding to the user component.
[0080] The embodiments of the present application do not specifically limit the communication method between the first thread and the second thread. Continuing with the main thread and the Web Worker thread as an example, the data information communication between the above two threads can be maintained through the postMessage() method and onmessage(), wherein postMessage and onmessage are HTML5 methods used to solve cross-page communication, postMessage is the sender, and onmessage is the receiver, which allows scripts from different sources to communicate effectively in an asynchronous manner, and can realize cross-text document, multi-window, and cross-domain message transmission, and is mostly used for data communication between windows.
[0081] For example, if the first thread sends the detected first interaction operation to the second thread, the worker.postMessage(EventData) command can be sent to the second thread to notify the second thread to determine the target page area according to the page coordinate position. In addition, after calculating the target page area, the second thread can send the target page area to the first thread through the self.postMessage(currentNode) command, thereby updating the position of the current auxiliary DOM node of the main thread.
[0082] S303: Move the auxiliary document object model node to the target page area through the first thread, and display the interactive component corresponding to the first interactive operation through the auxiliary document object model node.
[0083] For ease of understanding, the page displayed on the page has multiple levels. From bottom (the level farther away from the user) to top (the level closer to the user), the lower level is the user component displayed on the off-screen canvas, and the upper level is the auxiliary document object model node, that is, the auxiliary DOM node is a DOM node established by the first thread, which is used to indicate the location where the interactive component is displayed. In other words, the auxiliary DOM node is equivalent to an anchor point, and the interactive component can be displayed based on the auxiliary DOM node, such as a floating button control, a floating prompt control, a right-click menu control and other interactive components, thereby improving the diversity and scalability of component interaction through the auxiliary DOM nodes.
[0084] After determining the target page area, the second thread can send the target page area to the first thread so that the first thread can clearly identify the target page area for interaction with the user. The auxiliary DOM node is thus moved to the target page area through the first thread, and the interactive component corresponding to the first interactive operation is displayed through the auxiliary DOM node. Taking the highlight control as an example, the auxiliary DOM node can be moved to the target page area, which is equivalent to covering the control displayed on the off-screen canvas based on the auxiliary DOM node, and then performing a redraw operation on the off-screen canvas, and then displaying the highlighted control in the target page area, so that from the perspective of user perception, the control shows a highlight effect after being clicked.
[0085] For another example, if the page structure changes after the user deletes a control on the page, the auxiliary DOM node can be moved to the target page area after determining the target page area based on the deletion operation. This is equivalent to covering and hiding the control displayed on the underlying off-screen canvas based on the auxiliary DOM node, and then redrawing the off-screen canvas at the position of the auxiliary DOM node in the target page area. From the user's perspective, the control is deleted from the page by performing a redraw operation on the off-screen canvas.
[0086] For another example, if a user deletes a certain control on the page, a pop-up window will pop up to allow the user to determine whether to delete the control. After the target page area is determined based on the deletion operation, the auxiliary DOM node can be moved to the target page area, and a pop-up window can be displayed at the position of the auxiliary DOM node in the target page area. When the user clicks the control indicating no based on the pop-up window, this click operation is equivalent to a new first interaction operation, and the details can be referred to above. In addition, since two consecutive interaction operations do not cause the page structure to change, there is no need to redraw the off-screen canvas through a redraw operation. Therefore, from the perspective of user perception, after the control is accidentally deleted, a pop-up window is displayed to confirm whether to delete it again to avoid accidental deletion operations.
[0087] It can be seen from the above technical solution that the display of components is no longer realized based on the main thread (or a single thread), but through multiple threads. Taking the first thread and the second thread as an example, the second thread can perform tasks without interfering with the first thread. Specifically, the user component is obtained by drawing the second thread based on the off-screen canvas, and in response to obtaining the first interactive operation for the user component, the page coordinate position corresponding to the first interactive operation is determined by the first thread. Through the second thread, according to the page coordinate position, from the multiple page areas corresponding to the user component, the target page area corresponding to the first interactive operation is determined. Through the first thread, the pre-established auxiliary document object model node is moved to the target page area, and the auxiliary document object model node is located in the upper layer of the off-screen canvas, so that the auxiliary document object model node can cover the content of the off-screen canvas located in the lower layer, and then the interactive component corresponding to the first interactive operation is displayed through the auxiliary document object model node, that is, the interaction with the document object model node is simulated on the off-screen canvas through the auxiliary document object model node.
[0088] Therefore, compared with redrawing user components and interactive components based on the canvas, it is more convenient to display interactive components through auxiliary document object model nodes, and document object model nodes include multiple types of interactive components, thereby improving the diversity and scalability of component interactions. Moreover, combined with the off-screen canvas, different tasks are performed by multiple threads respectively, which reduces the computing overhead of a single thread and avoids blocking the main thread. In addition, the off-screen canvas is decoupled from the first thread, that is, the off-screen canvas can be operated in the second thread, which reduces the amount of data transmitted between the first thread and the second thread, shortens the loading time of components, and improves the user experience.
[0089] The following describes the process of drawing the user component based on the off-screen canvas through the second thread, see A1-A5 for details.
[0090] A1: Obtain the initial component data set and the total page area size through the second thread.
[0091] The initial component data set includes multiple component data, and the structure of the initial component data set is a tree structure, or in other words, the structure of multiple component data is a tree structure with infinite levels. Component data is data used to describe components, such as component configuration data describing component configuration, component source data describing component parameters, etc. The total page area size is the size of the total page area, that is, the size of the page used to display user components. Generally, the total page area size is consistent with the size of the off-screen canvas.
[0092] A2: Adding a level identifier to each component data included in the initial component data set through the second thread, and setting the level height of each level to obtain a component data set.
[0093] Since the structure of the initial component data set is a tree structure, the initial component data set can be traversed from top to bottom or in other ways, thereby adding a level identifier for each component data, so that the level of the corresponding component data in the initial component data set can be determined by the level identifier, and the level height of each level is set by the second thread, so that the level height of the component data at the same level is the same, thereby obtaining an updated initial component data set, that is, a component data set. It should be noted that the structure of the component data set has not changed, so the structure of the component data set is a tree structure.
[0094] As a possible implementation method, in order to facilitate subsequent calculations, the level heights of each level can be set to be consistent, that is, the level heights of each component data are consistent.
[0095] A3: According to the total area size of the page, the level identifier and the level height, the number of displayable component data is determined from the component data set through the second thread.
[0096] Since the total area of the page is limited, when the amount of component data included in the component data set is large, it may not be possible to display all the component data in the total area of the page, that is, the total area of the page will display a part of the component data included in the component data set. Therefore, the number of component data in the component data set that can be displayed on the page can be determined according to the level identifier and level height, as well as the total area size of the page, so as to display the number of component data.
[0097] A4: According to the number of displayable component data, obtain a displayable component data subset from the component data collection.
[0098] The number of displayable component data is the number of component data that can be displayed in the total area of the page. Component data that meets the number of displayable component data is obtained from the component data collection to obtain a displayable component data subset.
[0099] The embodiments of the present application do not specifically limit the method of obtaining a subset of displayable component data from a component data set. For example, when displaying a user component for the first time, component data can be obtained from the first component data in the component data set from top to bottom based on a tree structure to obtain component data of the number of displayable component data, thereby obtaining a subset of displayable component data. For another example, a history record of a user's page browsing is recorded, and based on the user's historical browsing location, component data corresponding to the historical browsing location is determined. Based on the component data, component data is obtained from top to bottom based on a tree structure to obtain component data of the number of displayable component data, thereby obtaining a subset of displayable component data.
[0100] A5: According to the displayable component data subset, the second thread draws in an off-screen canvas to obtain a user component.
[0101] The second thread operates the off-screen canvas object to draw on the off-screen canvas according to the displayable component data subset, and the style of the user component is displayed on the page.
[0102] Therefore, compared with the initial component data set, the displayable component data subset includes less component data, so that the speed of traversing the displayable component data subset to draw the user component data is faster, that is, the loading time of the user component is reduced, which improves the user experience. Furthermore, in the scenario of a large amount of component data (such as more than 100,000), instead of traversing all component data, only the initial component data set is traversed, and the user component is displayed in real time on the page (visible canvas area), which takes less time to load and provides a better user experience.
[0103] It is understandable that after interacting with the user, the user component on the page may or may not change, so the second thread can redraw the user component on the off-screen canvas after each interactive operation, or the second thread can redraw the user component on the off-screen canvas after the user component on the page changes, so as to display the redrawn user component on the page.
[0104] The following takes the scrolling operation as the first interactive operation as an example. The scrolling operation will cause the user components on the page to change. In the related technology, all component data, that is, the initial component data set, is generally traversed to redraw the user components, but this method takes a long time to load.
[0105] Based on this, an embodiment of the present application proposes a method for reducing loading time, see B1-B4 for details.
[0106] B1: If the first interactive operation is a scrolling operation, determine the scrolling distance based on the page coordinate position through the second thread.
[0107] The scrolling operation can cause the component data to change quickly. The second thread can determine the scrolling distance based on the page coordinate position. The scrolling distance is used to identify the length of the component data change caused by the scrolling operation. For example, sliding the mouse can skip half a page of component data.
[0108] B2: According to the scrolling distance and the level height of each level, the amount of component data skipped by the scrolling operation is determined by the second thread.
[0109] Based on the scrolling distance, the page length skipped by the scrolling operation on the page can be determined, so that the component data displayed on the page length is also skipped. Since the level height of each level is known, the number of component data skipped by the scrolling operation can be determined based on the scrolling distance and the level height of each level.
[0110] For example, before the scrolling operation is performed, the level identifier of the last component data included in the currently displayable component data subset can be determined, so as to determine the number of components to be skipped based on the level identifier, level height and scrolling distance.
[0111] B3: According to the number of component data skipped by the scrolling operation, an updated displayable component data subset is obtained from the component data collection through the second thread.
[0112] Since the total area size of the page remains unchanged, when part or all of the component data on the page is skipped, it is necessary to redraw it on the off-screen canvas based on the other part of the component data. Therefore, it is necessary to determine the data required for drawing, that is, according to the number of component data skipped by the scrolling operation, obtain the updated displayable component data subset from the component data collection through the second thread.
[0113] For example, the first component data and the last component data in the displayable component data subset obtained after the last interaction and the number of component data skipped by this scrolling operation can be used to determine the first component data and the last component data in the updated displayable component data subset, so that the updated displayable component data subset can be obtained from the component data collection.
[0114] For another example, the structure of the component data set is a tree structure, and the displayable component data subset can be obtained by finding the number of skipped component data starting from the last component data in the displayable component data subset obtained after the last interaction to obtain the displayable component data subset.
[0115] B4: Drawing is performed in an off-screen canvas by a second thread according to the updated displayable component data subset to obtain a user component corresponding to the scrolling operation.
[0116] Therefore, after a scrolling operation occurs, the displayable component data subset may undergo significant changes. Compared to traversing all component data in the initial component data set for drawing, first obtaining an updated displayable component data subset, and then drawing based on the component data included in the updated displayable component data subset, the number of traversed component data is smaller, thereby drawing user component data faster, that is, the loading time of user components is reduced, thereby improving user experience.
[0117] The following describes how to draw the user component based on the second thread, see C1-C4 for details.
[0118] C1: Get component data and off-screen canvas through the second thread.
[0119] The embodiment of the present application does not specifically limit the method of obtaining component data through the second thread, and two methods are used as examples for explanation below.
[0120] Method 1: The first thread obtains the information and then forwards it to the second thread.
[0121] After the user customizes the component data, the component data will be uploaded, and in response to the upload operation of the first thread to obtain the component data, the component data is obtained through the first thread. The component data is sent to the second thread through the first thread so that the second thread obtains the component data.
[0122] Method 2: Obtain directly through the second thread.
[0123] In response to obtaining a request including component data, a request is obtained through a second thread, the request including component data, so that the second thread can obtain the component data through the request. For example, a network request is initiated through a Web Worker thread to obtain component data.
[0124] Thus, the component data is directly obtained through the second thread without forwarding through the first thread, which reduces the number of interactions between the first thread and the second thread, shortens the data transmission time, and improves the user experience.
[0125] The embodiment of the present application does not specifically limit the manner in which the second thread obtains the off-screen canvas, and two manners are used as examples for description below.
[0126] Method 1 is to create an off-screen canvas between the second threads, that is, to create a canvas decoupled from the first thread through the second thread, so that after the off-screen canvas is created, drawing can be performed on the off-screen canvas.
[0127] Method 2: An initial canvas is created through the first thread. The initial canvas is coupled with the first thread, so the initial canvas needs to be converted through the first thread to obtain an off-screen canvas. The off-screen canvas is decoupled from the first thread. Finally, the off-screen canvas is sent to the second thread through the first thread so that the second thread can draw based on the off-screen canvas.
[0128] For example, the main thread creates a Canvas canvas, and then executes the API method transferControlToOffscreen() on the newly initialized Canvas object to convert the Canvas object into an OffscreenCanvas object to obtain an off-screen canvas. In this way, the OffscreenCanvas object can be directly operated on the off-screen canvas for drawing in the Web Worker thread.
[0129] Thus, after the first thread obtains the component data, it can create an initial canvas, thereby converting the initial canvas into an off-screen canvas and sending it to the second thread. After the second thread obtains the component data through the first thread, it generates drawing data based on the component data, and then the second thread draws on the off-screen canvas based on the drawing data to obtain the user component. In this way, the first thread and the second thread each perform different tasks and cooperate well, thereby making the generation process of the user component more convenient and quick.
[0130] C2: According to the component data, the drawing data for drawing the user component is determined by the second thread.
[0131] After the second thread obtains the component data, the second thread may obtain drawing data based on the component data, such as the canvas size of the off-screen canvas, configuration data for drawing each subcomponent, and source data for drawing each subcomponent.
[0132] C3: According to the drawing data, the second thread draws in an off-screen canvas to obtain a user component.
[0133] Get the drawing context through OffscreenCanvasRenderingContext2D(), and then draw in the off-screen canvas according to the drawing data. The drawing object can be a rectangle, text, picture, etc., so as to obtain the user component.
[0134] C4: Display user components.
[0135] As a result, the off-screen canvas is decoupled from the first thread, thereby reducing the number of interactions between the first thread and the second thread while sharing the computational overhead of drawing through the second thread. That is, there is no need for the first thread and the second thread to transmit a large amount of data to each other, thereby reducing data transmission time, shortening loading time, and improving user experience.
[0136] As a possible implementation method, in order to further reduce the user's learning cost, the component data can be subdivided into component source data and component configuration data, where the component source data is used to describe the component parameters, such as the texture, size, color and other parameters that the component can use, and the component configuration data is used to describe the component configuration, that is, the user's adjustment of the component. In this way, the user does not need to learn complex drawing knowledge, and can adjust the component by adjusting the component configuration data.
[0137] In addition, if you want to expand the style of interactive components, for example, you can add colors to interactive components and pop up a prompt window. By adding data for expanding the corresponding style in the component source data, users can customize the interactive components according to their own style requirements, including but not limited to fonts, font sizes, line heights, icons, etc., and even make more configuration customizations for interactions such as node selection and directory expansion of components.
[0138] In addition, users can also add customized callback functions for each icon passed in, that is, functions that are passed as parameters and called under certain events or conditions. This allows for dual customization of styles and callbacks, improving user experience.
[0139] As a possible implementation method, component configuration data is generally no longer used after being used for the first time the user component is drawn on an off-screen canvas. Therefore, in order to further reduce memory usage, the component configuration data can be deleted by the second thread after the user component is obtained based on the component source data, the component configuration data and the off-screen canvas. However, the component source data is generally used each time the user component is drawn. Therefore, the component source data can be stored in the second thread before the user component is destroyed. If the user component is destroyed, such as when the user closes the current page, the component source data is deleted by the second thread.
[0140] Therefore, whether the second thread deletes the data is determined according to the usage of the data to reduce the memory usage caused by data storage. Specifically, after the component configuration data has been used, the component configuration data can be deleted by the second thread. However, after the component source data has been used, the component source data will not be deleted immediately. Instead, the component source data will be deleted after the user component is destroyed, thereby reducing memory usage while ensuring data availability.
[0141] As a possible implementation, not only one thread but also multiple threads may assist the first thread in executing the task, thereby further improving the calculation speed and shortening the loading time of the interactive component.
[0142] For the convenience of description, the following example takes the second thread including the first sub-thread and the second sub-thread as an example, the first sub-thread and the second sub-thread are different sub-threads, and each sub-thread is a thread for performing tasks without interfering with the first thread and other sub-threads. Specifically, the first sub-thread is used to obtain a user component based on off-screen canvas drawing, and the second sub-thread is used to determine the target page area corresponding to the page coordinate position from the user component.
[0143] Therefore, the tasks of the second thread are shared by different sub-threads, that is, multiple sub-threads collaborate and parallel processing improves processing efficiency, thereby further improving the computing speed of the second thread, shortening the loading time of the interactive component, and improving the user experience.
[0144] As a possible implementation method, since the user may perform multiple interactive operations in a short period of time, such as continuously moving the cursor on the page, continuously clicking on the blank area of the page in a short period of time, thereby generating multiple click operations, etc., if the user's interactive operations are responded to every time, it may cause the first thread and the second thread to generate a large amount of meaningless calculations. Based on this, an embodiment of the present application provides a method for responding to a first interactive operation through a first thread, see S2011-S2013 for details.
[0145] S2011: In response to obtaining a first interactive operation for a user component, setting a first operation delay period through a first thread.
[0146] After obtaining the first interactive operation through the first thread, in response to obtaining the first interactive operation for the user component, the page position corresponding to the first interactive operation is no longer directly determined through the first thread, but a first operation delay period is first set through the first thread, the first operation delay period is the operation delay period corresponding to the first interactive operation, and the start time of the first operation delay period is the acquisition time of the first interactive operation. The embodiment of the present application does not specifically limit the length of the first operation delay period, and those skilled in the art can set it according to actual needs.
[0147] The operation delay period is a time period for delaying the execution of the step of the first thread determining the page location corresponding to the first interactive operation, or even not executing the step.
[0148] S2012: If a second interactive operation for the user component is acquired during the first operation delay period, the timing of the first operation delay period is canceled, and a second operation delay period is set through the first thread.
[0149] If the second interactive operation for the user component is obtained during the first operation delay period, that is, before the end of the first operation delay period, the second interactive operation is obtained, which means that multiple interactive operations are obtained continuously in a short period of time. In order to avoid the interactive operation being triggered at a high frequency in a short period of time, the timing of the first operation delay period is canceled, and a second operation delay period is set for the second interactive operation. The start time of the second operation delay period is the acquisition time of the second interactive operation, which is equivalent to no longer performing subsequent processing based on the first interactive operation, but taking the second interactive operation as the basis for performing subsequent processing, and re-timing based on the second operation delay period corresponding to the second interactive operation. If no other interactive operations are obtained during the second operation delay period, the page coordinate position corresponding to the second interactive operation can be determined through the first thread at the end of the second operation delay period.
[0150] Among them, the second interactive operation is an interactive operation, such as a floating operation, a click operation, a scrolling operation, a size change operation, etc. It can be the same type of interactive operation as the first interactive operation, or it can be a different type of interactive operation, but it and the first interactive operation are interactive operations obtained by the first thread at different times.
[0151] The embodiment of the present application does not specifically limit the duration of the first operation delay period and the second operation delay period, and those skilled in the art can set them according to actual needs. For example, the duration of the first operation delay period and the second operation delay period is the same, and both are less than the preset duration, so that the first operation delay period and the second operation delay period are both shorter periods. For another example, the duration of the first operation delay period and the second operation delay period is different, and different operation delay periods can be set based on different interactive operation types to match the interactive operation type, so that it is more suitable for application scenarios.
[0152] S2013: If the second interactive operation for the user component is not acquired during the first operation delay period, at the end of the first operation delay period, the page coordinate position corresponding to the first interactive operation is determined through the first thread.
[0153] If the second interactive operation for the user component is not obtained in the first operation delay period, that is, no other interactive operations are obtained in the first operation delay period, it means that only one interactive operation, that is, the first interactive operation, is obtained in a short period of time. Therefore, the page coordinate position corresponding to the first interactive operation can be determined through the first thread at the end of the first operation delay period.
[0154] Therefore, after obtaining the interactive operation, the page coordinate position is no longer directly determined based on the interactive operation through the first thread, but the operation delay period is set through the first thread. If no other interactive operations are obtained during the operation delay period, it means that there is no high-frequency triggering of interactive operations in a short period of time, and the page coordinate position corresponding to the interactive operation can be determined through the first thread. If other interactive operations are obtained during the operation delay period, it means that the interactive operations are triggered frequently in a short period of time. In order to reduce the computing overhead of the first thread, the timing of the operation delay period corresponding to the interactive operation can be canceled, and an operation delay period can be reset for the other interactive operations, and the timing can be restarted until there is no high-frequency triggering of interactive operations in a short period of time, and the page coordinate position corresponding to the interactive operation can be determined through the first thread. Thereby reducing performance issues caused by users triggering the same interactive operation quickly and continuously, such as multiple requests caused by continuous clicking of controls.
[0155] As a possible implementation method, if the structure of the user component changes, such as if the user component is a tree structure and one of the nodes is deleted, the structure of the current user component will change, so that the updated user component needs to be redrawn through the off-screen canvas. However, if the number of redraws is too many, it will also cause a burden on the second thread. Based on this, the embodiment of the present application provides a triggering method for the redraw operation, see D1-D2 for details.
[0156] D1: If the difference between the time when the page coordinate position is obtained through the second thread and the time when the historical page coordinate position is last obtained is less than a preset time difference, the redrawing operation is not performed.
[0157] If the difference between the time when the page coordinate position is obtained through the second thread this time and the time when the historical page coordinate position was obtained through the second thread last time is less than the preset time difference, that is, the time between two adjacent acquisitions of the page coordinate position is short, where the historical page coordinate position is the page coordinate position obtained last time.
[0158] This is equivalent to the second thread obtaining the page coordinate position corresponding to an interactive operation after the first thread obtains the interactive operation, and checking the time of the last redraw operation before executing the redraw operation. It can be understood that the time when the last redraw operation started is approximately equal to the time when the historical page coordinate position was obtained last time. If the time interval from the last redraw operation to now is less than the set time window (i.e., the preset time difference), then the redraw operation will not be executed.
[0159] D2: If the difference between the time of obtaining the page coordinate position through the second thread and the time of obtaining the historical page coordinate position last time is greater than or equal to the preset time difference, a redraw operation is performed.
[0160] If the difference between the time of obtaining the page coordinate position through the second thread this time and the time of obtaining the historical page coordinate position through the second thread last time is greater than or equal to the preset time difference, that is, the time of obtaining the page coordinate position twice is longer, which is equivalent to that after the first thread obtains an interactive operation, the second thread obtains the page coordinate position corresponding to the interactive operation. Before performing the redraw operation, check the time of the last redraw operation. If the time interval from the last redraw operation to now is greater than or equal to the set time window (that is, the preset time difference), then perform the redraw operation.
[0161] The redraw operation is described below, see E1-E3 for details.
[0162] E1: According to the page position coordinates, obtain component data and off-screen canvas through the second thread.
[0163] E2: According to the component data, determining, through the second thread, updated drawing data corresponding to the updated user component for drawing.
[0164] The updated drawing data is the drawing data corresponding to the updated user component.
[0165] E3: According to the updated drawing data, redrawing is performed in the off-screen canvas through the second thread to obtain an updated user component.
[0166] Therefore, before executing the redrawing operation, the second thread determines whether the time difference between the current redrawing operation and the previous redrawing operation is greater than or equal to the preset time difference. If not, it means that the time between the two redrawing operations is close, which may be less than the screen refresh frequency, so that the current redrawing operation is meaningless and cannot be viewed by the user, so the redrawing operation can no longer be executed. If so, the redrawing operation is executed, so that the frequency of the redrawing operation is greater than the refresh frequency to avoid meaningless redrawing and reduce the calculation burden of the second thread. In this way, the frequency of interactive operations is limited, such as limiting the triggering frequency of page scrolling events to improve page performance.
[0167] The component display method provided in the embodiment of the present application can be applied to Chrome TM , Firefox TM , Safari TM In the pages of web applications hosted by mainstream browsers such as , it can significantly shorten the loading time and improve the smoothness of user experience. However, in some web applications with lower versions, incompatibility issues may occur, resulting in the inability of web applications with lower versions to display user components.
[0168] After research, it was found that the incompatibility problem is generally caused by the fact that the web application with a lower version cannot support the drawing of the off-screen canvas, which leads to the failure of drawing the user component. Based on this, it can be judged whether the second thread can implement the calling logic of this application, that is, whether the second thread can draw the user component based on the off-screen canvas.
[0169] Specifically, if the second thread successfully draws the user component based on the off-screen canvas, it means that the version of the current web application is relatively high, so it can be compatible with the display method of the component provided in the embodiment of the present application, thereby achieving the effect of shortening the loading time of the interactive component. If the second thread fails to draw the user component based on the off-screen canvas, it means that the version of the current web application is relatively low, then the user component is generated through the first thread, such as the first thread realizes the display of the component based on the aforementioned DOM node combination method, and then after obtaining the third interactive operation for the user component, in response to the first thread obtaining the third interactive operation for the user component, the interactive component corresponding to the third interactive operation is determined through the first thread, that is, the display of the user component and the interactive component is realized through the first thread. Although this method will cause a large computational overhead for the first thread, it can correctly guarantee the display of the interactive component and the user component.
[0170] Therefore, by judging whether the second thread can draw the user component based on the off-screen canvas, it is possible to identify whether the version of the current web application is compatible. When it is incompatible, the user component and the interactive component can be displayed alone through the first thread, thereby ensuring the normal display of the user component and the interactive component and improving the user experience.
[0171] In order to facilitate further understanding of the technical solution provided by the embodiment of the present application, the display method of the component provided by the embodiment of the present application is generally introduced by way of example, taking the execution subject of the display method of the component provided by the embodiment of the present application as a terminal device as an example.
[0172] The following first describes the environment of the application scenario of this embodiment: The structure of the user component is a tree (or directory structure), the first thread is the main thread, the second thread is the Web Worker thread, and the off-screen canvas is the OffscreenCanvas.
[0173] See also Figure 4 , which is an architecture diagram of a display method of a component provided by an embodiment of the present application. In addition, under this architecture, it is not only applicable to tree-shaped components, but also applicable to scenarios such as list data and batch tag data.
[0174] The user interaction layer 410 is used to obtain interactive operations, which will trigger the update of user components. The update event is interactively expanded in the auxiliary DOM layer 420, and the auxiliary DOM layer 420 includes an update event processing module 421 and an interactive DOM module 422. After obtaining the interactive operation through the change event processing module 421, the data corresponding to the interactive operation is transmitted to the bottom layer 440 through the data layer 430 for calculation and rendering through the interactive DOM module, wherein the data layer 430 includes a component source data module 431 and a component configuration data module 432, the component source data module 431 is used to obtain component source data, and the component configuration data module 432 is used to obtain component configuration data. The bottom layer includes a rendering engine (Rendering Engine) 441, an offline canvas 442, a WebWorker thread 443, a calculation module 444, a communication layer 445 and a main thread 446. The following describes each module included in the bottom layer 440.
[0175] First, the communication process between the main thread and the Web Worker thread is explained.
[0176] See also Figure 5 , which is a schematic diagram of a multi-threaded communication provided by an embodiment of the present application. Figure 5 In the example, the main thread and the Web Worker thread communicate through a message channel. For example, data information communication between the two threads can be maintained through the postMessage() method and onmessage().
[0177] After the first thread obtains the component data through the component data module, the first thread sends the component data to the Web Worker thread through the message channel. The Web Worker thread performs content parsing through the preprocessing module, that is, obtains the component source data and the component configuration data from the component data.
[0178] The interactive DOM module includes a component container and an auxiliary DOM node, wherein the component container is used to detect whether an interactive operation is obtained, and the auxiliary DOM node is used as an anchor point to display the interactive component corresponding to the interactive operation.
[0179] The rendering engine is responsible for drawing user components on the off-screen canvas. It receives three types of messages: (1) component data initially passed in from the main thread, such as component configuration data such as custom component styles and events, and component source data; (2) the OffscreenCanvas canvas object passed in from the main thread via the message channel module, which can be directly operated in the Web Worker thread; and (3) data detected related to interactive operations (such as the type of interactive operations) are also passed from the main thread to the rendering engine via the message channel module.
[0180] The computing module provides all auxiliary computing capabilities, including recursive positioning of tree structures, tree node information acquisition, and leaf node length judgment.
[0181] The following describes the process of the main thread and the Web Worker thread cooperating to display user components.
[0182] See also Figure 6 , which is a schematic diagram of an application scenario of a component provided in an embodiment of the present application. Figure 6 In the figure, for the convenience of illustration, the main thread and the Web Worker thread communicate through the message channel through the dotted arrows, and the communication within the thread is indicated by the solid arrows.
[0183] After the main thread obtains the component source data and component configuration data based on the component data module, it sends the component source data and component configuration data to the preprocessing module in the WebWorker thread through worker.postMessage(SourceData+OptionSet), where SourceData represents the component source data and OptionSet represents the component configuration data.
[0184] As a possible implementation, if the user component is destroyed, the component source data is deleted through the Web Worker thread; if the Web Worker thread obtains the user component based on the component configuration data and off-screen canvas drawing, the component configuration data is deleted through the second thread.
[0185] The preprocessing module determines the canvas size, the configuration data for drawing each subcomponent, and the source data for drawing each subcomponent based on the component source data and the component configuration data. The Web Worker thread sends the canvas size of the offline canvas to the auxiliary DOM node in the main thread through self.postMessage(CanvasSize) so that the auxiliary DOM node can clarify its movement range.
[0186] The main thread creates a canvas and converts the Canvas object into an OffscreenCanvas object through transferControlToOffscreen() to obtain an off-screen canvas. The main thread then sends the off-screen canvas to the Web Worker thread through worker.postMessage(OffscreenCanvas), so that the Web Worker thread can directly operate the OffscreenCanvas object on the off-screen canvas to draw based on the canvas size, the configuration data for drawing each subcomponent, and the source data for drawing each subcomponent, thereby obtaining a user component.
[0187] After displaying the user component, the component container detects whether the first interactive operation is obtained. In response to obtaining the first interactive operation for the user component, the page coordinate position corresponding to the first interactive operation is determined through the main thread, and the page coordinate position, the type corresponding to the interactive operation and other data are sent to the calculation module in the Web Worker thread through worker.postpostMessage(EventData).
[0188] The target page area corresponding to the page coordinate position is determined from the user component through the calculation module. The Web Worker thread sends the target page area to the main thread through worker.postpostMessage(currentNode), moves the auxiliary document object model node to the target page area through the main thread, and displays the interactive component corresponding to the first interactive operation through the auxiliary document object model node.
[0189] If the first interactive operation causes the structure of the user component to change, such as adding a tree node or deleting a tree node, a redraw operation may be performed on the off-screen canvas through the calculation module to obtain an updated user component.
[0190] In addition, in order to improve page performance, this embodiment sets different methods for the main thread and the Web Worker thread, which are described below respectively.
[0191] For the main thread, after obtaining the interactive operation, the operation delay period is set through the main thread. If no other interactive operations are obtained within the operation delay period, the page coordinate position corresponding to the interactive operation can be determined through the main thread. If other interactive operations are obtained within the operation delay period, the timing of the operation delay period corresponding to the interactive operation can be canceled, and a new operation delay period can be set for the other interactive operations, and the timing can be restarted until there are no high-frequency interactive operations triggered in a short period of time. This reduces performance issues caused by users triggering the same interactive operation quickly and continuously, such as multiple requests caused by continuous clicks on controls.
[0192] For the Web Worker thread, before executing the redraw operation, the Web Worker thread determines whether the time difference between the current redraw operation and the previous redraw operation is greater than or equal to the preset time difference. If not, the current redraw operation is no longer executed. If yes, the redraw operation is executed, so that the frequency of the redraw operation is greater than the refresh frequency to avoid meaningless redrawing and reduce the computing burden of the second thread. In this way, the frequency of interactive operations is limited, such as limiting the triggering frequency of page scrolling events, to improve page performance.
[0193] Therefore, this embodiment provides a component display solution in the scenario of massive data (50,000 or even larger), which can not only ensure fast loading and smooth experience, but also provide basic and complete interactive capabilities and scalability. Moreover, it can overcome the problems of large memory usage of web pages and slow usage and scrolling under large data volumes, and achieve a rendering speed improvement of more than 90% compared with conventional user components.
[0194] See also Figure 7 , which is a schematic diagram of a loading time comparison provided by an embodiment of the present application. The solution of the embodiment of the present application reduces the loading time by more than 90% compared with the solution based on DOM node combination, and can even be optimized by more than 98% at the level of 50,000 nodes, and the larger the data level, the more obvious its advantage.
[0195] See also Figure 8 , which is a schematic diagram of memory comparison provided by an embodiment of the present application. The solution of the embodiment of the present application reduces the memory usage by more than 95% compared with the solution based on DOM node combination, and the larger the data volume, the more obvious its advantage. This is because Canvas has a huge advantage in memory usage over the DOM solution.
[0196] See also Fig. 9 , which is a schematic diagram of a thread overhead comparison provided by an embodiment of the present application. Fig. 9 In (a), since only the main thread participates in drawing in the solution based on DOM node combination, the main thread bears a lot of computing overhead, and the possibility of thread blocking is very high in the scenario of massive data. Fig. 9 In (b), the Web Worker thread of the embodiment of the present application bears the main computing overhead, which greatly alleviates the blocking pressure of the main thread.
[0197] With respect to the display method of the components described above, the present application also provides a display device of the corresponding components, so that the display method of the components described above can be applied and implemented in practice.
[0198] See also Fig.10 , which is a schematic diagram of the structure of a display device of a component provided in an embodiment of the present application. Fig.10 As shown, the display device 1000 of the component is built in a device running a first thread and a second thread, wherein the first thread and the second thread are different threads, and the second thread is used to perform tasks without interfering with the first thread. The display device 1000 of the component includes: a page coordinate position determination unit 1001, a target page area determination unit 1002, and an interactive component display unit 1003;
[0199] The page coordinate position determining unit 1001 is configured to determine, in response to obtaining a first interactive operation for a user component, a page coordinate position corresponding to the first interactive operation through the first thread, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread;
[0200] The target page area determination unit 1002 is used to determine, through the second thread, a target page area corresponding to the page coordinate position from the user component, wherein the target page area is one of the multiple page areas corresponding to the user component;
[0201] The interactive component display unit 1003 is used to move the auxiliary document object model node to the target page area through the first thread, and display the interactive component corresponding to the first interactive operation through the auxiliary document object model node, the auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
[0202] It can be seen from the above technical solution that the display device of the component includes: a page coordinate position determination unit, a target page area determination unit and an interactive component display unit. Moreover, the component display device no longer realizes the display of the component based only on the main thread (or a single thread), but realizes the display of the component through multiple threads. Taking the first thread and the second thread as an example, the second thread can perform tasks without interfering with the first thread. Specifically, after the user component is obtained by the second thread based on the off-screen canvas drawing, the page coordinate position determination unit is used to determine the page coordinate position corresponding to the first interactive operation for the user component through the first thread in response to obtaining the first interactive operation. The target page area determination unit is used to determine the target page area corresponding to the first interactive operation from the multiple page areas corresponding to the user component through the second thread according to the page coordinate position. An interactive component display unit is used to move a pre-established auxiliary document object model node to a target page area through a first thread, wherein the auxiliary document object model node is located in an upper layer of an off-screen canvas, so that the auxiliary document object model node can obscure the content of the off-screen canvas in a lower layer, and then display the interactive component corresponding to the first interactive operation through the auxiliary document object model node, that is, the interaction with the document object model node is simulated on the off-screen canvas through the auxiliary document object model node.
[0203] Therefore, compared with redrawing user components and interactive components based on the canvas, it is more convenient to display interactive components through auxiliary document object model nodes, and document object model nodes include multiple types of interactive components, thereby improving the diversity and scalability of component interactions. Moreover, combined with the off-screen canvas, different tasks are performed by multiple threads respectively, which reduces the computing overhead of a single thread and avoids blocking the main thread. In addition, the off-screen canvas is decoupled from the first thread, that is, the off-screen canvas can be operated in the second thread, which reduces the amount of data transmitted between the first thread and the second thread, shortens the loading time of components, and improves the user experience.
[0204] As a possible implementation manner, the device further includes a drawing unit, which is used to:
[0205] Acquire an initial component data set and a total page area size through the second thread, wherein the structure of the initial component data set is a tree structure;
[0206] By using the second thread, a level identifier is added to each component data included in the initial component data set, and a level height of each level is set to obtain a component data set, wherein component data at the same level have the same level height;
[0207] According to the total area size of the page, the level identifier and the level height, determining, by the second thread, the number of displayable component data from the component data set;
[0208] According to the number of displayable component data, obtaining a displayable component data subset from the component data set;
[0209] The user component is obtained by drawing in the off-screen canvas through the second thread according to the displayable component data subset.
[0210] As a possible implementation manner, the device further includes a drawing unit, which is used to:
[0211] If the first interactive operation is a scrolling operation, determining a scrolling distance based on the page coordinate position through the second thread;
[0212] Determining, by the second thread, the amount of component data skipped by the scrolling operation according to the scrolling distance and the level heights of the various levels;
[0213] According to the amount of component data skipped by the scrolling operation, acquiring an updated displayable component data subset from the component data set through the second thread;
[0214] According to the updated displayable component data subset, drawing is performed in the off-screen canvas by the second thread to obtain a user component corresponding to the scrolling operation.
[0215] As a possible implementation, the device further includes an acquisition unit, a parsing unit, a drawing unit and a display unit;
[0216] The acquisition unit is used to acquire component data and off-screen canvas through the second thread;
[0217] The parsing unit is used to determine drawing data for drawing the user component through the second thread according to the component data;
[0218] The drawing unit is configured to draw on the off-screen canvas through the second thread according to the drawing data to obtain the user component;
[0219] The display unit is used to display the user component.
[0220] As a possible implementation manner, the device further includes an acquisition unit, configured to:
[0221] In response to the upload operation of acquiring the component data, acquiring the component data through the first thread;
[0222] sending the component data to the second thread through the first thread; or,
[0223] In response to obtaining a request including the component data, obtaining the request by the second thread;
[0224] The component data is obtained through the request.
[0225] As a possible implementation manner, the device further includes an acquisition unit, configured to:
[0226] Creating an initial canvas through the first thread, wherein the initial canvas is coupled to the first thread;
[0227] Converting the initial canvas through the first thread to obtain the off-screen canvas, where the off-screen canvas is decoupled from the first thread;
[0228] The off-screen canvas is sent to the second thread through the first thread.
[0229] As a possible implementation manner, the component data includes component source data and component configuration data, and the apparatus further includes a deleting unit, which is used to:
[0230] If the user component is destroyed, deleting the component source data through the second thread;
[0231] If the second thread obtains the user component based on the component configuration data and the off-screen canvas drawing, the component configuration data is deleted through the second thread.
[0232] As a possible implementation, the second thread includes a first sub-thread and a second sub-thread, the first sub-thread is used to obtain the user component based on the off-screen canvas drawing, and the target page area determination unit 1002 is specifically used to determine the target page area corresponding to the page coordinate position from the user component through the second sub-thread.
[0233] As a possible implementation manner, the page coordinate position determining unit 1001 is specifically used to:
[0234] In response to obtaining a first interactive operation for the user component, setting a first operation delay period through the first thread, where a start time of the first operation delay period is a time when the first interactive operation is obtained;
[0235] If a second interactive operation for the user component is obtained during the first operation delay period, the timing of the first operation delay period is canceled, and a second operation delay period is set through the first thread, and the start time of the second operation delay period is the time when the second interactive operation is obtained;
[0236] If the second interactive operation for the user component is not acquired during the first operation delay period, then at the end of the first operation delay period, the page coordinate position corresponding to the first interactive operation is determined through the first thread.
[0237] As a possible implementation manner, the device further includes a drawing unit, which is used to:
[0238] If the difference between the time when the page coordinate position is obtained by the second thread and the time when the historical page coordinate position is last obtained is less than the preset time difference, the redrawing operation is not performed;
[0239] If the difference between the time when the page coordinate position is obtained by the second thread and the time when the historical page coordinate position is last obtained is greater than or equal to the preset time difference, the redrawing operation is performed;
[0240] The redrawing operation includes:
[0241] According to the page position coordinates, acquiring component data and the off-screen canvas through the second thread;
[0242] According to the component data, determining, by the second thread, updated drawing data corresponding to drawing the updated user component;
[0243] According to the updated drawing data, the second thread redraws in the off-screen canvas to obtain an updated user component.
[0244] As a possible implementation manner, the device further includes a detection unit, which is used to:
[0245] If drawing the user component based on the off-screen canvas by the second thread fails, generating the user component by the first thread;
[0246] In response to acquiring a third interaction operation for the user component, determining, through the first thread, an interaction component corresponding to the third interaction operation.
[0247] The present application also provides a computer device, which may be a server or a terminal device. The following will introduce the computer device provided by the present application from the perspective of hardware entity. Fig.11 The following is a schematic diagram of the server structure. Fig.12 Shown is a schematic diagram of the structure of the terminal equipment.
[0248] See also Fig.11 , which is a schematic diagram of a server structure provided in an embodiment of the present application. The server 1400 may have relatively large differences due to different configurations or performances, and may include one or more processors 1422, such as central processing units (CPU), memory 1432, one or more application programs 1442 or storage media 1430 (such as one or more massive storage devices) for data 1444. Among them, the memory 1432 and the storage medium 1430 may be temporary storage or permanent storage. The program stored in the storage medium 1430 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the processor 1422 may be configured to communicate with the storage medium 1430 to execute a series of instruction operations in the storage medium 1430 on the server 1400.
[0249] The server 1400 may also include one or more power supplies 1426, one or more wired or wireless network interfaces 1450, one or more input and output interfaces 1458, and / or one or more operating systems 1441, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.
[0250] The steps performed by the server in the above embodiment can be based on the Fig.11 The server structure shown.
[0251] The processor 1422 is used to perform the following steps:
[0252] In response to obtaining a first interaction operation for a user component, determining, through the first thread, a page coordinate position corresponding to the first interaction operation, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread;
[0253] Determine, by the second thread, from the user component, a target page area corresponding to the page coordinate position, wherein the target page area is one of the multiple page areas corresponding to the user component;
[0254] The auxiliary document object model node is moved to the target page area through the first thread, and the interactive component corresponding to the first interactive operation is displayed through the auxiliary document object model node. The auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
[0255] Optionally, the processor 1422 may also execute method steps of any specific implementation of the display method of the component in the embodiment of the present application.
[0256] See also Fig.12 , which is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Taking the terminal device as a smart phone as an example, Fig.12 The block diagram of the partial structure of the smart phone is shown, and the smart phone includes: a radio frequency (RF) circuit 1510, a memory 1520, an input unit 1530, a display unit 1540, a sensor 1550, an audio circuit 1560, a wireless fidelity (WiFi) module 1570, a processor 1580, and a power supply 1590. Those skilled in the art can understand that Fig.12 The structure of the smartphone shown in the figure does not constitute a limitation of the smartphone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0257] Combine the following Fig.12 A detailed introduction to the various components of a smartphone:
[0258] The RF circuit 1510 may be used for receiving and sending signals during information transmission or calls. In particular, after receiving the downlink information from the base station, it is sent to the processor 1580 for processing; in addition, the designed uplink data is sent to the base station.
[0259] The memory 1520 may be used to store software programs and modules. The processor 1580 implements various functional applications and data processing of the smartphone by running the software programs and modules stored in the memory 1520 .
[0260] The input unit 1530 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the smartphone. Specifically, the input unit 1530 may include a touch panel 1531 and other input devices 1532. The touch panel 1531, also known as a touch screen, can collect user touch operations on or near it and drive the corresponding connection device according to a pre-set program. In addition to the touch panel 1531, the input unit 1530 may also include other input devices 1532. Specifically, other input devices 1532 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, and the like.
[0261] The display unit 1540 may be used to display information input by the user or information provided to the user and various menus of the smartphone. The display unit 1540 may include a display panel 1541, and the display panel 1541 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0262] The smartphone may also include at least one sensor 1550, such as a light sensor, a motion sensor, and other sensors. As for other sensors that may be configured in the smartphone, such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., they will not be described in detail here.
[0263] The audio circuit 1560, the speaker 1561, and the microphone 1562 can provide an audio interface between the user and the smartphone. The audio circuit 1560 can transmit the received audio data to the speaker 1561 after converting the received audio data into an electrical signal, which is converted into a sound signal for output; on the other hand, the microphone 1562 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1560 and converted into audio data, and then the audio data is output to the processor 1580 for processing, and then sent to another smartphone through the RF circuit 1510, or the audio data is output to the memory 1520 for further processing.
[0264] The processor 1580 is the control center of the smartphone, and uses various interfaces and lines to connect various parts of the entire smartphone, and executes various functions of the smartphone and processes data by running or executing software programs and / or modules stored in the memory 1520, and calling data stored in the memory 1520. Optionally, the processor 1580 may include one or more processing units.
[0265] The smart phone also includes a power supply 1590 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 1580 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption management.
[0266] Although not shown, the smartphone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.
[0267] In the embodiment of the present application, the memory 1520 included in the smart phone can store a computer program and transmit the computer program to the processor.
[0268] The processor 1580 included in the smart phone can execute the display method of the component provided in the above embodiment according to the instructions in the computer program.
[0269] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program, wherein the computer program is used to execute the display method of the component provided in the above embodiment.
[0270] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the display method of the component provided in various optional implementations of the above aspects.
[0271] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the above program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the above storage medium can be at least one of the following media: read-only memory (English: Read-Only Memory, abbreviated: ROM), RAM, magnetic disk or optical disk, etc. Various media that can store computer programs.
[0272] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0273] It should be noted that each embodiment in this specification is described in a progressive manner, and the same and similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiments. The device and system embodiments described above are merely schematic, in which the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0274] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a technician familiar with the technical field within the technical scope disclosed in the present application should be included in the protection scope of the present application. Based on the implementation methods provided in the above aspects, the present application can also be further combined to provide more implementation methods. Therefore, the protection scope of the present application should be based on the protection scope of the claims.< / canvas>
Claims
1. A method for displaying a component, characterized in that: The method is applied to a device running a first thread and a second thread, the first thread and the second thread are different threads, and the second thread is used to execute a task without interfering with the first thread. The method includes: In response to obtaining a first interaction operation for a user component, determining, through the first thread, a page coordinate position corresponding to the first interaction operation, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread; Determine, by the second thread, from the user component, a target page area corresponding to the page coordinate position, wherein the target page area is one of the multiple page areas corresponding to the user component; The auxiliary document object model node is moved to the target page area through the first thread, and the interactive component corresponding to the first interactive operation is displayed through the auxiliary document object model node. The auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
2. The method according to claim 1, characterized in that The method further comprises: Acquire an initial component data set and a total page area size through the second thread, wherein the structure of the initial component data set is a tree structure; By using the second thread, a level identifier is added to each component data included in the initial component data set, and a level height of each level is set to obtain a component data set, wherein component data at the same level have the same level height; According to the total area size of the page, the level identifier and the level height, determining, by the second thread, the number of displayable component data from the component data set; According to the number of displayable component data, obtaining a displayable component data subset from the component data set; The user component is obtained by drawing in the off-screen canvas through the second thread according to the displayable component data subset.
3. The method according to claim 2, characterized in that The method further comprises: If the first interactive operation is a scrolling operation, determining a scrolling distance based on the page coordinate position through the second thread; Determining, by the second thread, the amount of component data skipped by the scrolling operation according to the scrolling distance and the level heights of the various levels; According to the amount of component data skipped by the scrolling operation, acquiring an updated displayable component data subset from the component data set through the second thread; According to the updated displayable component data subset, drawing is performed in the off-screen canvas by the second thread to obtain a user component corresponding to the scrolling operation.
4. The method according to claim 1, characterized in that The method further comprises: Acquire component data and off-screen canvas through the second thread; According to the component data, determining, by the second thread, drawing data for drawing the user component; According to the drawing data, the second thread draws on the off-screen canvas to obtain the user component; The user component is displayed.
5. The method according to claim 4, characterized in that The obtaining component data through the second thread includes: In response to the upload operation of acquiring the component data, acquiring the component data through the first thread; sending the component data to the second thread through the first thread; or, In response to obtaining a request including the component data, obtaining the request by the second thread; The component data is obtained through the request.
6. The method according to claim 4, characterized in that The acquiring the off-screen canvas through the second thread includes: Creating an initial canvas through the first thread, wherein the initial canvas is coupled to the first thread; Converting the initial canvas through the first thread to obtain the off-screen canvas, where the off-screen canvas is decoupled from the first thread; The off-screen canvas is sent to the second thread through the first thread.
7. The method according to claim 4, characterized in that The component data includes component source data and component configuration data, and the method further includes: If the user component is destroyed, deleting the component source data through the second thread; If the second thread obtains the user component based on the component configuration data and the off-screen canvas drawing, the component configuration data is deleted through the second thread.
8. The method according to claim 1, characterized in that: The second thread includes a first sub-thread and a second sub-thread, the first sub-thread is used to obtain the user component based on the off-screen canvas drawing, and the determining, by the second thread, from the user component a target page area corresponding to the page coordinate position includes: The target page area corresponding to the page coordinate position is determined from the user component through the second sub-thread.
9. The method according to claim 1, characterized in that: In response to acquiring a first interactive operation for a user component, determining, by the first thread, a page coordinate position corresponding to the first interactive operation, includes: In response to obtaining a first interactive operation for the user component, setting a first operation delay period through the first thread, where a start time of the first operation delay period is a time when the first interactive operation is obtained; If a second interactive operation for the user component is obtained during the first operation delay period, the timing of the first operation delay period is canceled, and a second operation delay period is set through the first thread, and the start time of the second operation delay period is the time when the second interactive operation is obtained; If the second interactive operation for the user component is not acquired during the first operation delay period, then at the end of the first operation delay period, the page coordinate position corresponding to the first interactive operation is determined through the first thread.
10. The method according to claim 1, characterized in that The method further comprises: If the difference between the time when the page coordinate position is obtained by the second thread and the time when the historical page coordinate position is last obtained is less than the preset time difference, the redrawing operation is not performed; If the difference between the time when the page coordinate position is obtained by the second thread and the time when the historical page coordinate position is last obtained is greater than or equal to the preset time difference, the redrawing operation is performed; The redrawing operation includes: According to the page position coordinates, acquiring component data and the off-screen canvas through the second thread; According to the component data, determining, by the second thread, updated drawing data corresponding to drawing the updated user component; According to the updated drawing data, the second thread redraws in the off-screen canvas to obtain an updated user component.
11. The method according to any one of claims 1 to 10, characterized in that: The method further comprises: If drawing the user component based on the off-screen canvas by the second thread fails, generating the user component by the first thread; In response to acquiring a third interaction operation for the user component, determining, through the first thread, an interaction component corresponding to the third interaction operation.
12. A display device of a component, characterized in that: The device is built in a device running a first thread and a second thread, the first thread and the second thread are different threads, and the second thread is used to perform a task without interfering with the first thread. The device includes: a page coordinate position determination unit, a target page area determination unit, and an interactive component display unit; The page coordinate position determining unit is configured to determine, in response to obtaining a first interactive operation for a user component, a page coordinate position corresponding to the first interactive operation through the first thread, wherein the user component is drawn by the second thread based on an off-screen canvas, and the off-screen canvas is a canvas decoupled from the first thread; The target page area determination unit is used to determine, through the second thread, a target page area corresponding to the page coordinate position from the user component, wherein the target page area is one of the multiple page areas corresponding to the user component; The interactive component display unit is used to move the auxiliary document object model node to the target page area through the first thread, and display the interactive component corresponding to the first interactive operation through the auxiliary document object model node, the auxiliary document object model node is a document object model node established by the first thread, and the auxiliary document object model node is located in the upper layer of the off-screen canvas.
13. A computer device, characterized in that: The computer device comprises a processor and a memory: The memory is used to store a computer program and transmit the computer program to the processor; The processor is configured to execute the method according to any one of claims 1 to 11 according to the computer program.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method according to any one of claims 1 to 11.
15. A computer program product comprising a computer program, characterized in that When the method is executed on a computer device, the computer device is enabled to execute the method according to any one of claims 1 to 11.
