Task execution method and device, equipment and storage medium
By creating multi-threads to execute Wasm format target files in parallel in the browser, the problem of insufficient performance when the browser engine executes Wasm language code is solved, and task execution efficiency is significantly improved.
Patent Information
- Application Number
- CN202310332837.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-23
- Publication Date
- 2024-09-24
AI Technical Summary
In the existing technology, the browser engine cannot achieve maximum execution performance when executing Wasm language code, resulting in task execution efficiency that cannot meet usage requirements.
During the running of the browser, it sends a task request message to the server, receives the Wasm format target file for parallel execution, and creates at least two worker threads based on the thread creation file to achieve multi-threaded parallel execution of the target file.
Through multi-threaded parallel execution, task execution efficiency is significantly improved to meet usage requirements. The overall performance is about 8 times higher than the JavaScript version.
Smart Images

Figure CN118689484A
Abstract
Description
Background Art
[0002] With the development of technology, there are many tasks running in browsers, including tasks that consume a lot of computing resources and computing time. Therefore, in order to improve the execution performance of browsers, it is proposed to use Rust language code to write the source code of tasks, which takes into account both development efficiency and execution efficiency. In order to ensure that tasks written in Rust language code can run smoothly in browsers, the source code needs to be compiled to generate executable files that match the browser.
[0003] Since Wasm language code has faster compilation and execution efficiency than JavaScript language code, in related technologies, tasks written in Rust language code are usually compiled into Wasm files, and the compiled Wasm files are run in the browser process.
[0004] However, Wasm language code is a programming language code between native machine code and high-level language code. Since current browser engines only have good execution performance for native machine code, when the compiled Wasm file is executed by the browser engine in the browser process, the maximum execution performance cannot be achieved, resulting in execution efficiency that cannot meet usage requirements.
[0005] Therefore, how to improve task execution performance and execution efficiency is a technical problem that needs to be solved at present. Summary of the invention
[0006] The embodiments of the present application provide a task execution method, apparatus, device and storage medium to improve task execution performance.
[0007] In a first aspect, an embodiment of the present application provides a task execution method, the method comprising:
[0008] During the operation of the browser, in response to a trigger operation on the browser, a task request message is sent to the server;
[0009] Receive a task response message fed back by the server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in a WebAssembly (Wasm) format that can be executed in parallel in a multi-threaded manner;
[0010] Create files based on threads and create at least two working threads;
[0011] Based on at least two working threads, multiple target tasks associated with the target file are executed in parallel.
[0012] In a second aspect, an embodiment of the present application provides a task execution device, the device comprising:
[0013] A sending unit, used to send a task request message to a server in response to a trigger operation on the browser during the operation of the browser;
[0014] A receiving unit, configured to receive a task response message fed back by the server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in Wasm format that can be executed in parallel in a multi-threaded manner;
[0015] A creation unit is used to create files based on threads and to create at least two working threads;
[0016] The execution unit is used to execute multiple target tasks associated with the target file in parallel based on at least two working threads.
[0017] In a possible implementation, the task response message further includes: a webpage response header with a webpage security policy set, and a file response header with a resource security policy set;
[0018] After receiving the task response message fed back by the server through the receiving unit, and before executing multiple target tasks associated with the target file in parallel based on at least two threads through the executing unit, the method is also used to:
[0019] Based on the webpage response header and the file response header, determine to load the resource file from the same source for the current webpage.
[0020] In a possible implementation, the resource file is obtained in the following manner:
[0021] Rewrite the single-thread source code associated with the trigger operation to obtain the multi-thread code associated with the trigger operation task;
[0022] Compile the multi-thread code to obtain a resource file; wherein the resource file includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and a calling file that calls the target file.
[0023] In a possible implementation, a single-thread source code is analyzed to determine the running state of the single-thread source code in a multi-thread environment;
[0024] Based on the running state, the single-thread source code is divided into the first type of code and the second type of code; wherein the first type of code represents normal operation in a multi-thread environment, and the second type of code represents disordered operation in a multi-thread environment;
[0025] Based on the first type of code, the internal variables of the multi-threaded running content are rewritten, and based on the second type of code, the external variables of the multi-threaded running content are rewritten to obtain the multi-threaded code.
[0026] In a possible implementation, compile parameters and compile functions are configured for multi-threaded code; wherein the compile functions at least include: providing the ability to access variables for at least two working threads, memory management capabilities in a multi-threaded environment, and the ability to associate and build the functions of a single-threaded source code standard library with compiled generated resource files;
[0027] Based on the compilation parameters and compilation functions, compile the multi-threaded code to generate the target file and the initial file that calls the target file;
[0028] Modify the part of the initial file used to define the link path to obtain the calling file;
[0029] Set the target file and the calling file as resource files.
[0030] In a possible implementation, the new Uniform Resource Locator (new URL) code used to define the link path in the initial file is removed, and relative path information directly pointing to the browser address is added to the initial file.
[0031] In a possible implementation, after receiving the task response message fed back by the server through the receiving unit, and before executing the multiple target tasks associated with the target file in parallel based on at least two threads through the executing unit, the method is further configured to:
[0032] Set the local configuration file as a resource file;
[0033] The execution unit is specifically used to: read the resource file based on the absolute path of the configuration file relative to the browser address;
[0034] Based on at least two working threads, multiple target tasks associated with the target file of the resource file are executed in parallel.
[0035] In a possible implementation, the creation unit is specifically used for:
[0036] Read the thread to create the file and perform the following operations:
[0037] According to the browser environment, determine the number of parallel tasks supported by the browser;
[0038] Based on the number of parallel tasks, at least two worker threads are created, which is less than or equal to the number of parallel tasks.
[0039] In a possible implementation, after executing multiple target tasks associated with the target file in parallel based on at least two working threads, the execution unit is further configured to:
[0040] For at least two working threads, respectively execute: by means of shared memory, the target task execution result corresponding to one working thread is transmitted to other working threads.
[0041] In a third aspect, an embodiment of the present application provides a computing device, comprising: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to execute the computer program to implement the steps of the task execution method provided in the embodiment of the present application.
[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the task execution method provided in the embodiment of the present application are implemented.
[0043] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer program, and the computer program is stored in a computer-readable storage medium; when the processor of a computing device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the computing device performs the steps of the task execution method provided in the embodiment of the present application.
[0044] The beneficial effects of this application are as follows:
[0045] The embodiment of the present application provides a task execution method, device, equipment and storage medium, which relates to the field of computer technology; in the present application, in response to the trigger operation for the browser during the operation of the browser, a task request message is sent to the server; and a task response message fed back by the server is received, and the task response message at least includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner; then, based on the thread, a file is created, and at least two working threads are created; based on the at least two working threads, multiple target tasks associated with the target file are executed in parallel. In the browser environment, the browser engine creates a file based on the thread, creates at least two working threads, and calls at least two working threads to execute multiple target tasks of the target file in parallel to complete the tasks related to the trigger operation, splitting the original single-thread execution into multi-threaded parallel execution, and improving the task execution efficiency compared to the single-thread execution, so that the execution efficiency meets the use requirements.
[0046] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments 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 labor.
[0048] Figure 1 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0049] Figure 2 A flowchart of a task execution method provided in an embodiment of the present application;
[0050] Figure 3 A schematic diagram of an interface for triggering an operation in a browser provided in an embodiment of the present application;
[0051] Figure 4 A flow chart of a resource file generation method provided in an embodiment of the present application;
[0052] Figure 5 A flow chart of a method for rewriting a single-threaded source code into a multi-threaded code provided in an embodiment of the present application;
[0053] Figure 6 A code rewriting schematic diagram provided for an embodiment of the present application;
[0054] Figure 7 A schematic diagram of a code rewriting example provided in an embodiment of the present application;
[0055] Figure 8 A flowchart of a method for compiling multi-threaded code provided in an embodiment of the present application;
[0056] Fig. 9 A schematic diagram of resource file generation provided in an embodiment of the present application;
[0057] Fig.10 A flowchart of a specific implementation method for task execution provided in an embodiment of the present application;
[0058] Fig.11 A schematic diagram of a specific implementation method of task execution provided in an embodiment of the present application;
[0059] Fig.12 A structural diagram of a task execution device provided in an embodiment of the present application;
[0060] Fig.13 A structural diagram of a computing device provided in an embodiment of the present application;
[0061] Fig.14 A structural diagram of another computing device provided for an embodiment of the present application. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solution and beneficial effects of this application clearer, the technical solution in the embodiment of this application will be clearly and completely described below in conjunction with the drawings in the embodiment of this application. Obviously, the described embodiment is only a part of the embodiment of this application, not all the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0063] Some of the terms used in the embodiments of the present application are explained below to facilitate understanding by those skilled in the art.
[0064] Rust language code: is a programming language code dedicated to elegantly solving high-concurrency and high-security system problems. It is a general-purpose high-level language code with high development efficiency, high execution efficiency and high reliability.
[0065] Machine code: In computer programming, machine code, consisting of machine code instructions, is a strict digital language code designed to run as fast as possible and can be considered the lowest level representation of a compiled or assembled computer program, or, as raw and hardware-dependent programming language code; that is, a low-level programming language code. Instructions generated based on machine code can be used to directly control the computer's central processing unit (CPU), each instruction causing the CPU to perform a very specific task on one or more data units in the CPU registers or memory, such as load, store, jump, or Arithmetic and Logic Unit (ALU) operations.
[0066] WebAssembly: is a new binary instruction format that is portable, small, fast to load, and compatible with the Web. It is a low-level programming language code that can run on a stack-based virtual machine. WebAssembly is a portable abstract syntax tree designed to provide faster compilation and execution than JavaScript. WebAssembly will allow developers to compile with more familiar programming language code (initially with C / C++ as the implementation target), and then execute it in the browser through a virtual machine engine to improve the browser's execution performance.
[0067] JavaScript: A client-side scripting language code based on objects and events and with relative security. It is also a scripting language code widely used in client-side Web development, often used to add dynamic functions to HTML web pages, such as responding to various operations of operating objects. It is a directly interpreted scripting language code, a dynamic type, weak type, prototype-based language code, with built-in support types.
[0068] WebWorker: Creates a multi-threaded environment for the browser engine, allowing the main thread to create worker threads and assign some tasks to the latter. While the main thread is running, the worker thread runs in the background without interfering with each other. After the worker thread completes the task, it returns the execution result to the main thread. The advantage of this is that some computationally intensive or high-latency tasks are borne by the worker thread, and the main thread will be smooth and will not be blocked or slowed down.
[0069] Variables: Based on the effective range of variables (i.e. the scope of variables), variables are divided into local variables and global variables; local variables are also called internal variables, and external variables are also called global variables. Variables defined inside a function or a compound sentence are called internal variables, which can only be referenced internally and are only valid within the scope of the function or compound sentence, and cannot be referenced by other compound sentences or functions. Variables defined outside a function are called external variables, and their scope is: starting from the definition position of the external variable to the end of the source file, and the external variable can be directly referenced by all functions within the scope.
[0070] Uniform Resource Locator (URL): A concise representation of the location and access method of resources available on the Internet. It is the address of standard resources on the Internet. Every file on the Internet has a unique URL that indicates the location of the file and how the browser should handle the associated file.
[0071] The following is a brief introduction to the design concept of the embodiments of the present application.
[0072] With the development of technology, there are many tasks running in browsers, including tasks that consume a lot of computing resources and computing time. Therefore, in order to improve the execution performance of browsers, it is proposed to use Rust language code to write the source code of tasks, which takes into account both development efficiency and execution efficiency, to achieve a 5-6 times performance improvement. In addition, in order to ensure that tasks written in Rust language code can run smoothly in browsers, the source code needs to be compiled to generate an executable file that matches the browser.
[0073] Since Wasm language code has faster compilation and execution efficiency than JavaScript language code, in related technologies, tasks written in Rust language code are usually compiled into Wasm files, and the compiled Wasm files are run in the browser process.
[0074] However, Wasm language code is a programming language code between native machine code and high-level language code. Since the current browser engine only has good execution performance for native machine code, in the browser process, due to the limitations of the browser engine, the maximum execution performance cannot be achieved when the compiled Wasm file is executed through the browser engine. That is, after compiling the source code written in Rust language code into a Wasm file, the performance is lost a lot, resulting in the original performance that can be improved by 5-6 times, which may become 1-2 times after the loss, and the best effect is not achieved, resulting in the execution efficiency not meeting the usage requirements.
[0075] Therefore, how to improve task execution performance so that the execution efficiency meets usage requirements is a technical problem that needs to be solved at present.
[0076] In view of this, embodiments of the present application provide a task execution method, apparatus, device and storage medium, which are used to improve the task execution performance and make the execution efficiency meet the usage requirements.
[0077] In an embodiment of the present application, during the operation of the browser, in response to a trigger operation for the browser, a task request message is sent to the server; and a task response message fed back by the server is received, the task response message at least including: a target file in Wasm format that can be executed in parallel in a multi-threaded manner; then, based on the thread creation file, at least two working threads are created; based on the at least two working threads, multiple target tasks associated with the target file are executed in parallel. In the browser environment, the browser engine creates at least two working threads, and executes the related tasks of the trigger operation in parallel through at least two working threads, splitting the original single-thread execution into multi-threaded parallel execution, which greatly improves the execution performance compared to the single-thread execution, so that the execution efficiency meets the use requirements.
[0078] After introducing the design concept of the embodiment of the present application, the application scenario set in the present application is briefly described below. It should be noted that the following scenario is only used to illustrate the embodiment of the present application and is not limited. In the specific implementation, the technical solution provided by the embodiment of the present application can be flexibly applied according to actual needs.
[0079] See also Figure 1 , Figure 1Schematic diagram of an application scenario of an embodiment of the present application. The application scenario includes a terminal device 110 and a server 120, and the terminal device 110 and the server 120 can communicate with each other through a communication network.
[0080] In a possible implementation, the communication network may be a wired network or a wireless network. Therefore, the terminal device 110 and the server 120 may be directly or indirectly connected via a wired or wireless communication. For example, the terminal device 110 may be indirectly connected to the server 120 via a wireless access point, or the terminal device 110 may be directly connected to the server 120 via the Internet, and this application does not limit this.
[0081] In the embodiment of the present application, the terminal device 110 includes but is not limited to mobile phones, tablet computers, laptop computers, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, car terminals and other devices; various clients can be installed on the terminal device, and the client can be an application (such as a browser, game software, etc.), or a web page, a mini-program, etc.
[0082] The server 120 is a background server corresponding to the client installed in the terminal device 110. The server 120 may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server 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 (CDNs), and big data and artificial intelligence platforms.
[0083] Take the client running in the terminal device as an example:
[0084] During operation, the browser installed in the terminal device responds to the trigger operation through the browser engine and sends a task request message to the server;
[0085] After receiving the task request message, the server feeds back a task response message corresponding to the task request message;
[0086] After receiving the task response message fed back by the server, the browser engine obtains various file information contained in the task response message; in the embodiment of the present application, the file information obtained from the task response message includes: a thread creation file for instructing the creation of at least two working threads, and a resource file of a web page resource corresponding to the triggering operation, wherein the resource file includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and a call text in JavaScript format for calling the target file;
[0087] After obtaining the file information, the browser engine creates the file based on the thread, creates at least two working threads; and the browser engine executes the call text, calls the target file in the process of executing the call file, and executes the target file in parallel based on at least two working threads to complete multiple target tasks associated with the target file. The performance is greatly improved by executing multiple working threads in parallel, and after testing, the overall performance can be improved by about 8 times compared to the browser JavaScript version.
[0088] In the embodiments of the present application, Figure 1 The figure is only an example. In fact, the number of terminal devices 110 and servers 120 is not limited, and no specific limitation is made in the embodiment of the present application. In the embodiment of the present application, when there are multiple servers 120, multiple servers 120 can form a blockchain, and the server 120 is a node on the blockchain.
[0089] To further illustrate the technical solution provided by the embodiment of the present application, the task execution method provided by the present application is described in detail below in conjunction with the accompanying drawings. Although the embodiment of the present application provides the method operation steps as shown in the following embodiments or drawings, more or fewer operation steps may be included in the method based on routine or no creative labor. In the steps where there is no necessary causal relationship logically, the execution order of these steps is not limited to the execution order provided by the embodiment of the present application.
[0090] See also Figure 2 , Figure 2 A method flow chart of a task execution method is provided for an embodiment of the present application, which is applied to a browser engine and includes the following steps:
[0091] Step S200: During the operation of the browser, in response to a trigger operation on the browser, a task request message is sent to the server.
[0092] See also Figure 3 , is a schematic diagram of an interface for triggering an operation in a browser provided in an embodiment of the present application; exemplarily, after entering the search content in the search box, click the search button, and at this time, during the operation of the browser, a search task is triggered for the browser, and the browser engine responds to the search task triggered for the browser and sends a search task request message to the server.
[0093] It should be noted that Figure 3 The triggering method shown is only one possible way to trigger an operation in a browser, but it is not the only way. For example, you can also trigger an operation by entering a URL to be searched in the URL input box, or directly clicking an application link, an article link, etc. in the browser interface.
[0094] Step S201, receiving a task response message fed back by the server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in Wasm format that can be executed in parallel in a multi-threaded manner.
[0095] After sending a task request message to the server, the server will feedback a task response message matching the task request message, and the task response message carries the file associated with the triggering operation; therefore, the task response message fed back by the server will be received.
[0096] Among them, the task response message includes at least: a thread creation file for instructing the creation of at least one working thread, and a resource file of a web page resource associated with the triggering operation, and the resource file includes at least: a target file in Wasm format that can be executed in parallel in a multi-threaded manner.
[0097] Considering that the browser engine in the related art supports JavaScript, and the Wasm format is incompatible with the browser engine, therefore, in an embodiment of the present application, the resource file also includes: a calling file for calling the target file, and the calling file is in JavaScript format.
[0098] Step S202: Create a file based on the thread and create at least two working threads.
[0099] When at least two working threads are created based on the thread creation file, the creation code in the thread creation file is read and the creation code is executed to achieve the creation of at least two working threads.
[0100] In a possible implementation, when executing the creation code to create at least two worker threads, the init ThreadPool method is used to create a thread pool. Optionally, the initThreadPool method is used to first determine the maximum number of parallel tasks that the current browser can support based on the browser environment of the current browser, and initialize a thread pool; then, based on the maximum number of parallel tasks, at least two worker threads less than or equal to the number of parallel tasks are simultaneously created in the thread pool, so as to execute tasks associated with the triggering operation of the browser in parallel based on the at least two worker threads.
[0101] Step S203: Based on at least two working threads, multiple target tasks associated with the target file are executed in parallel.
[0102] In this application, in a browser environment, the browser engine creates at least two working threads, and uses at least two working threads to execute related tasks of the trigger operation in parallel, splitting the original single-thread execution into multi-threaded parallel execution. Compared with single-thread execution, the execution performance is greatly improved, so that the execution efficiency meets the usage requirements.
[0103] In order to conveniently determine whether the main task associated with the triggering operation has been completed, or to obtain the execution results of multiple target tasks under the main task associated with the triggering operation, in an embodiment of the present application, after executing multiple target tasks associated with the target file in parallel based on at least two working threads, at least two working threads are respectively executed: by sharing memory, the execution result of the target task corresponding to one working thread is passed to other threads. It should be noted that other threads can be other working threads other than the working thread in which the other thread is located, and can also be the main thread.
[0104] For example, the transfer method is used so that different worker threads can directly communicate and transfer data through shared memory. Using shared memory does not require data serialization for communication between worker threads, which reduces the performance consumption of data serialization and deserialization, and further improves performance.
[0105] In a possible implementation, in a browser environment, memory sharing is performed through a sharedArrayBuffer object.
[0106] Considering that shared memory is a dangerous operation for the browser engine, if the browser engine loads resources under other domain names under the current web page, it is easy to be used by other files. For security reasons, when using the sharedArrayBuffer object for shared memory, it must be declared on the web page that the current web page can only load content under the resources of the current web page domain name, and cannot load resource content of non-current domain names.
[0107] Therefore, in the embodiment of the present application, the task response message also includes: a webpage response header with a webpage security policy, and a file response header with a resource security policy; so that after the browser engine receives the task response message fed back by the server, before executing multiple target tasks associated with the target file in parallel based on at least two threads, it determines to load resource files from the same source for the current webpage based on the webpage response header and the file response header. In this way, when using the sharedArrayBuffer object for memory sharing, the execution security of the browser engine is guaranteed.
[0108] Optionally, add Cross-Origin-Embedder-Policy to the webpage response header to instruct the browser whether the security policy needs to be enabled for this webpage;
[0109] Add Cross-Origin-resource-policy to the file response header to instruct the browser on the specific security policy mode of this web page.
[0110] In an embodiment of the present application, in order to enable the browser engine to smoothly execute the content in the resource file, it is necessary to ensure that the browser engine can access the resource file. Therefore, after receiving the task response message fed back by the server, before executing multiple target tasks associated with the target file in parallel based on at least two working threads, the local configuration file is set to the received resource file. At this time, when executing multiple target tasks associated with the target file in parallel based on at least two working threads, the resource file is read based on the absolute path of the configuration file relative to the browser address, and multiple target tasks associated with the target file of the resource file are executed in parallel based on at least two working threads.
[0111] It should be noted that the resource files stored in the server are obtained by the developer terminal, uploaded to the server, and stored by the server. After receiving the request message matching the resource file sent by other terminals, the server feeds back the resource file to the other terminals; the other terminals can be understood as user terminals. Therefore, a resource file generation method or a resource file acquisition method is also provided in the embodiments of the present application.
[0112] The following is a detailed description of the method for obtaining the resource files stored in the server.
[0113] See also Figure 4 , Figure 4 A flow chart of a method for generating a resource file provided in an embodiment of the present application includes the following steps:
[0114] Step S400, rewriting the single-thread source code associated with the triggering operation to obtain the multi-thread code associated with the triggering operation task.
[0115] Considering that the codes associated with the triggering operation are all running in a single-threaded situation, that is, the source code associated with the triggering operation is a single-threaded source code. The performance of the single-threaded source code meets the requirements in most scenarios. However, for scenarios with higher performance requirements, in order to meet performance requirements, the code is usually written in the form of multi-threading to improve performance, but in the case of multi-threading, it is easy to cause data disorder. For example, when multiple threads modify the value of a data at the same time, it will cause execution errors. In the related art, in order to ensure normal execution, for example, in order to prevent multiple threads from modifying the value of a data at the same time, a locking operation is required so that only one thread can access the modified data at a time, that is, only one thread is allowed to modify the same data that multiple threads need to modify at a time, but the locking operation will greatly reduce the computing performance. Therefore, an embodiment of the present application proposes a method of rewriting a single-threaded source code into a multi-threaded code.
[0116] See also Figure 5 , Figure 5A flowchart of a method for rewriting a single-threaded source code into a multi-threaded code provided in an embodiment of the present application includes the following steps:
[0117] Step S500, analyzing the single-thread source code to determine the running state of the single-thread source code in the multi-thread environment;
[0118] Step S501, based on the running state, split the single-thread source code into a first type of code and a second type of code; wherein the first type of code represents normal operation in a multi-thread environment, and the second type of code represents disordered operation in a multi-thread environment;
[0119] Step S502, based on the first type of code, rewrite the internal variables of the multi-threaded running content, and based on the second type of code, rewrite the external variables of the multi-threaded running content to obtain the multi-threaded code.
[0120] That is, when rewriting the single-threaded source code, only read operations are performed in the multi-threaded code. Write operations only modify the internal variables of the multi-threaded code, and do not modify the referenced external variables. After completing the multi-threaded code, modify the separate external variables; see Figure 6 , Figure 6 A code rewriting schematic diagram provided in an embodiment of the present application, from Figure 6 It can be seen that when rewriting single-threaded source code written in Rust language, it is divided into two parts. One part is multi-threaded transformation, in which only variables are read or modified, and the other part is single-threaded modification, in which only external variables are modified. In this way, locking and unlocking operations during operation are avoided, and maximum performance is achieved.
[0121] See also Figure 7 , Figure 7 A schematic diagram of a code rewriting example provided in an embodiment of the present application; Figure 7 The single-threaded source code given in is the code that runs normally in a single-threaded environment. Specifically, the single-threaded source code uses the single-threaded traversal method iter() to traverse the node data. During the traversal process, different values are calculated according to the edge attributes of the nodes, and then the calculation results are assigned to the edge attributes. So far, this operation is safe in both single-threaded and multi-threaded environments. But then, in the single-threaded source code, the value is written to the external variable graph based on the calculation result. This write operation runs normally in a single-threaded environment, but will cause disorder in a multi-threaded environment. In order to ensure normal operation and avoid performance degradation due to the use of locking, Figure 7 The single-threaded source code shown in the figure is split into the first type of code and the second type of code; the first type of code represents normal operation in a multi-threaded environment, see Figure 7 The dashed box part in the single-thread source code; the second type of code represents disordered operation in a multi-threaded environment, see Figure 7 The implementation box part is in the single-thread source code; then, the first type of code that runs normally is placed inside the multi-thread, and the second type of code that runs disorderly is placed outside the multi-thread; at this point, the rewriting of the single-thread source code is completed to obtain the multi-thread code. The format of the multi-thread code can be found in Figure 7 The multithreaded code shown in . In the multithreaded code, the method of traversing the array in parallel in a multithreaded environment, par_iter_mut(), is used instead of iter() to improve the traversal speed; the modification operation of the graph variable is moved to the outside of the multithreaded code for separate modification to avoid locking operations.
[0122] Step S401, compile the multi-thread code to obtain a resource file; wherein the resource file includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and a calling file that calls the target file.
[0123] After obtaining the multi-threaded code, the multi-threaded code is compiled into a target file in Wasm format that can be executed in parallel in a multi-threaded manner, so that the target file can be run in a browser.
[0124] See also Figure 8 , Figure 8 A flowchart of a method for compiling multi-threaded code provided in an embodiment of the present application includes the following steps:
[0125] Step S800, configuring compilation parameters and compilation functions for the multi-threaded code.
[0126] Since the single-threaded source code is rewritten into multi-threaded code, during the code compilation process, compared with the compilation of the single-threaded source code, when compiling the multi-threaded code, additional compilation parameters need to be configured, and the compiler needs to be explicitly told which additional compilation functions need to be configured.
[0127] In the embodiment of the present application, the compiler uses Wasm-pack;
[0128] The additional compilation parameters are: "RUSTFLAGS="-C target-feature="+atomics,+bulk-memory" wasm-pack build . / packages / wasm –target web –out dir
[0129] .. / .. / example / pkg-mt----features parallel–Z build-std=panic_abort,std
[0130] Additional compilation features include at least: atomics, which represents the ability to provide access to variables for at least two working threads; bulk-memory, which represents the ability to manage memory in a multi-threaded environment; build-std, which represents the ability to associate the functions of the standard library of single-threaded source code (such as Rust) with the compiled resource files.
[0131] Step S801, based on the compilation parameters and the compilation function, compile the multi-thread code to generate a target file and an initial file that calls the target file.
[0132] After the compilation parameters and the compilation functions are determined, the compiler performs a compilation operation on the multi-threaded code based on the compilation parameters and the compilation functions to generate a target file and an initial file that calls the target file.
[0133] Step S802, modify the part of the initial file used to define the link path to obtain a calling file.
[0134] Considering that the generated initial file uses the new URL code to create a URL object, but the new URL code cannot be used directly in the browser environment, the URL object created by the new URL code, that is, the link path is also incorrect. Therefore, it is necessary to modify the part of the initial file used to define the link path to obtain the calling file associated with the initial file so that the calling file can be used directly in the browser environment.
[0135] Exemplarily, the new URL code used to define the link path in the initial file is removed, and a link directly pointing to a specific file is added in the initial file, so that the final path is directly '. / workerHelpers.js', that is, a relative path directly pointing to the current browser address; for example, if the current browser address is abc.com, the abc.com / workerHeplers.js resource will be downloaded.
[0136] Step S803, setting the target file and the calling file as resource files.
[0137] Exemplarily, the compilation product is set as a resource file, that is, the target file in Wasm format that can be executed in parallel in a multi-threaded manner and the calling file that calls the target file are set as resource files to access these files in a browser.
[0138] In a possible implementation, in order to ensure the security of resource files running in the current web page of the browser, a security response header is set for the resource files and the web pages associated with the resource files. The specific setting method of the security response header is described above and will not be repeated here.
[0139] See also Fig. 9 , Fig. 9 A schematic diagram of resource file generation provided in an embodiment of the present application. Fig. 9 It can be seen that: first, the single-threaded source code written in Rust language is rewritten to obtain multi-threaded code; then, the multi-threaded code is compiled to obtain a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and an initial file that calls the target file; then, the initial file is modified to obtain a calling file that is compatible with the browser environment and is used to call the target file; then, the target file in Wasm format and the calling file are set as resource files; finally, in order to ensure the security of browser operation, a security response header is set for the resource file and the web page associated with the resource file.
[0140] See also Fig.10 , Fig.10 A flowchart of a specific implementation method of a task execution provided in an embodiment of the present application includes the following steps:
[0141] Step S1000: during the operation of the browser, the terminal device responds to a trigger operation on the browser through the browser engine;
[0142] Step S1001, the terminal device sends a task request message to the server through the browser engine;
[0143] Step S1002, after receiving the task request message, the server determines the thread creation file and resource file matching the task request message;
[0144] Step S1003, the server generates a task response message based on the thread creation file and the resource file; wherein the task response message includes: the thread creation file, the resource file, a file response header set for the resource file, and a webpage response header set for the webpage associated with the resource file;
[0145] Step S1004, the server feeds back a task response message to the terminal device;
[0146] Step S1005: The terminal device calls a thread through the browser engine to create a file and creates at least two working threads:
[0147] Step S1006, the terminal device sets the local configuration file as a resource file;
[0148] Step S1007, the terminal device reads the resource file from the same source as the current web page through the browser engine according to the web page response header and the file response header and based on the absolute path of the configuration file relative to the browser address;
[0149] Step S1008: the terminal device calls at least two working threads through the browser engine, and executes multiple target tasks associated with the target file in parallel based on the at least two working threads;
[0150] Step S1009: The terminal device transmits the target task execution result corresponding to one working thread to other working threads by means of shared memory.
[0151] It should be noted that Fig.10 The steps shown are just one way that this can be accomplished, but are not the only way.
[0152] See also Fig.11 , Fig.11 A schematic diagram of a specific implementation method of task execution provided in an embodiment of the present application; Fig.11 It can be seen that a browser is run in a user terminal, and during the operation of the browser, in response to an image search operation triggered on the browser in the browser interface, an image search request message is sent to the server; after receiving the image search request message, the server selects a thread creation file and a resource file that match the image search request message from the thread creation file and the resource file pre-uploaded by the developer terminal, and based on the thread creation file and the resource file, feeds back an image search response message to the user terminal, wherein the image search response message includes at least: a thread creation file for indicating the creation of at least two working threads, and a resource file associated with the image search, and the resource file includes at least a target file in Wasm format that can be executed in parallel in a multi-threaded manner; after receiving the task response message, the user terminal creates at least two working threads based on the thread creation file, and executes multiple target tasks associated with the target file in parallel based on the at least two working threads, and finally displays multiple search results associated with the image search in the browser interface.
[0153] The resource files pre-uploaded to the server by the developer terminal are compiled by multi-threaded code. For details, see the above Figure 4 The content of the resource file generation part shown is not repeated here.
[0154] In the present application, in a browser environment, the browser engine creates files based on threads, creates at least two working threads, and calls at least two working threads to execute multiple target tasks of the target file in parallel to complete the related tasks of the triggering operation, and splits the original single-thread execution into multi-threaded parallel execution. Compared with single-threaded execution, the task execution efficiency is improved so that the execution efficiency meets the usage requirements.
[0155] Based on the same inventive concept, the embodiment of the present application also provides a task execution device 1200, such as Fig.12 As shown, the task execution device 1200 includes:
[0156] The sending unit 1201 is used to send a task request message to the server in response to a trigger operation on the browser during the browser operation;
[0157] The receiving unit 1202 is used to receive the task response message fed back by the server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in Wasm format that can be executed in parallel in a multi-threaded manner;
[0158] A creating unit 1203 is used to create a file based on a thread and create at least two working threads;
[0159] The execution unit 1204 is used to execute multiple target tasks associated with the target file in parallel based on at least two working threads.
[0160] In a possible implementation, the task response message further includes: a webpage response header with a webpage security policy set, and a file response header with a resource security policy set;
[0161] After receiving the task response message fed back by the server through the receiving unit 1202, before executing multiple target tasks associated with the target file in parallel based on at least two threads through the executing unit 1204, it is also used to:
[0162] Based on the webpage response header and the file response header, determine to load the resource file from the same source for the current webpage.
[0163] In a possible implementation, the resource file is obtained in the following manner:
[0164] Rewrite the single-thread source code associated with the trigger operation to obtain the multi-thread code associated with the trigger operation task;
[0165] Compile the multi-thread code to obtain a resource file; wherein the resource file includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and a calling file that calls the target file.
[0166] In a possible implementation, a single-thread source code is analyzed to determine the running state of the single-thread source code in a multi-thread environment;
[0167] Based on the running state, the single-thread source code is divided into the first type of code and the second type of code; wherein the first type of code represents normal operation in a multi-thread environment, and the second type of code represents disordered operation in a multi-thread environment;
[0168] Based on the first type of code, the internal variables of the multi-threaded running content are rewritten, and based on the second type of code, the external variables of the multi-threaded running content are rewritten to obtain the multi-threaded code.
[0169] In a possible implementation, compile parameters and compile functions are configured for multi-threaded code; wherein the compile functions at least include: providing the ability to access variables for at least two working threads, memory management capabilities in a multi-threaded environment, and the ability to associate and build the functions of a single-threaded source code standard library with compiled generated resource files;
[0170] Based on the compilation parameters and compilation functions, compile the multi-threaded code to generate the target file and the initial file that calls the target file;
[0171] Modify the part of the initial file used to define the link path to obtain the calling file;
[0172] Set the target file and the calling file as resource files.
[0173] In a possible implementation, the new URL code for defining the link path in the initial file is removed, and relative path information directly pointing to the browser address is added to the initial file.
[0174] In a possible implementation, after receiving the task response message fed back by the server through the receiving unit 1202, and before executing the multiple target tasks associated with the target file in parallel based on at least two threads through the executing unit 1204, it is further configured to:
[0175] Set the local configuration file as a resource file;
[0176] The execution unit 1204 is specifically used to: read the resource file based on the absolute path of the configuration file relative to the browser address;
[0177] Based on at least two working threads, multiple target tasks associated with the target file of the resource file are executed in parallel.
[0178] In a possible implementation, the creating unit 1203 is specifically configured to:
[0179] Read the thread to create the file and perform the following operations:
[0180] According to the browser environment, determine the number of parallel tasks supported by the browser;
[0181] Based on the number of parallel tasks, at least two worker threads are created, which is less than or equal to the number of parallel tasks.
[0182] In a possible implementation, after executing multiple target tasks associated with the target file in parallel based on at least two working threads by the execution unit 1204, the execution unit 1204 is further configured to:
[0183] For at least two working threads, respectively execute: by means of shared memory, the target task execution result corresponding to one working thread is transmitted to other working threads.
[0184] For the convenience of description, the above parts are divided into units (or modules) according to their functions and described separately. Of course, when implementing this application, the functions of each unit (or module) can be implemented in the same or multiple software or hardware.
[0185] After introducing the task execution method and apparatus according to an exemplary embodiment of the present application, another exemplary embodiment of the present application, a computing device, is introduced next.
[0186] Those skilled in the art will appreciate that various aspects of the present application may be implemented as a system, method or program product. Therefore, various aspects of the present application may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to as "circuit", "module" or "system" herein.
[0187] In an embodiment of the present application, a computing device is also provided, and the computing device may include at least a processor and a memory. The memory stores a computer program, and when the computer program is executed by the processor, the processor executes any step of the task execution method of various exemplary embodiments of the present application.
[0188] In a possible implementation, the computing device may be a terminal device, and the structure of the computing device may be as follows: Fig.13 As shown, it includes: a communication component 1310, a memory 1320, a display unit 1330, a camera 1340, a sensor 1350, an audio circuit 1360, a Bluetooth module 1370, a processor 1380 and other components.
[0189] The communication component 1310 is used to communicate with the ring wearable device. In some embodiments, a circuit wireless fidelity (Wireless Fidelity, WiFi) module may be included. The WiFi module belongs to a short-range wireless transmission technology, and the computing device sends and receives information through the WiFi module.
[0190] The memory 1320 can be used to store software programs and data. The processor 1380 performs various functions and data processing by running the software programs or data stored in the memory 1320. The memory 1320 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one type of disk storage device, flash memory device, or other volatile solid-state storage device. The memory 1320 stores an operating system that enables the computing device to run. In the present application, the memory 1320 can store an operating system and various application programs, and can also store code for executing the task execution method of the embodiment of the present application.
[0191] The display unit 1330 can also be used to display information input by the user or information provided to the user and a graphical user interface (GUI) of various menus of the terminal device. Specifically, the display unit 1330 includes a display screen 1332 arranged on the front of the terminal device. The display screen 1332 can be configured in the form of a liquid crystal display, a light emitting diode, etc.
[0192] The display unit 1330 can also be used to receive input digital or character information and generate signal input related to user settings and function control of the terminal device. Specifically, the display unit 1330 may include a touch screen 1331 arranged on the front of the terminal device, which can collect user touch operations on or near it, such as clicking a button, dragging a scroll box, etc.
[0193] The touch screen 1331 can be covered on the display screen 1332, or the touch screen 1331 and the display screen 1332 can be integrated to realize the input and output functions of the terminal device, and the integrated display screen can be referred to as a touch display screen. In this application, the display unit 1330 can display applications, multimedia information played by applications, and corresponding operation steps.
[0194] The camera 1340 can be used to capture static images. The camera 1340 can be one or more. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then transmits the electrical signal to the processor 1380 to convert it into a digital image signal.
[0195] The computing device may further include at least one sensor 1350, such as an acceleration sensor 1351, a distance sensor 1352, a fingerprint sensor 1353, and a temperature sensor 1354. The computing device may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, a light sensor, and a motion sensor.
[0196] The audio circuit 1360, the speaker 1361, and the microphone 1362 can provide an audio interface between the user and the computing device. The audio circuit 1360 can transmit the electrical signal converted from the received audio data to the speaker 1361, which is converted into a sound signal for output. The computing device can also be configured with a volume button for adjusting the volume of the sound signal. On the other hand, the microphone 1362 converts the collected sound signal into an electrical signal, which is received by the audio circuit 1360 and converted into audio data, and then the audio data is output to the communication component 1313 for transmission to, for example, another computing device, or the audio data is output to the memory 1320 for further processing.
[0197] The Bluetooth module 1370 is used to exchange information with other Bluetooth devices having Bluetooth modules through the Bluetooth protocol. For example, the computing device can establish a Bluetooth connection with a wearable computing device (such as a smart watch) that also has a Bluetooth module through the Bluetooth module 1370 to exchange data.
[0198] The processor 1380 is the control center of the computing device. It uses various interfaces and lines to connect various parts of the entire computing device. It executes various functions of the computing device and processes data by running or executing software programs stored in the memory 1320 and calling data stored in the memory 1320. In some embodiments, the processor 1380 may include one or more processing units; the processor 1380 may also integrate an application processor and a baseband processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the baseband processor mainly processes wireless communications. It is understandable that the above-mentioned baseband processor may not be integrated into the processor 1380. In the present application, the processor 1380 can run the operating system, application programs, user interface display and touch response, as well as the task execution method of the embodiment of the present application. In addition, the processor 1380 is coupled to the display unit 1330.
[0199] In another possible implementation, the computing device may be a server. The structure of the computing device may be as follows: Fig.14 As shown, the components of the computing device 1400 may include, but are not limited to: at least one processor 1401 , at least one memory 1402 , and a bus 1403 connecting different system components (including the memory 1402 and the processor 1401 ).
[0200] The memory 1402 may be used to store software programs and data. The processor 1401 executes various functions and data processing by running the software programs or data stored in the memory 1402, thereby implementing the task execution method of the embodiment of the present application.
[0201] Bus 1403 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a processor, or a local bus using any of a variety of bus architectures.
[0202] The memory 1402 may include a readable medium in the form of a volatile memory, such as a random access memory (RAM) 14021 and / or a cache memory 14022 , and may further include a read-only memory (ROM) 14023 .
[0203] Memory 1402 may also include a program / utility 14025 having a set (at least one) of program modules 14024, such program modules 14024 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0204] The computing device 1400 may also communicate with one or more external devices 1404 (e.g., keyboards, pointing devices, etc.), one or more devices that enable a user to interact with the computing device 1400, and / or any device that enables the computing device 1400 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via input / output (I / O) interface 1405. Furthermore, the computing device 1400 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via network adapter 1406. Fig.14 As shown, network adapter 1406 communicates with other modules for computing device 1400 via bus 1403. It should be understood that although Fig.14 Not shown, other hardware and / or software modules may be used in conjunction with computing device 1400, including but not limited to microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0205] In addition, it should be noted that in the specific implementation of this application, user-related data is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0206] In some possible implementations, various aspects of the task execution method provided by the present application may also be implemented in the form of a program product, which includes a computer program. When the program product is run on a computer device, the computer program is used to enable the computer device to execute the steps of the task execution method according to various exemplary implementations of the present application described above in this specification.
[0207] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0208] The program product of multimedia information recommendation of the embodiment of the present application can adopt a portable compact disk read-only memory (CD-ROM) and include a computer program, and can be run on a computing device. However, the program product of the present application is not limited to this. In this document, the readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with a command execution system, device or device.
[0209] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, wherein a readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A readable signal medium may also be any readable medium other than a readable storage medium, which may convey, propagate, or transmit a program for use by or in conjunction with a command execution system, apparatus, or device.
[0210] The computer program embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0211] The computer program for performing the operations of the present application may be written in any combination of one or more programming language codes, including object-oriented programming language codes, such as Java, C++, etc., and conventional procedural programming language codes, such as "C" language codes or similar programming language codes. The computer program may be executed entirely on the user computing device, partially on the user equipment, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0212] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of one unit described above can be further divided into multiple units to be embodied.
[0213] In addition, although the operations of the method of the present application are described in a specific order in the drawings, this does not require or imply that the operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0214] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain a computer-usable computer program.
[0215] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program commands. These computer program commands can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the commands executed by the processor of the computer or other programmable data processing device generate commands for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0216] These computer program commands may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the commands stored in the computer readable memory produce an article of manufacture comprising a command device, the command device implementing the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0217] These computer program commands can also be loaded onto a computer or other programmable data processing device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the commands executed on the computer or other programmable device provide the instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0218] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0219] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A task execution method, characterized in that: Applied to a browser engine, the method comprises: During the operation of the browser, in response to a trigger operation on the browser, a task request message is sent to the server; Receive a task response message fed back by the server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in Wasm format of a network conference that can be executed in parallel in a multi-threaded manner; Based on the thread creation file, at least two working threads are created; Based on the at least two working threads, multiple target tasks associated with the target file are executed in parallel.
2. The method according to claim 1, characterized in that The task response message also includes: a webpage response header with a webpage security policy set, and a file response header with a resource security policy set; After receiving the task response message fed back by the server and before executing the multiple target tasks associated with the target file in parallel based on the at least two threads, the method further includes: Based on the webpage response header and the file response header, it is determined to load a resource file from the same source for the current webpage.
3. The method according to claim 1, characterized in that The resource file is obtained in the following way: Rewriting the single-thread source code associated with the trigger operation to obtain the multi-thread code associated with the trigger operation task; Compile the multi-thread code to obtain the resource file; wherein the resource file includes: a target file in Wasm format that can be executed in parallel in a multi-threaded manner, and a calling file that calls the target file.
4. The method according to claim 3, characterized in that The rewriting of the single-thread source code associated with the trigger operation to obtain the multi-thread code associated with the trigger operation includes: Analyzing the single-thread source code to determine the running state of the single-thread source code in a multi-thread environment; Based on the running state, the single-thread source code is divided into a first type of code and a second type of code; wherein the first type of code represents normal operation in the multi-thread environment, and the second type of code represents disordered operation in the multi-thread environment; Based on the first type of code, the internal variables of the multi-threaded running content are rewritten, and based on the second type of code, the external variables of the multi-threaded running content are rewritten to obtain the multi-threaded code.
5. The method according to claim 3, characterized in that The compiling operation on the multi-threaded code to obtain the resource file includes: Compilation parameters and compilation functions are configured for the multi-threaded code; wherein the compilation functions include at least: providing the at least two working threads with the ability to access variables, memory management capabilities in the multi-threaded environment, and the ability to associate and construct the functions of the single-threaded source code standard library with the compiled resource files; Based on the compilation parameters and the compilation function, compile the multi-threaded code to generate the target file and an initial file that calls the target file; Modify the part of the initial file used for defining the link path to obtain the calling file; The target file and the calling file are set as resource files.
6. The method according to claim 5, characterized in that The part of the initial file used to define the link path is modified to obtain the calling file, including: The new uniform resource locator new URL code used to define the link path in the initial file is removed, and relative path information directly pointing to the browser address is added to the initial file.
7. The method according to claim 1 or 2, characterized in that: After receiving the task response message fed back by the server, and before executing the multiple target tasks associated with the target file in parallel based on the at least two working threads, the method further includes: Set the local configuration file as the resource file; Based on the at least two working threads, executing multiple target tasks associated with the target file in parallel includes: Read the resource file based on the absolute path of the configuration file relative to the browser address; Based on the at least two working threads, multiple target tasks associated with the target file of the resource file are executed in parallel.
8. The method according to claim 1 or 2, characterized in that: The step of creating a file based on the thread and creating at least two working threads includes: Read the thread creation file and perform the following operations: Determining the number of parallel tasks supported by the browser according to the browser environment of the browser; Based on the number of parallel tasks, at least two working threads less than or equal to the number of parallel tasks are created.
9. The method according to claim 1 or 2, characterized in that: After executing the plurality of target tasks associated with the target file in parallel based on the at least two working threads, the method further includes: For the at least two working threads, respectively executing: transmitting the target task execution result corresponding to one working thread to other working threads by means of shared memory.
10. A task execution device, characterized in that: The device comprises: A sending unit, used to send a task request message to a server in response to a trigger operation on the browser during the operation of the browser; A receiving unit, configured to receive a task response message fed back by a server; wherein the task response message includes at least: a thread creation file and a resource file; the resource file includes at least: a target file in a network conference Wasm format that can be executed in parallel in a multi-threaded manner; A creation unit, used to create a file based on the thread and create at least two working threads; An execution unit is used to execute multiple target tasks associated with the target file in parallel based on the at least two working threads.
11. A computing device, characterized in that: The computing device comprises: a memory and a processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to implement the steps of any one of the methods of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
13. A computer program product, characterized in that The invention comprises a computer program, which implements the steps of any one of the methods of claims 1 to 9 when executed by a processor.
Citation Information
Cited By
Browser data modification method and device, equipment, storage medium and product
CN121144636A
