Task execution method and apparatus

By adding task execution to the remaining time of each browser frame, and utilizing the requestAnimationFrame method and instances of non-fixed tasks, the page lag problem caused by single-threaded task overload was solved, improving browser responsiveness and user experience.

CN118585723BActive Publication Date: 2026-11-27HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410634451.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-21
Publication Date
2026-11-27
Estimated Expiration
2044-05-21

AI Technical Summary

Technical Problem

When performing a large number of tasks during or after webpage rendering, single-threaded just-in-time compiled programming languages ​​can cause page lag or freezing.

Method used

By adding task execution to the remaining time of each browser frame, triggering the execution function using the requestAnimationFrame method, creating instances of non-fixed tasks, and executing these tasks in the next frame, task overload within the same frame is avoided.

Benefits of technology

It effectively avoids page lag caused by task overload, improving browser page response speed and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585723B_ABST
    Figure CN118585723B_ABST
Patent Text Reader

Abstract

The application provides a task execution method and device, the method comprising: determining a theoretical running duration of each frame in a browser, a frame being one page refresh of the browser, the running duration being a refresh time interval required by the browser for each page refresh; obtaining at least one non-fixed task to be executed in the browser, the non-fixed task being a task not specified to be executed in the running process of any frame; creating an instance object corresponding to each non-fixed task; triggering an execution function when the running of the current frame ends; determining whether there is remaining time in the running process of the next frame based on the triggering time of the execution function and the theoretical running duration; if there is remaining time in the running process of the next frame, adding at least one instance object in the running process of the next frame to execute the non-fixed task corresponding to the at least one instance object in the running process of the next frame.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a task execution method and apparatus. Background Technology

[0002] In some scenarios, when a user visits a webpage, a large number of tasks may need to be executed during or after the webpage rendering process. These tasks might include dynamically rendering page elements or performing computational tasks. Since just-in-time (JIT) compiled programming languages ​​(JavaScript, JS) are single-threaded, they can only process one task at a time. When the number of tasks is large, all tasks need to be completed when the browser refreshes the page. Most browsers refresh the page 60 times per second, with a very short time interval between each refresh (approximately 16.6 milliseconds, the duration of each frame). If the total time spent on all the tasks within a single frame is too long, the timing of the next frame's trigger will be delayed. This means the number of refreshes per second will be far less than 60, or even only once every few seconds. As a result, the user will experience page lag or freezing. Summary of the Invention

[0003] In view of this, the present invention provides a task execution method, which allows tasks to be added and executed in the remaining time of multiple frames, thereby avoiding significant page lag caused by tasks being executed in the same frame.

[0004] The present invention also provides a task execution device to ensure the implementation and application of the above method in practice.

[0005] A task execution method, comprising:

[0006] Determine the theoretical runtime of each frame in the browser, where each page refresh of the browser is considered a frame, and the runtime is the refresh time interval required for each page refresh by the browser.

[0007] Obtain at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame;

[0008] Create an instance object corresponding to each of the aforementioned non-fixed tasks;

[0009] The function is triggered when the current frame finishes running;

[0010] Based on the trigger time of the execution function and the theoretical runtime, determine whether there is remaining time in the next frame during execution;

[0011] If there is remaining time during the execution of the next frame, at least one instance object is added during the execution of the next frame to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame.

[0012] Optionally, in the aforementioned apparatus, determining the theoretical runtime of each frame in the browser includes:

[0013] Obtain the browser's refresh rate;

[0014] The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

[0015] Optionally, in the aforementioned apparatus, determining whether there is remaining time in the next frame during execution based on the trigger time of the execution function and the theoretical runtime includes:

[0016] Determine the last trigger time of the execution function in the current frame and the first trigger time in the next frame;

[0017] Determine a second time interval between the last trigger time and the first trigger time;

[0018] Determine whether the second time interval is not greater than the theoretical running time;

[0019] If the second time interval is not greater than the theoretical runtime, it is determined that there is remaining time in the next frame during operation;

[0020] The last trigger time of the execution function in the current frame is the time point at which the current frame ends.

[0021] Optionally, in the above-described apparatus, if a fixed task exists in the next frame, the first trigger time of the execution function in the next frame is the time point at which the fixed task finishes execution;

[0022] If there is no fixed task in the next frame, the first trigger time of the execution function in the next frame is the start time of the next frame, and the start time of the next frame is the same as the end time of the current frame.

[0023] The fixed task is a task that is specified to be executed in any frame.

[0024] Optionally, in the above-described apparatus, adding at least one instance object during the execution of the next frame to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame includes:

[0025] In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

[0026] A task execution device, comprising:

[0027] The first determining unit is used to determine the theoretical runtime of each frame in the browser, wherein each page refresh of the browser is one frame, and the runtime is the refresh time interval required for each page refresh of the browser.

[0028] The acquisition unit is used to acquire at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame;

[0029] A creation unit is used to create instance objects corresponding to each of the aforementioned non-fixed tasks;

[0030] The triggering unit is used to trigger the execution function when the current frame ends.

[0031] The second determining unit is used to determine whether there is remaining time in the next frame during the execution process based on the trigger time of the execution function and the theoretical runtime.

[0032] An execution unit is configured to add at least one instance object during the execution of the next frame if there is remaining time during the execution of the next frame, so as to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame.

[0033] Optionally, in the aforementioned apparatus, the first determining unit determines the theoretical runtime of each frame in the browser, specifically for:

[0034] Obtain the browser's refresh rate;

[0035] The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

[0036] Optionally, in the aforementioned apparatus, the second determining unit determines whether there is remaining time in the next frame during execution based on the trigger time of the execution function and the theoretical runtime, including:

[0037] Determine the last trigger time of the execution function in the current frame and the first trigger time in the next frame;

[0038] Determine a second time interval between the last trigger time and the first trigger time;

[0039] Determine whether the second time interval is not greater than the theoretical running time;

[0040] If the second time interval is not greater than the theoretical runtime, it is determined that there is remaining time in the next frame during operation;

[0041] The last trigger time of the execution function in the current frame is the time point at which the current frame ends.

[0042] Optionally, in the above-described apparatus, if a fixed task exists in the next frame, the first trigger time of the execution function in the next frame is the time point at which the fixed task finishes execution;

[0043] If there is no fixed task in the next frame, the first trigger time of the execution function in the next frame is the start time of the next frame, and the start time of the next frame is the same as the end time of the current frame.

[0044] The fixed task is a task that is specified to be executed in any frame.

[0045] Optionally, in the above-described apparatus, the execution unit adds at least one instance object during the execution of the next frame to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame, specifically for:

[0046] In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

[0047] A storage medium comprising stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides controls the execution of the task execution method described above.

[0048] An electronic device includes a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors using the task execution method described above.

[0049] Compared with the prior art, the present invention has the following advantages:

[0050] This invention provides a task execution method, comprising: determining the theoretical runtime of each frame in a browser, wherein each page refresh of the browser is considered a frame, and the runtime is the refresh time interval required for each page refresh; obtaining at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task not specified to be executed during the execution of any frame; creating an instance object corresponding to each of the non-fixed tasks; triggering an execution function when the current frame finishes execution; determining whether there is remaining time in the next frame based on the trigger time of the execution function and the theoretical runtime; if there is remaining time in the next frame, adding at least one instance object during the execution of the next frame to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame. By applying the method provided by this invention, tasks can be added and executed in the remaining time of multiple frames, avoiding significant page lag caused by tasks being executed in the same frame. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0052] Figure 1 A flowchart of a task execution method provided in an embodiment of the present invention;

[0053] Figure 2 An example diagram illustrating a task execution method provided in an embodiment of the present invention;

[0054] Figure 3 This is another flowchart of a task execution method provided in an embodiment of the present invention;

[0055] Figure 4 Another example diagram of a task execution method provided in an embodiment of the present invention;

[0056] Figure 5 Another example diagram of a task execution method provided in an embodiment of the present invention;

[0057] Figure 6 Another example diagram of a task execution method provided in an embodiment of the present invention;

[0058] Figure 7 Another example diagram of a task execution method provided in an embodiment of the present invention;

[0059] Figure 8Another example diagram of a task execution method provided in an embodiment of the present invention;

[0060] Figure 9 This is a structural diagram of a task execution device provided in an embodiment of the present invention;

[0061] Figure 10 This is a schematic diagram of an electronic device structure provided in an embodiment of the present invention. Detailed Implementation

[0062] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0063] In this application, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0064] This invention can be used in a wide variety of general-purpose or special-purpose computing environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor devices, distributed computing environments including any of the above devices, etc.

[0065] This invention provides a task execution method that can be applied to various system platforms. The executing entity can be a computer terminal or the processor of various mobile devices. The method flowchart is shown below. Figure 1 As shown, it specifically includes:

[0066] S101: Determine the theoretical runtime of each frame in the browser.

[0067] In this context, each page refresh in the browser is considered a frame, and the runtime is the refresh interval required for each page refresh by the browser.

[0068] Specifically, the implementation method for determining the theoretical runtime of each frame in the browser is as follows:

[0069] Obtain the browser's refresh rate;

[0070] The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

[0071] It should be noted that the theoretical runtime is determined based on the browser's page refresh rate. However, between each two consecutive time intervals, there may be some tasks that need to be executed. Before the next refresh, these tasks need to be completed before the page can be refreshed. Therefore, the actual refresh interval of the browser may differ from the theoretical refresh interval. Similarly, the theoretical runtime of each frame may also differ from the actual runtime.

[0072] For example, if the browser's refresh rate is 75Hz, then the browser's refresh interval is: 1000ms / 75Hz ≈ 13.3ms (reference). Figure 2 , Figure 2 R1 to R4 represent the various frames, each with a theoretical runtime of 13.3ms. If a frame requires a 10ms task to execute, the actual runtime of that frame remains 13.3ms. If a frame requires an 18ms task to execute, the frame's execution will only end after the task is completed. Therefore, the actual runtime of that frame is 18ms, and there is a difference between the actual runtime and the theoretical runtime.

[0073] S102: Obtain at least one non-fixed task to be executed in the browser.

[0074] Non-fixed tasks are those that are not specified to be executed during the execution of any particular frame. In other words, non-fixed tasks can be executed during the execution of any frame.

[0075] S103: Create an instance object corresponding to each non-fixed task.

[0076] S104: Trigger the execution function when the current frame ends.

[0077] In S104, when the current frame finishes running, the method that triggers the execution function can be triggered in the pre-set requestAnimationFrame method. The methods for triggering the execution function in this application include, but are not limited to, the requestAnimationFrame method.

[0078] It should be noted that the requestAnimationFrame method is used to trigger the execution function at the end of the current frame; if there is no fixed task to be executed in the next frame, the execution function is triggered when the next frame starts running; if there is a fixed task to be executed in the next frame, the execution function is triggered when the fixed task ends.

[0079] The main function of the requestAnimationFrame method is to receive a callback method, in which you can do something, such as rendering an animation task or executing a task unrelated to the animation (most common and recommended use case is executing animation tasks). The callback method is triggered before the next browser repaint (i.e., before the next page refresh).

[0080] S105: Based on the trigger time of the execution function and the theoretical runtime, determine whether there is remaining time in the next frame during the execution process.

[0081] If there is remaining time in the next frame during its execution, then S106 is executed; otherwise, S107 is executed.

[0082] Specifically, based on the trigger time of the last function executed in the current frame and the trigger time of the first function executed in the next frame, it is determined whether the time interval between the two exceeds the theoretical runtime. If not, there is remaining time; otherwise, there is no remaining time. If the time interval between the last function executed in the current frame and the first function executed in the next frame exceeds the theoretical runtime, then the duration corresponding to this time interval is the actual runtime of the next frame.

[0083] S106: Add at least one instance object during the execution of the next frame to execute at least one non-fixed task corresponding to the instance object during the execution of the next frame.

[0084] Specifically, the implementation method of adding at least one instance object during the execution of the next frame to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame is as follows:

[0085] In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

[0086] It should be noted that the callback function contains a resolve method, which is provided by the JS engine. Its function is to indicate that the task corresponding to the next instance object can only be executed after the task corresponding to the instance object has been completed.

[0087] S107: Set the next frame as the current frame and wait for it to finish running.

[0088] In the method provided by this invention, at the end of each frame's execution in the browser, the `requestAnimationFrame` method is used to determine whether there is remaining time in the next frame's execution. If there is remaining time, a new instance object is added to the next frame to complete the non-fixed task corresponding to that instance object during the next frame's execution. The instance object added in each frame must ensure that the frame's execution time does not exceed the theoretical runtime of each frame. Using the theoretical runtime of each frame as a reference standard, the difference between the actual runtime of each frame after adding the instance object and the theoretical runtime cannot exceed a pre-set time.

[0089] By applying the method provided by this invention, tasks can be added and executed separately in frames with remaining time, avoiding page lag caused by multiple tasks being executed simultaneously in one frame.

[0090] In the method provided in the embodiments of the present invention, reference is made to Figure 3 Based on the trigger time of the execution function and the theoretical runtime, the process of determining whether there is remaining time in the next frame during execution is as follows:

[0091] S301: Determine the last trigger time of the function in the current frame and the first trigger time in the next frame.

[0092] The last time the function is triggered in the current frame is the time when the current frame ends.

[0093] Furthermore, if a fixed task exists in the next frame, the first trigger time of the function in the next frame is the time when the fixed task finishes execution; if no fixed task exists in the next frame, the first trigger time of the function in the next frame is the time when the next frame starts running, and the time when the next frame starts running is the same as the time when the current frame ends; where a fixed task is a task specified to be executed in any frame.

[0094] It is understandable that when any frame triggers the execution function for the first time, that frame does not contain any fixed tasks to be executed in the subsequent running process, and the system's threads are in an idle state at this time.

[0095] S302: Determine the second time interval between the last trigger time and the first trigger time.

[0096] S303: Determine whether the second time interval is not greater than the theoretical running time.

[0097] If the second time interval is not greater than the theoretical running time, execute S304; otherwise, execute S305.

[0098] Understandably, since there are no fixed tasks to be executed in any given frame when the task is first triggered, it is necessary to determine whether there is idle time to execute other tasks during the execution of the next frame. The second time interval is consistent with the execution duration of the fixed tasks in the next frame.

[0099] S304: Determines that there is remaining time in the next frame during its execution.

[0100] refer to Figure 4 If the time interval R1 to R2 is the runtime of the current frame, and the time interval R2 to R3 is the runtime of the next frame, then at the end of the current frame, the execution function is triggered for the last time in the current frame. Since the next frame contains a fixed task 'a', the execution function will not be triggered during the execution of fixed task 'a'. At the end of fixed task 'a', the execution function is triggered for the first time in the next frame. Because the execution duration of fixed task 'a' is less than the runtime of the next frame, the time interval between the end of fixed task 'a' and the end of the current frame is no greater than the theoretical runtime. Therefore, a new non-fixed task 'A' (e.g., ...) can be added in the next frame. Figure 5 (As shown).

[0101] S305: Determines that there is no remaining time in the next frame during its execution.

[0102] refer to Figure 6 If the time interval R1 to R2 is the runtime of the current frame, and the time interval R2 to R3 is the runtime of the next frame, then at the end of the current frame, the execution function is triggered for the last time in the current frame. Since the next frame contains a fixed task 'a', the execution function will not be triggered during the execution of fixed task 'a'. At the end of fixed task 'a', the execution function is triggered for the first time in the next frame. Because the execution duration of fixed task 'a' is the same as the runtime of the next frame, the time interval between the end of fixed task 'a' and the end of the current frame is equal to the theoretical runtime, and there is no need to add a new non-fixed task in the next frame.

[0103] Based on the methods provided in the above embodiments, the following is a specific execution process of the embodiments of the present invention:

[0104] Example: Execute 100 tasks

[0105] asyncfunctiontestMultipleTask(){

[0106] / / Example: A time-consuming task (approximately 10ms)

[0107] constsingleTask=(j)=>{

[0108] constnow = performance.now()

[0109] while(performance.now()-now<10){}

[0110] }

[0111] / / Example: Execute 100 tasks sequentially. Once j reaches 100, it indicates that all tasks have been completed. for(let j = 1; j <= 100; j++){

[0112] / / Create an instance object P using newPromise (this will create 100 instances).

[0113] awaitnewPromise((resolve)=>{

[0114] / / Execute function A(splitRunTask) in the callback function of p, passing in the singleTask and resolve parameters.

[0115] splitRunTask(singleTask,resolve)})}}

[0116] / / Function A (a recursive function that will be called repeatedly) The first call to this function is triggered manually by the user; subsequent calls are triggered within the requestAnimationFrame.

[0117] functionsplitRunTask(singleTask,resolve){

[0118] / / Record the start time (start(S)) of A each time.

[0119] const start = Date.now() / / Date.now() retrieves the current time; the value obtained after each call is different. / / Method FrequestAnimationFrame (this method is a built-in API in the JavaScript language)

[0120] requestAnimationFrame(()=>{

[0121] const currentTime = Date.now() / / Date.now() retrieves the current time; the value obtained after each call is different.

[0122] const G = currentTime - start / / The time interval between two requestsAnimationFrame method triggers.

[0123] / / If G is less than or equal to the normal refresh interval fpsGap, the current target task is completed, and then resolve is called to enter the judgment logic for the next task.

[0124] if (G <= fpsGap) {

[0125] singleTask() / / Completes the current target task

[0126] `resolve()` / / After the `resolve` method is called, `j` will be incremented, meaning a new instance `P` will be created using `newPromise`. The new object `P` will then determine when the next task should be executed. This process repeats until all tasks are completed.

[0127] }else{

[0128] splitRunTask(singleTask,resolve)}})}

[0129] In this invention, if a new non-fixed task needs to be added in the next frame, the actual runtime of the next frame may differ from the theoretical runtime. For example... Figure 5 As shown, if adding task A in the next frame results in the total execution time of fixed task a and non-fixed task A being the same as the runtime of the next frame, then the actual runtime of the next frame is consistent with the theoretical runtime. Figure 7 As shown, if the total execution time of fixed task a and non-fixed task A is greater than the runtime of the next frame after adding task A in the next frame, then the actual runtime of the next frame is the total execution time of fixed task a and non-fixed task A.

[0130] In this invention, during the execution of any frame, if any task (e.g., a fixed task or a non-fixed task) finishes execution, the execution function is triggered at the task's end time. If the execution function is triggered at a time less than the time when the frame ends according to its theoretical runtime, it indicates that there is still remaining time to execute non-fixed tasks in that frame, and non-fixed tasks are added to that frame. If the execution function is triggered at a time greater than or equal to the time when the frame ends according to its theoretical runtime, then this trigger is the last trigger in that frame, and the trigger time is the end time of that frame.

[0131] refer to Figure 8 The theoretical runtime of each frame is pre-set to be 13.3ms. In the target frame corresponding to time periods R2 and R3, a fixed task 'a' needs to run. The execution function is triggered at the end time of fixed task 'a'. At this time, the trigger time indicates that there is still time remaining in the target frame. A non-fixed task 'A' is added to the target frame. At the end time of non-fixed task 'A', the execution function is triggered again. The trigger time still indicates that there is still time remaining in the target frame (i.e., the sum of the execution time of fixed task 'a' and the execution time of non-fixed task 'A' is less than 13.3ms). Then, non-fixed task 'B' is added. At the end time of non-fixed task 'B', the execution function is triggered again. The trigger time indicates that there is no time remaining in the target frame (e.g., the total execution time of fixed task 'a', non-fixed task 'A', and non-fixed task 'B' is greater than 13.3ms). The target frame runs out. At the end time of non-fixed task 'B', the execution function is triggered for the last time in the target frame.

[0132] By applying the method provided in the embodiments of the present invention, tasks can be added and executed in frames with remaining time, avoiding page lag caused by multiple tasks being executed simultaneously in one frame.

[0133] The specific implementation processes and derivative methods of the above embodiments are all within the protection scope of this invention.

[0134] and Figure 1 Corresponding to the method described above, embodiments of the present invention also provide a task execution device for performing tasks on... Figure 1 The specific implementation of the method, the task execution device provided in this embodiment of the invention, can be applied to computer terminals or various mobile devices, and its structural schematic diagram is shown below. Figure 9 As shown, it specifically includes:

[0135] The first determining unit 901 is used to determine the theoretical runtime of each frame in the browser, wherein each page refresh of the browser is one frame, and the runtime is the refresh time interval required for each page refresh of the browser.

[0136] The acquisition unit 902 is used to acquire at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame;

[0137] Creation unit 903 is used to create instance objects corresponding to each of the non-fixed tasks;

[0138] Trigger unit 904 is used to trigger the execution function when the current frame ends;

[0139] The second determining unit 905 is used to determine whether there is remaining time in the next frame during the execution process based on the trigger time of the execution function and the theoretical running time.

[0140] The execution unit 906 is configured to add at least one instance object during the execution of the next frame if there is remaining time during the execution of the next frame, so as to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame.

[0141] In the apparatus provided in this embodiment of the invention, the first determining unit determines the theoretical runtime of each frame in the browser, specifically for:

[0142] Obtain the browser's refresh rate;

[0143] The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

[0144] In the apparatus provided in this embodiment of the invention, the second determining unit determines whether there is remaining time in the next frame during execution based on the trigger time of the execution function and the theoretical runtime, including:

[0145] Determine the last trigger time of the execution function in the current frame and the first trigger time in the next frame;

[0146] Determine a second time interval between the last trigger time and the first trigger time;

[0147] Determine whether the second time interval is not greater than the theoretical running time;

[0148] If the second time interval is not greater than the theoretical runtime, it is determined that there is remaining time in the next frame during operation;

[0149] The last trigger time of the execution function in the current frame is the time point at which the current frame ends.

[0150] In the apparatus provided in this embodiment of the invention, if there is a fixed task in the next frame, the first trigger time of the execution function in the next frame is the time point when the fixed task finishes execution;

[0151] If there is no fixed task in the next frame, the first trigger time of the execution function in the next frame is the start time of the next frame, and the start time of the next frame is the same as the end time of the current frame.

[0152] The fixed task is a task that is specified to be executed in any frame.

[0153] In the apparatus provided by this embodiment of the invention, the execution unit adds at least one instance object during the execution of the next frame, so as to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame, specifically for:

[0154] In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

[0155] The specific working process of each unit and subunit in the task execution device disclosed in the above embodiments of the present invention can be found in the corresponding content of the task execution method disclosed in the above embodiments of the present invention, and will not be repeated here.

[0156] This invention also provides a storage medium that includes stored instructions, wherein the execution of the instructions controls the device where the storage medium is located to execute the above-described task execution method.

[0157] This invention also provides an electronic device, the structural schematic of which is shown below. Figure 10 As shown, it specifically includes a memory 1001 and one or more instructions 1002, wherein one or more instructions 1002 are stored in the memory 1001 and configured to be executed by one or more processors 1003 to perform the following operations:

[0158] Determine the theoretical runtime of each frame in the browser, where each page refresh of the browser is considered a frame, and the runtime is the refresh time interval required for each page refresh by the browser.

[0159] Obtain at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame;

[0160] Create an instance object corresponding to each of the aforementioned non-fixed tasks;

[0161] The function is triggered when the current frame finishes running;

[0162] Based on the trigger time of the execution function and the theoretical runtime, determine whether there is remaining time in the next frame during execution;

[0163] If there is remaining time during the execution of the next frame, at least one instance object is added during the execution of the next frame to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame.

[0164] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0165] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both.

[0166] To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described in terms of functionality above. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0167] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A task execution method, characterized in that, include: Determine the theoretical runtime of each frame in the browser, where each page refresh of the browser is considered a frame, and the runtime is the refresh time interval required for each page refresh by the browser. Obtain at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame; Create an instance object corresponding to each of the aforementioned non-fixed tasks; The function is triggered when the current frame finishes running; Based on the trigger time of the execution function and the theoretical runtime, determine whether there is remaining time in the next frame during execution; If there is remaining time during the execution of the next frame, at least one instance object is added during the execution of the next frame to execute the non-fixed task corresponding to the at least one instance object during the execution of the next frame. The step of determining whether there is remaining time in the next frame during execution, based on the trigger time of the execution function and the theoretical runtime, includes: Determine the last trigger time of the execution function in the current frame and the first trigger time in the next frame; Determine a second time interval between the last trigger time and the first trigger time; Determine whether the second time interval is not greater than the theoretical running time; If the second time interval is not greater than the theoretical runtime, it is determined that there is remaining time in the next frame during operation.

2. The method according to claim 1, characterized in that, Determining the theoretical runtime of each frame in the browser includes: Obtain the browser's refresh rate; The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

3. The method according to claim 1, characterized in that, The last time the execution function is triggered in the current frame is the time when the current frame ends.

4. The method according to claim 3, characterized in that, If a fixed task exists in the next frame, the first trigger time of the execution function in the next frame is the time point when the fixed task finishes execution; If there is no fixed task in the next frame, the first trigger time of the execution function in the next frame is the start time of the next frame, and the start time of the next frame is the same as the end time of the current frame. The fixed task is a task that is specified to be executed in any frame.

5. The method according to claim 1, characterized in that, Adding at least one instance object during the execution of the next frame to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame includes: In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

6. A task execution device, characterized in that, include: The first determining unit is used to determine the theoretical runtime of each frame in the browser, wherein each page refresh of the browser is one frame, and the runtime is the refresh time interval required for each page refresh of the browser. The acquisition unit is used to acquire at least one non-fixed task to be executed in the browser, wherein the non-fixed task is a task that is not specified to be executed during the execution of any frame; A creation unit is used to create instance objects corresponding to each of the aforementioned non-fixed tasks; The triggering unit is used to trigger the execution function when the current frame ends. The second determining unit is used to determine whether there is remaining time in the next frame during the execution process based on the trigger time of the execution function and the theoretical running time. An execution unit is configured to add at least one instance object during the execution of the next frame if there is remaining time during the execution of the next frame, so as to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame. The second determining unit determines whether there is remaining time in the next frame during execution based on the trigger time of the execution function and the theoretical runtime, including: Determine the last trigger time of the execution function in the current frame and the first trigger time in the next frame; Determine a second time interval between the last trigger time and the first trigger time; Determine whether the second time interval is not greater than the theoretical running time; If the second time interval is not greater than the theoretical runtime, it is determined that there is remaining time in the next frame during operation.

7. The apparatus according to claim 6, characterized in that, The first determining unit determines the theoretical runtime of each frame in the browser, specifically for: Obtain the browser's refresh rate; The theoretical runtime of each frame of the browser is obtained based on the refresh rate.

8. The apparatus according to claim 6, characterized in that, The last time the execution function is triggered in the current frame is the time when the current frame ends.

9. The apparatus according to claim 8, characterized in that, If a fixed task exists in the next frame, the first trigger time of the execution function in the next frame is the time point when the fixed task finishes execution; If there is no fixed task in the next frame, the first trigger time of the execution function in the next frame is the start time of the next frame, and the start time of the next frame is the same as the end time of the current frame. The fixed task is a task that is specified to be executed in any frame.

10. The apparatus according to claim 6, characterized in that, The execution unit adds at least one instance object during the execution of the next frame to execute a non-fixed task corresponding to the at least one instance object during the execution of the next frame, specifically for: In the next frame, a pre-set callback function is triggered to add individual instance objects in a pre-set order, and after each individual instance object is added, the execution of the non-fixed task corresponding to the added instance object is monitored.

Citation Information

Patent Citations

  • Frame based clock rate adjustment for processing unit

    US20170220062A1

  • H5 page-based animation display method, apparatus and device, and storage medium

    WO2020233056A1