Data processing method, device and equipment and readable storage medium

Through the method of asynchronous processing and sub-thread parsing data, combined with WebWorker and WebAssembly, the problem of long CPU calculation time in Web page data processing is solved, and the data loading performance and page interaction fluency are improved.

CN118567734APending Publication Date: 2024-08-30GLODON CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310194906.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Existing web page data processing methods can easily cause the CPU calculation time to be too long when processing large amounts of data, causing page interaction to freeze or crash. In addition, the multi-threaded processing of WebWorker is also restricted by the main thread bottleneck, making it difficult to maintain the smoothness of page interaction.

Method used

Data requests are sent asynchronously through the main thread and stored in the event queue. After the synchronization task is completed, the sub-thread is started to parse the data and the results are stored back in the event queue. The main thread processes them step by step to avoid main thread blocking. WebWorker and WebAssembly are used to accelerate data parsing. .

Benefits of technology

It improves the data loading performance, prevents the main thread from blocking, ensures smooth page interaction, reduces the amount of CPU calculation through parallel parsing and double cache queue processing, and improves the interactive experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567734A
    Figure CN118567734A
Patent Text Reader

Abstract

The invention discloses a data processing method, device and equipment and a readable storage medium, and the method comprises the steps: when a data processing instruction is received, sending a data request to a server through a main thread, and asynchronously storing original data returned by the server into an event queue; when it is detected that all the synchronization tasks of the main thread are executed, obtaining the original data from the event queue through the main thread; starting a corresponding sub-thread for the original data through the main thread, analyzing the original data into result data through the sub-thread, and storing the result data into the event queue; when it is detected that all the synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread, and processing the result data; when a processing end message is detected, continuing to execute the synchronization task through the main thread; the data processing performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, equipment and readable storage medium for processing data. Background Art

[0002] There are two main existing data processing methods based on Web pages: one is synchronous processing, that is, after obtaining multiple data from the data server, synchronously processing the data one by one; the other is multi-threaded processing using WebWorker, that is, transferring the multiple data obtained from the data server to multiple sub-threads in WebWorker for data processing. However, the synchronous processing method has the following disadvantages: when the amount of data obtained from the data server is large, synchronous processing of these data requires a lot of CPU computing time, which is easy to cause interaction jams, page pseudo-death, and even page crashes in severe cases; in addition, using the multi-threaded processing method of WebWorker, although the operation of WebWorker will not block the main thread, it is still restricted by the bottleneck of the main thread. If WebWorker frequently interacts with the main thread, the main thread may still block the page due to the need to frequently process interactive operations. In addition, when the amount of data obtained from the data server is large, the data transmitted back to the main thread from WebWorker will accumulate, and the main thread needs to synchronously process the returned data, which will still consume a lot of CPU computing time, resulting in unsmooth page interaction and jams. Therefore, how to improve data loading performance and how to maintain the interactive fluency of web pages have become technical problems that technical personnel in this field need to solve urgently. Summary of the invention

[0003] The object of the present invention is to provide a method, device, equipment and readable storage medium for processing data, which can improve the loading performance of Web page data and ensure the interactive fluency of Web pages.

[0004] According to one aspect of the present invention, there is provided a method for processing data, the method comprising:

[0005] When a data processing instruction is received, a data request is sent to the server through the main thread, and the original data returned by the server is asynchronously stored in the event queue;

[0006] When it is detected that all synchronization tasks of the main thread are executed, obtaining the original data from the event queue through the main thread;

[0007] Start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue;

[0008] When it is detected that all synchronization tasks of the main thread are executed, the result data is obtained from the event queue through the main thread, and the result data is processed;

[0009] When the processing end message is detected, the synchronization task continues to be executed through the main thread.

[0010] Optionally, starting a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue, includes:

[0011] Start a corresponding WebWorker child thread for the original data through the main thread;

[0012] Loading a WebAssembly file through the WebWorker child thread, and parsing the original data into result data by instantiating the code in the WebAssembly file;

[0013] The result data is stored in the event queue.

[0014] Optionally, when it is detected that all synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread and processing the result data include:

[0015] Obtaining the result data from the event queue through the main thread, and storing the result data in a preset receiving queue;

[0016] Determine whether the preset processing queue is empty;

[0017] If yes, set the empty processing queue as the new receiving queue, set the receiving queue containing the result data as the new processing queue, and send a processing end message;

[0018] If not, the result data in the processing queue that is not empty is processed, and a processing end message is sent after the processing is completed.

[0019] Optionally, obtaining the result data from the event queue through the main thread and storing the result data in a preset receiving queue includes:

[0020] Determine whether the main thread obtains result data from the event queue for the first time;

[0021] If yes, storing the result data obtained for the first time in any one of the two preset cache queues, setting the cache queue storing the result data obtained for the first time as a processing queue, and setting the other cache queue as a receiving queue;

[0022] If not, the result data is stored in the set receiving queue.

[0023] Optionally, the processing of result data in a non-empty processing queue and sending a processing end message after the processing is completed include:

[0024] Obtaining a set amount of result data from the processing queue that is not empty, and processing the set amount of result data;

[0025] After the processing is completed, the set amount of result data is deleted from the non-empty processing queue;

[0026] An activation event is generated, the activation event is stored in the event queue, and a processing end message is sent; wherein the activation event is used to instruct the main thread to process the result data in the processing queue that is not empty.

[0027] Optionally, when it is detected that all synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread and processing the result data include:

[0028] Obtaining the result data from the event queue through the main thread, and storing the result data in a preset cache queue;

[0029] Determine whether there is a temporary queue;

[0030] If yes, process the result data in the temporary queue and send a processing end message after the processing is completed;

[0031] If not, a temporary queue is created, all result data in the cache queue is moved to the temporary queue, the result data in the temporary queue is processed, and a processing end message is sent after the processing is completed.

[0032] Optionally, the processing the result data in the temporary queue and sending a processing end message after the processing is completed includes:

[0033] Obtaining a set amount of result data from the temporary queue, and processing the set amount of result data;

[0034] After the processing is completed, the set amount of result data is deleted from the temporary queue;

[0035] Generate an activation event, store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the temporary queue.

[0036] In order to achieve the above object, the present invention further provides a device for processing data, the device comprising:

[0037] A sending module, for sending a data request to a server through a main thread when receiving a data processing instruction, and asynchronously storing the original data returned by the server into an event queue;

[0038] An acquisition module, configured to acquire the original data from the event queue through the main thread when it is detected that all synchronization tasks of the main thread are executed;

[0039] A parsing module, configured to start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue;

[0040] A processing module, configured to obtain the result data from the event queue through the main thread and process the result data when it is detected that all synchronization tasks of the main thread are executed completely;

[0041] The execution module is used to continue executing the synchronization task through the main thread when a processing end message is detected.

[0042] In order to achieve the above-mentioned purpose, the present invention also provides a computer device, which specifically includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method for processing data introduced above when executing the computer program.

[0043] In order to achieve the above object, the present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for processing data introduced above are implemented.

[0044] The method, device, equipment and readable storage medium for processing data provided by the present invention accelerate the parsing of data, improve the data loading performance, and ensure the interactive fluency of the page. In the present invention, multiple sub-threads can be started to parse the original data in parallel, thereby preventing the main thread from being blocked and improving the interactive experience; in addition, the main thread only obtains a small amount of result data from the event queue for processing each time, ensuring that the main thread only processes a limited amount of result data each time it loops, solving the problem of interactive jams caused by excessive CPU calculations due to data accumulation. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0046] Figure 1 An optional flowchart of the method for processing data provided in Example 1;

[0047] Figure 2 Another optional flowchart of the method for processing data provided in Embodiment 2;

[0048] Figure 3 A schematic diagram of another optional flow chart of the method for processing data provided in Embodiment 2;

[0049] Figure 4 A schematic diagram of an optional structure of a device for processing data provided in Embodiment 3;

[0050] Figure 5 A schematic diagram of an optional hardware architecture of a computer device provided in Example 4. DETAILED DESCRIPTION

[0051] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0052] Embodiment 1

[0053] The embodiment of the present invention provides a method for processing data, which is applied to a user terminal browser, such as Figure 1 As shown, the method specifically comprises the following steps:

[0054] Step S101: when a data processing instruction is received, a data request is sent to a server through a main thread, and the original data returned by the server is asynchronously stored in an event queue.

[0055] Among them, the data processing instruction is triggered by the user through the user-side browser. When the data processing request is received, an asynchronous operation is used to send a data request to the corresponding data server. Since the data request is an asynchronous operation, there is no need to wait for the data to be returned after the data request is sent, and the synchronous task in the main thread of the browser can continue to be executed.

[0056] It should be noted that the main thread is a JS engine thread allocated to JavaScript (i.e., JS) by a rendering process of the user-side browser, and all tasks of the rendering process will be executed through the main thread; in addition, the executed tasks can be divided into synchronous tasks and asynchronous tasks; synchronous tasks refer to tasks queued for execution on the main thread, and the next synchronous task can only be executed after the previous synchronous task is completed; and asynchronous tasks refer to tasks that will not enter the main thread at the beginning but are delegated by the JavaScript main thread to the host environment (browser, Node.js, etc.) for execution. When the asynchronous task is executed, the callback function corresponding to the asynchronous task will be added to the task queue and wait for execution. When all the synchronous tasks of the main thread are executed, the main thread reads the callback function of the asynchronous task from the task queue, puts it into the execution stack and executes it in sequence.

[0057] Specifically, the asynchronously storing the original data returned by the server into the event queue includes:

[0058] Step A1: receiving the original data returned by the server, and encapsulating the original data into an original event;

[0059] Step A2: Store the original event in a JavaScript event queue.

[0060] It should be noted that, in the process of executing the above steps A1 to A2, the main thread continues to execute the synchronization task until all the synchronization tasks are completed, and then executes the following step S102.

[0061] Step S102: when it is detected that all synchronization tasks of the main thread are executed, the original data is obtained from the event queue through the main thread.

[0062] Specifically, step S102 includes:

[0063] When it is detected that all synchronization tasks of the main thread are executed, the original event is obtained from the JavaScript event queue through the main thread, and the original data is obtained from the original event.

[0064] Step S103: starting a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue.

[0065] Specifically, step S103 includes:

[0066] Step B1: starting a corresponding WebWorker sub-thread for the original data through the main thread, and transferring the original data to the WebWorker sub-thread;

[0067] Step B2: Loading the WebAssembly file through the WebWorker child thread, and parsing the original data into result data by instantiating the code in the WebAssembly file;

[0068] In this embodiment, WebWorker parses the original data into result data by using WebAssembly; wherein the result data is a data structure that can be processed by the lightweight engine.

[0069] Step B3: Store the result data in the event queue.

[0070] Furthermore, the step B3 specifically includes:

[0071] The result data is encapsulated as a result event, and the result event is stored in the JavaScript event queue.

[0072] It should be noted that, during the execution of the above steps B2 to B3, the main thread continues to execute the synchronization task until all the synchronization tasks are completed, and then executes the following step S104.

[0073] It should be noted that WebWorker is defined by the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG) as a JavaScript script. WebWorker is JavaScript running in the background and will not affect the performance of the page. In addition, WebAssembly (WASM for short) is a virtual instruction set architecture (virtual ISA). The overall architecture includes the core ISA definition, binary encoding, definition and execution of program semantics, and application programming interfaces (WebAssembly API) for different embedded environments (such as Web). Its initial goal is to compile programs written in languages ​​​​such as C / C++ and run them better on the Web platform while ensuring security and running speeds close to native applications.

[0074] In this embodiment, since the WebWorker+WebAssembly method is used to parse data, the occurrence of page freezes and interactive freezes caused by the synchronous data processing method in the prior art is avoided; in addition, when N raw data are requested from the data server, N WebWorkers can be set to process the N raw data in parallel with multi-threading, thereby preventing the main thread from being blocked and improving the interactive experience; in addition, WebAssembly is introduced into WebWorker to parse the raw data. Since WebAssembly is bytecode, compared with JavaScript, WebAssembly's instructions are closer to machine code and execute faster, making data parsing more efficient. Therefore, since WebWorker can process multiple copies of data in parallel, and WebAssembly can speed up data parsing, the combination of the two shortens the time consumption of data processing and significantly improves loading performance.

[0075] Step S104: when it is detected that all synchronization tasks of the main thread are executed, the main thread obtains the result data from the event queue and processes the result data.

[0076] Specifically, when it is detected that all synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread includes:

[0077] When it is detected that all synchronization tasks of the main thread are executed, the result event is obtained from the JavaScript event queue through the main thread, and the result data is obtained from the result event.

[0078] Furthermore, the step S104 specifically includes:

[0079] Step C1: obtaining the result data from the event queue through the main thread, and storing the result data in a preset receiving queue;

[0080] Step C2: Determine whether the preset processing queue is empty, if so, execute step C3, if not, execute step C4;

[0081] Step C3: setting the empty processing queue as a new receiving queue, setting the receiving queue containing the result data as a new processing queue, and sending a processing end message;

[0082] Step C4: Process the result data in the processing queue that is not empty, and send a processing end message after the processing is completed.

[0083] It should be noted that in this embodiment, a dual cache queue approach is adopted to process the result data. Specifically, two cache queues are created in advance, one of the cache queues is set as a receiving queue, and the other cache queue is set as a processing queue; wherein, the result data in the receiving queue is only cached but not processed, while the result data in the processing queue needs to be processed.

[0084] Furthermore, the step C1 specifically includes:

[0085] Determine whether the main thread obtains result data from the event queue for the first time;

[0086] If yes, storing the result data obtained for the first time in any one of the two preset cache queues, setting the cache queue storing the result data obtained for the first time as a processing queue, and setting the other cache queue as a receiving queue;

[0087] If not, the result data is stored in the set receiving queue.

[0088] Furthermore, the step C4 specifically includes:

[0089] Step C41: acquiring a set amount of result data from the processing queue that is not empty, and processing the set amount of result data;

[0090] Step C42: after the processing is completed, the set amount of result data is deleted from the processing queue that is not empty;

[0091] Step C43: asynchronously generate an activation event, asynchronously store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the processing queue that is not empty.

[0092] In this embodiment, after the main thread has executed all synchronization tasks, it obtains the activation event from the event queue and processes a set amount of result data in the processing queue according to the activation event.

[0093] Step S105: When the processing end message is detected, the synchronization task continues to be executed through the main thread, and step S101 is repeatedly executed.

[0094] In this embodiment, the main thread continuously loops according to the above steps S101 to S105 to continuously process data.

[0095] In this embodiment, a double cache queue (i.e., a receiving queue and a processing queue) is used to process the result data returned from the WebWorker child threads in batches, ensuring that the main thread only processes a limited amount of result data each time it loops, thereby solving the problem of excessive CPU calculations due to data accumulation, which causes interaction jams.

[0096] In addition, this embodiment also provides another way to process the result data.

[0097] Specifically, the step S104 includes:

[0098] Step D1: obtaining the result data from the event queue through the main thread, and storing the result data in a preset cache queue;

[0099] Step D2: Determine whether there is a temporary queue, if yes, execute step D3, if no, execute step D4;

[0100] Step D3: Process the result data in the temporary queue and send a processing end message after the processing is completed;

[0101] Step D4: Create a temporary queue, move all result data in the cache queue to the temporary queue, process the result data in the temporary queue, and send a processing end message after the processing is completed.

[0102] It should be noted that after the result data is moved from the cache queue to the temporary queue, the cache queue is empty; in addition, a temporary queue will only be temporarily created when there is result data that needs to be processed in the cache queue to process the result data through the temporary queue. After all the result data in the temporary queue have been processed, the temporary queue will be deleted.

[0103] Further, the processing the result data in the temporary queue and sending a processing end message after the processing is completed specifically includes:

[0104] Step E1: obtaining a set amount of result data from the temporary queue, and processing the set amount of result data;

[0105] Step E2: after the processing is completed, the set amount of result data is deleted from the temporary queue;

[0106] Step E3: asynchronously generate an activation event, asynchronously store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the temporary queue.

[0107] This embodiment provides a data scheduling and parsing method based on WebWorker, WebAssembly, and dual-buffer queues, which accelerates the parsing of data, improves data loading performance, and ensures the interactive fluency of the page. In this embodiment, multiple child threads can be started to parse the original data in parallel, thereby preventing the main thread from being blocked and improving the interactive experience; in addition, the main thread only obtains a small amount of data from the cache queue for processing each time, ensuring that the main thread only processes limited result data each time it loops, solving the problem of interactive jams caused by excessive CPU calculations due to data accumulation, and using the exchange mechanism of the dual-buffer queue to reduce the copying and clearing operations of queue data.

[0108] Embodiment 2

[0109] The embodiment of the present invention provides a method for processing data, taking rendering of BIM (Building Information Modeling, Building Information Modeling) as an example, Figure 2 As shown, the method is applied in a user-side browser, and the method specifically includes the following steps:

[0110] Step S201: When an instruction for rendering a BIM model is received, a data request is sent to a server through a main thread.

[0111] Among them, the instruction is triggered by the user through the user-side browser (for example, a click operation). After receiving the instruction, a data request for requesting BIM model data is sent to the data server through the main thread. The data request is an asynchronous operation. After the data request is sent, there is no need to wait for the data to be returned, and the synchronization task in the main thread continues to be executed.

[0112] Step S202: Asynchronously encapsulating the binary data block (BinaryData Block) of the BIM model returned by the server into an original event, and storing the original event in a JavaScript event queue.

[0113] Step S203: when it is detected that all synchronization tasks of the main thread are executed, the main thread obtains the original event from the JavaScript event queue to obtain the binary data block.

[0114] Step S204: starting a corresponding WebWorker child thread for the binary data block through the main thread, and transferring the binary data block to the WebWorker child thread.

[0115] Step S205: Load the WebAssembly file through the WebWorker child thread, and parse the binary data block into result data of a data structure that can be processed by the lightweight engine by instantiating the code in the WebAssembly file.

[0116] Step S206: Encapsulate the result data into a result event, and store the result event in the JavaScript event queue.

[0117] It should be noted that the above steps S205 and S206 are not executed by the main thread, but are executed asynchronously.

[0118] Step S207: when it is detected that all synchronization tasks of the main thread are executed, the result event is obtained from the JavaScript event queue through the main thread to obtain the result data.

[0119] Among them, the result data is lightweight data obtained after parsing the binary data block, and one or more components in the BIM model can be constructed based on the result data; a BIM model is composed of multiple components, each binary data block corresponds to one or more components, and when all components in a BIM model are constructed, the BIM model can be rendered.

[0120] Step S208: storing the result data in a receiving queue of two preset cache queues through the main thread.

[0121] It should be noted that in this embodiment, a dual cache queue approach is adopted to process the result data. Specifically, two cache queues are created in advance, one of the cache queues is set as a receiving queue, and the other cache queue is set as a processing queue; wherein, the result data in the receiving queue is only cached but not processed, while the result data in the processing queue needs to be processed.

[0122] Specifically, the step S208 includes:

[0123] Determine whether the main thread obtains result data from the event queue for the first time;

[0124] If yes, storing the result data obtained for the first time in any one of the two preset cache queues, setting the cache queue storing the result data obtained for the first time as a processing queue, and setting the other cache queue as a receiving queue;

[0125] If not, the result data is stored in the set receiving queue.

[0126] Step S209: determining whether the processing queues in the two preset cache queues are empty through the main thread, if so, executing step S210, if not, executing step S212;

[0127] Step S210: swapping two preset buffer queues to set the original receiving queue as the new processing queue and the original processing queue as the new receiving queue;

[0128] Step S211: Continue to execute the synchronization task through the main thread to start the next cycle, that is, re-execute step S201.

[0129] Step S212: Processing a set amount of result data in the processing queue through the main thread, and deleting the processed result data from the processing queue.

[0130] In step S212, one or more components in the BIM model are constructed based on the result data.

[0131] Step S213: asynchronously generate an activation event through the main thread, store the activation event in the event queue, and continue to execute the synchronization task through the main thread to start the next cycle, that is, re-execute step S201.

[0132] The activation event is used to instruct the main thread to process the result data in the non-empty processing queue.

[0133] In this embodiment, after the main thread has executed all synchronization tasks, it obtains the activation event from the event queue and processes a set amount of result data in the processing queue according to the activation event.

[0134] As an alternative, Figure 3 As shown, the above steps S208 to S213 can be replaced by the following steps S208' to S214':

[0135] Step S208': storing the result data in a preset cache queue through the main thread.

[0136] It should be noted that, different from the above steps S208 to S213, there is only one cache queue instead of two cache queues.

[0137] Step S209': determine whether there is a temporary queue through the main thread, if so, execute step S210', if not, execute step S214'.

[0138] Step S210': determine whether the temporary queue is empty through the main thread, if so, execute step S211', if not, execute step S212'.

[0139] Step S211': Delete the temporary queue, and continue to execute the synchronization task through the main thread to start the next cycle, that is, re-execute step S201.

[0140] Step S212': Process a set amount of result data in the temporary queue through the main thread, delete the processed result data from the temporary queue, and execute step S213'.

[0141] Step S213': asynchronously generate an activation event through the main thread, store the activation event in the JavaScript event queue, and continue to execute the synchronization task through the main thread to start the next cycle, that is, re-execute step S201.

[0142] Step S214': create a temporary queue, move all result data in the cache queue to the temporary queue, process a set amount of result data in the temporary queue through the main thread, delete the processed result data from the temporary queue, and execute step S213'.

[0143] The activation event is used to instruct the main thread to process the result data in the temporary queue.

[0144] Embodiment 3

[0145] The embodiment of the present invention provides a device for processing data, such as Figure 4 As shown, the device specifically includes the following components:

[0146] The sending module 401 is used to send a data request to the server through the main thread when receiving a data processing instruction, and asynchronously store the original data returned by the server into the event queue;

[0147] An acquisition module 402 is used to acquire the original data from the event queue through the main thread when it is detected that all synchronization tasks of the main thread are executed;

[0148] A parsing module 403 is used to start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue;

[0149] The processing module 404 is used to obtain the result data from the event queue through the main thread and process the result data when it is detected that all synchronization tasks of the main thread are executed.

[0150] The execution module 405 is used to continue executing the synchronization task through the main thread when a processing end message is detected.

[0151] Specifically, the parsing module 403 is used to:

[0152] Start a corresponding WebWorker child thread for the original data through the main thread;

[0153] Loading a WebAssembly file through the WebWorker child thread, and parsing the original data into result data by instantiating the code in the WebAssembly file;

[0154] The result data is stored in the event queue.

[0155] Furthermore, the processing module 404 specifically includes:

[0156] A first storage unit, used for acquiring the result data from the event queue through the main thread, and storing the result data in a preset receiving queue;

[0157] A first judging unit, used to judge whether a preset processing queue is empty;

[0158] The first processing unit is used to set the empty processing queue as a new receiving queue, set the receiving queue containing the result data as a new processing queue, and send a processing end message; if not, process the result data in the processing queue that is not empty, and send a processing end message after the processing is completed.

[0159] Furthermore, the first storage unit is specifically used for:

[0160] Determine whether the main thread obtains result data from the event queue for the first time;

[0161] If yes, storing the result data obtained for the first time in any one of the two preset cache queues, setting the cache queue storing the result data obtained for the first time as a processing queue, and setting the other cache queue as a receiving queue;

[0162] If not, the result data is stored in the set receiving queue.

[0163] In addition, the first processing unit is specifically configured to:

[0164] Obtaining a set amount of result data from the processing queue that is not empty, and processing the set amount of result data;

[0165] After the processing is completed, the set amount of result data is deleted from the non-empty processing queue;

[0166] An activation event is generated, the activation event is stored in the event queue, and a processing end message is sent; wherein the activation event is used to instruct the main thread to process the result data in the processing queue that is not empty.

[0167] In addition, the processing module 404 may further include:

[0168] A second storage unit, used for acquiring the result data from the event queue through the main thread, and storing the result data in a preset cache queue;

[0169] A second determination unit, used to determine whether a temporary queue exists;

[0170] The second processing unit is used to process the result data in the temporary queue if yes and send a processing end message after the processing is completed; if no, create a temporary queue, move all the result data in the cache queue to the temporary queue, process the result data in the temporary queue, and send a processing end message after the processing is completed.

[0171] Wherein, the second processing unit is specifically used for:

[0172] Obtaining a set amount of result data from the temporary queue, and processing the set amount of result data;

[0173] After the processing is completed, the set amount of result data is deleted from the temporary queue;

[0174] Generate an activation event, store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the temporary queue.

[0175] Embodiment 4

[0176] This embodiment also provides a computer device, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. Figure 5 As shown, the computer device 50 of this embodiment includes at least but not limited to: a memory 501 and a processor 502 that can communicate with each other via a system bus. It should be noted that Figure 5Only computer device 50 is shown with components 501 - 502 , but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0177] In this embodiment, the memory 501 (i.e., a readable storage medium) includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 501 may be an internal storage unit of the computer device 50, such as a hard disk or a memory of the computer device 50. In other embodiments, the memory 501 may also be an external storage device of the computer device 50, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. equipped on the computer device 50. Of course, the memory 501 may also include both the internal storage unit and the external storage device of the computer device 50. In this embodiment, the memory 501 is generally used to store the operating system and various application software installed on the computer device 50. In addition, the memory 501 may also be used to temporarily store various data that have been output or are to be output.

[0178] In some embodiments, the processor 502 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 502 is generally used to control the overall operation of the computer device 50 .

[0179] Specifically, in this embodiment, the processor 502 is used to execute the program of the method for processing data stored in the memory 501, and the program of the method for processing data is implemented as follows when being executed:

[0180] When a data processing instruction is received, a data request is sent to the server through the main thread, and the original data returned by the server is asynchronously stored in the event queue;

[0181] When it is detected that all synchronization tasks of the main thread are executed, obtaining the original data from the event queue through the main thread;

[0182] Start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue;

[0183] When it is detected that all synchronization tasks of the main thread are executed, the result data is obtained from the event queue through the main thread, and the result data is processed;

[0184] When the processing end message is detected, the synchronization task continues to be executed through the main thread.

[0185] The specific implementation process of the above method steps can be found in Example 1, and this embodiment will not be repeated here.

[0186] Embodiment 5

[0187] This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored. When the computer program is executed by a processor, the following method steps are implemented:

[0188] When a data processing instruction is received, a data request is sent to the server through the main thread, and the original data returned by the server is asynchronously stored in the event queue;

[0189] When it is detected that all synchronization tasks of the main thread are executed, obtaining the original data from the event queue through the main thread;

[0190] Start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue;

[0191] When it is detected that all synchronization tasks of the main thread are executed, the result data is obtained from the event queue through the main thread, and the result data is processed;

[0192] When the processing end message is detected, the synchronization task continues to be executed through the main thread.

[0193] The specific implementation process of the above method steps can be found in Example 1, and this embodiment will not be repeated here.

[0194] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0195] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0196] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0197] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for processing data, characterized in that: The method comprises: When a data processing instruction is received, a data request is sent to the server through the main thread, and the original data returned by the server is asynchronously stored in the event queue; When it is detected that all synchronization tasks of the main thread are executed, obtaining the original data from the event queue through the main thread; Start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue; When it is detected that all synchronization tasks of the main thread are executed, the result data is obtained from the event queue through the main thread, and the result data is processed; When the processing end message is detected, the synchronization task continues to be executed through the main thread.

2. The method for processing data according to claim 1, characterized in that: The method of starting a corresponding sub-thread for the original data through the main thread, parsing the original data into result data through the sub-thread and storing the result data in the event queue, includes: Start a corresponding WebWorker child thread for the original data through the main thread; Loading a WebAssembly file through the WebWorker child thread, and parsing the original data into result data by instantiating the code in the WebAssembly file; The result data is stored in the event queue.

3. The method for processing data according to claim 1, characterized in that: When it is detected that all synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread and processing the result data include: Obtaining the result data from the event queue through the main thread, and storing the result data in a preset receiving queue; Determine whether the preset processing queue is empty; If yes, set the empty processing queue as the new receiving queue, set the receiving queue containing the result data as the new processing queue, and send a processing end message; If not, the result data in the processing queue that is not empty is processed, and a processing end message is sent after the processing is completed.

4. The method for processing data according to claim 3, characterized in that: The obtaining the result data from the event queue through the main thread and storing the result data in a preset receiving queue includes: Determine whether the main thread obtains result data from the event queue for the first time; If yes, storing the result data obtained for the first time in any one of the two preset cache queues, setting the cache queue storing the result data obtained for the first time as a processing queue, and setting the other cache queue as a receiving queue; If not, the result data is stored in the set receiving queue.

5. The method for processing data according to claim 3, characterized in that: The processing of the result data in the processing queue that is not empty and sending a processing end message after the processing is completed include: Obtaining a set amount of result data from the processing queue that is not empty, and processing the set amount of result data; After the processing is completed, the set amount of result data is deleted from the non-empty processing queue; Generate an activation event, store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the processing queue that is not empty.

6. The method for processing data according to claim 1, characterized in that: When it is detected that all synchronization tasks of the main thread are executed, obtaining the result data from the event queue through the main thread and processing the result data include: Obtaining the result data from the event queue through the main thread, and storing the result data in a preset cache queue; Determine whether there is a temporary queue; If yes, process the result data in the temporary queue and send a processing end message after the processing is completed; If not, a temporary queue is created, all result data in the cache queue is moved to the temporary queue, the result data in the temporary queue is processed, and a processing end message is sent after the processing is completed.

7. The method for processing data according to claim 6, characterized in that: The step of processing the result data in the temporary queue and sending a processing completion message after the processing is completed includes: Obtaining a set amount of result data from the temporary queue, and processing the set amount of result data; After the processing is completed, the set amount of result data is deleted from the temporary queue; Generate an activation event, store the activation event in the event queue, and send a processing end message; wherein the activation event is used to instruct the main thread to process the result data in the temporary queue.

8. A device for processing data, characterized in that: The device comprises: A sending module, for sending a data request to a server through a main thread when receiving a data processing instruction, and asynchronously storing the original data returned by the server into an event queue; An acquisition module, configured to acquire the original data from the event queue through the main thread when it is detected that all synchronization tasks of the main thread are executed; A parsing module, configured to start a corresponding sub-thread for the original data through the main thread, so as to parse the original data into result data through the sub-thread and store the result data in the event queue; A processing module, configured to obtain the result data from the event queue through the main thread and process the result data when it is detected that all synchronization tasks of the main thread are executed completely; The execution module is used to continue executing the synchronization task through the main thread when a processing end message is detected.

9. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.