CN115981822A - Task processing method, medium, device and computing equipment - Google Patents
Task processing method, medium, device and computing equipment Download PDFInfo
- Publication number
- CN115981822A CN115981822A CN202310014439.9A CN202310014439A CN115981822A CN 115981822 A CN115981822 A CN 115981822A CN 202310014439 A CN202310014439 A CN 202310014439A CN 115981822 A CN115981822 A CN 115981822A
- Authority
- CN
- China
- Prior art keywords
- task
- time
- processed
- rendering
- queue
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the disclosure provides a task processing method. The task processing method comprises the following steps: determining an idle time slice of a current frame, wherein the starting time of the idle time slice is the time when a User Interface (UI) thread starts to idle, and the ending time of the idle time slice is the ending time of the current frame; acquiring a target task of which the task processing duration is less than or equal to the idle time slice; within the idle time slice, the target task is executed. By acquiring the idle time slice of each frame, the executable time-consuming target task is executed in the idle time slice, so that the pause or frame skipping of the UI thread is avoided, and better experience is brought to a user. In addition, the embodiment of the disclosure provides a medium, a task processing device and a computing device.
Description
Technical Field
Embodiments of the present disclosure relate to the field of computers, and more particularly, to a task processing method, medium, apparatus, and computing device.
Background
This section is intended to provide a background or context to the embodiments of the disclosure that are recited in the claims. The description herein is not admitted to be prior art by inclusion in this section.
In an Android operating system, there are usually some time-consuming tasks (abbreviated as "time-consuming tasks") to be executed, and these time-consuming tasks are generally processed in a child thread to avoid a User Interface (UI) thread jamming situation. Inevitably, however, there are still time-consuming tasks that must be performed in the UI thread, resulting in a stuck condition where the UI thread performs the time-consuming tasks.
In the related art, in order to solve the problem that the UI thread is stuck when executing the time consuming task, after the UI thread finishes processing the time consuming tasks such as the UI rendering task at the current time point and the user-defined time consuming task, the task scheduler provided by the Android system is executed to execute other time consuming tasks scheduled by the task scheduler. There may still be problems with stutter or frame skipping of UI threads.
Disclosure of Invention
The invention provides a task processing method which can avoid the pause or the frame skipping of a UI thread.
In a first aspect of embodiments of the present disclosure, a task processing method is provided, including: determining an idle time slice of a current frame, wherein the starting time of the idle time slice is the time when a User Interface (UI) thread starts to idle, and the ending time of the idle time slice is the ending time of the current frame; acquiring a target task of which the task processing duration is less than or equal to the idle time slice; and executing the target task in the idle time slice.
In one embodiment of the present disclosure, acquiring a target task with a task processing duration less than or equal to an idle time slice includes: the method comprises the steps that a task list is obtained, wherein the task list comprises at least one task queue, the task processing time length of a task to be processed contained in each task queue is the same, and the task processing time lengths of the tasks to be processed contained in different task queues are different; determining a first task queue in a task list, wherein the task processing time length corresponding to the first task queue is less than or equal to the idle time slice; a target task is determined in a first task queue.
In another embodiment of the present disclosure, before acquiring the task list, the method further includes: constructing at least one task queue in a task list by adopting a linked list structure; acquiring a task to be processed; and adding the acquired task to be processed to a second task queue in the task list to obtain the task list, wherein the task processing time length corresponding to the second task queue is the same as the task processing time length of the acquired task to be processed.
In another embodiment of the present disclosure, adding the obtained to-be-processed task to a second task queue in the task list includes: in response to the fact that the task processing duration of the obtained tasks to be processed is smaller than or equal to a preset value, adding the obtained tasks to be processed to a second task queue, wherein the number of the second task queue is one; in response to the fact that the task processing duration of the obtained task to be processed is larger than a preset value, splitting the obtained task to be processed to obtain a plurality of subtasks; and adding a plurality of subtasks to a second task queue according to the task processing duration of the subtasks, wherein the number of the second task queue is multiple.
In still another embodiment of the present disclosure, further comprising: determining the historical task processing duration of the acquired task to be processed within a preset time range; and determining the maximum value in the historical task processing time length as the acquired task processing time length of the task to be processed.
In another embodiment of the present disclosure, before adding the obtained task to be processed to the second task queue in the task list, the method further includes: and binding the task to be processed with the life cycle of the page where the current frame is located.
In still another embodiment of the present disclosure, after the target task is executed in the idle time slice, the method further includes: determining and storing the execution duration of the target task in the idle time slice; and updating the idle time slice according to the execution duration.
In yet another embodiment of the present disclosure, at least one task queue in the task list is arranged in the order of the corresponding task processing time lengths from small to large; the task processing method further comprises the following steps: in response to monitoring flag information for indicating task scheduling timeout, determining a first non-empty task queue in a task list as a third task queue; and acquiring a first task in the third task queue for execution.
In still another embodiment of the present disclosure, further comprising: and after the execution of the task is completed, deleting the task which is completed in the corresponding task queue.
In yet another embodiment of the present disclosure, determining an idle temporal slice of a current frame comprises: acquiring the starting time and the ending time of the rendering task of the current frame; determining the rendering duration of the rendering task according to the starting time and the ending time; and determining the difference value of the refreshing time length and the rendering time length of the current frame as an idle time slice, wherein the refreshing time length is determined by the refreshing frequency of a user interface, and the refreshing time length is greater than or equal to the rendering time length.
In still another embodiment of the present disclosure, acquiring a rendering start time and a rendering end time of a current frame includes: calling a first monitoring callback function of the current frame, and determining the rendering starting time, wherein the first monitoring callback function is used for monitoring the starting time of a rendering task; and calling a second monitoring callback function of the current frame, and determining the rendering ending time, wherein the second monitoring callback function is used for monitoring the ending time of the rendering task.
In a second aspect of embodiments of the present disclosure, there is provided a medium having stored therein computer-executable instructions for implementing the task processing method as in the first aspect when executed by a processor.
In a third aspect of the disclosed embodiments, there is provided a task processing device comprising: the determining module is used for determining the idle time slice of the current frame, the starting time of the idle time slice is the time when the UI thread of the user interface starts to idle, and the ending time of the idle time slice is the ending time of the current frame; the acquisition module is used for acquiring a target task of which the task processing duration is less than or equal to the idle time slice; and the execution module is used for executing the target task in the idle time slice.
In a fourth aspect of embodiments of the present disclosure, there is provided a computing device comprising: a processor, and a memory coupled to the processor; the memory stores computer-executable instructions; the processor executes computer-executable instructions stored by the memory to implement the method of task processing as in the first aspect.
According to the task processing method of the embodiment of the disclosure, the idle time slice of each frame of the UI thread is determined, so that the UI thread can execute the executable time-consuming task in the idle time slice, and therefore, the problems of pause and frame skipping of the UI thread can not occur, the waiting time of the UI thread is reduced, the resource utilization rate of the UI thread is improved, and better experience is brought to a user.
Drawings
The above and other objects, features and advantages of exemplary embodiments of the present disclosure will become readily apparent from the following detailed description read in conjunction with the accompanying drawings. Several embodiments of the present disclosure are illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings and in which:
fig. 1 is a schematic view of an application scenario of a task processing method according to an embodiment of the present disclosure;
FIG. 2 is a schematic flow chart diagram of a task processing method according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of a task list according to an embodiment of the disclosure;
FIG. 4 is a diagram illustrating determining a task processing duration for a task according to an embodiment of the disclosure;
FIG. 5 is a schematic flow chart of tasks performed by the disclosed embodiments;
FIG. 6 is a schematic diagram illustrating a process of performing a rendering task according to an embodiment of the present disclosure;
fig. 7 is a schematic diagram of determining a start time and an end time of a current frame rendering task according to an embodiment of the present disclosure;
FIG. 8 is a flow diagram illustrating the determination of an idle time slice according to an embodiment of the present disclosure;
FIG. 9 is a schematic structural diagram of a storage medium according to an embodiment of the disclosure;
fig. 10 is a schematic structural diagram of a task processing device according to an embodiment of the present disclosure;
fig. 11 is a schematic structural diagram of a computing device according to an embodiment of the present disclosure.
In the drawings, like or corresponding reference characters designate like or corresponding parts.
Detailed Description
The principles and spirit of the present disclosure will be described with reference to a number of exemplary embodiments. It is understood that these embodiments are given solely for the purpose of enabling those skilled in the art to better understand and to practice the present disclosure, and are not intended to limit the scope of the present disclosure in any way. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
As will be appreciated by one of skill in the art, embodiments of the present disclosure may be embodied as a system, apparatus, device, method, or computer program product. Accordingly, the present disclosure may be embodied in the form of: entirely hardware, entirely software (including firmware, resident software, micro-code, etc.), or a combination of hardware and software.
According to the embodiment of the disclosure, a task processing method, a medium, a device and a computing device are provided. In this context, it is to be understood that the terms involved are to be interpreted as follows:
hertz (Hertz, hz for short): is the unit of frequency in the international system of units, and is the measurement of the number of repeated periodic fluctuation times per second. Once per second vibration (or oscillation, wave) is 1 hz. The refresh frequency of the LED display screen of the intelligent terminal is 60HZ, which means that the LED display screen is refreshed 60 times per second.
Frame rate (Frame rate): is the frequency (rate) at which the bitmap image appears continuously on the display in units of frames. The term applies equally to film and video cameras, computer graphics and motion capture systems. The frame rate may also be referred to as a frame frequency and is expressed in hertz (Hz).
User Interface (UI) thread: the method is realized by adding a message loop on the basis of a common sub-thread (namely a worker thread), continuously acquiring messages sent by the operating system or other threads (namely, executing the for loop in the thread), finding a corresponding message processing object/function according to the messages, and if no message needs to be processed temporarily, enabling a UI thread to wait to give a time slice of a central processing unit (CPU for short) so as to show the state that the UI thread is always in an on-line state until a certain specific quit message finishes the UI thread. On the Android system, all page rendering is performed in the UI thread, so time-consuming tasks cannot be put in the UI thread.
And (3) sub-thread: in order to avoid interface operation blockage caused by long-time task processing of the UI thread, user experience is improved, complex tasks are completed through the worker thread, the worker thread can be immediately quitted after the tasks are processed, and the worker thread can continue to wait for new tasks to see actual requirements. The worker thread which is not quitted but is in a waiting state after the task is processed is equivalent to the UI thread, namely, the worker thread can realize a task queue by itself and then continuously acquire the task to achieve the effect of the UI thread.
Frame skipping: on the Hz basis, if the refresh rate set by the display is 60Hz, i.e. 16.6ms refreshes the display once, then each 16.6ms phase requires the completion of the rendering of the UI and the time consuming task of the UI thread. If these time consuming tasks exceed 16.6ms, the rendering is skipped for the next frame, and the next frame is not rendered until the rendering of the current frame is completed, which is a frame skip.
Blocking: generally, the speed of the human eye for identifying the consecutive images is 24 frames/second, as long as the speed of the consecutive images exceeds 24 frames/second, the current consecutive images are considered to be smooth, and if the speed of the consecutive images is lower than 24 frames/second, the current consecutive images are considered to be less consecutive. When continuously skipping a plurality of frames, for example 10 frames, that is, 166ms, at the same time, about 6 frames/second on a frame skipping basis, the current consecutive image is obviously felt to be dull and slow in response, which is called katon.
Slicing idle time: on the Hz basis, taking a 60Hz refresh rate display as an example, in each 16.6ms period, when rendering of the UI and time consuming tasks of the UI thread are completed, the remaining time is called idle time slice.
Vertical Synchronization (VSYNC) signal: for synchronizing the number of Frames Per Second (Frames Per Second, FPS for short) and the refresh rate of the display. The aim is to avoid a phenomenon known as "tearing". Without the vertical synchronization signal, when the frame data rendered by the engine is fast, the display refresh rate cannot keep up, and tearing may occur, such as when the current display is displaying a certain frame and another frame triggers to be displayed on the display.
Furthermore, the number of any elements in the drawings is intended to be illustrative and not restrictive, and any nomenclature is used for distinction only and not for any restrictive meaning.
In addition, the data related to the present disclosure may be data authorized by a user or fully authorized by each party, and the collection, transmission, use, and the like of the data all meet the requirements of relevant national laws and regulations, and the embodiments/examples of the present disclosure may be combined with each other.
The principles and spirit of the present disclosure are explained in detail below with reference to several representative embodiments of the present disclosure.
Summary of The Invention
The inventor finds that in an Android system, some time-consuming tasks are usually required to be executed, and the time-consuming tasks are generally processed in a sub-thread, so that the phenomenon that a UI thread (namely a main thread) is stuck is avoided. In the related art, in order to solve the problem of deadlock caused by the execution of the time-consuming task by the UI thread, after the UI thread finishes processing the time-consuming tasks such as the UI rendering task at the current time point and the user-defined time-consuming task, the task scheduler provided by the Android system is executed to execute other time-consuming tasks scheduled by the task scheduler. However, if the time consumed by the UI thread to execute the task scheduler is too long, the UI thread may still be stuck or skipped, and if the task in the task scheduler needs to be adjusted, the task cannot be partially removed, but only the task can be completely removed. Therefore, in the related art, the rendering start time and the rendering end time of each frame on the Android system cannot be monitored, a user-defined time-consuming task cannot be started after a first UI frame is displayed after an Application (APP) page is started, or the rendering duration of the first UI frame is counted; in addition, the idle time slice cannot be accurately utilized in the related art, when the UI thread is in the idle time, all UI thread time consuming tasks may be executed, and since both the idle time slice and the UI thread time consuming tasks are uncertain time consumption, the time length of one frame of the UI thread is easily exceeded by 16.6ms when the UI thread executes the time consuming tasks, thereby causing a frame skipping or a stuck problem.
Therefore, the present disclosure provides a task processing method, wherein for each frame of rendering task processed by a UI thread, in the execution process of the rendering task, a rendering start time and a rendering end time of the rendering task may be obtained, and a task processing duration of the rendering task in the UI thread may be determined according to the rendering start time and the rendering end time, so that an idle time slice of each frame may be determined according to the duration of each frame and the task processing duration of the rendering task in the UI thread. And then matching the time-consuming tasks with corresponding time lengths according to the idle time slices, wherein the UI thread can execute the time-consuming tasks with corresponding time lengths in the idle time slices, so that the problems of unsmooth UI thread and frame skipping caused by overlong time consumption of executing the tasks are avoided.
Having described the general principles of the present disclosure, various non-limiting embodiments of the present disclosure are described in detail below.
Application scene overview
Referring to fig. 1, fig. 1 is a schematic view of an application scenario of a task processing method according to an embodiment of the present disclosure. In fig. 1, the task processing method may be applied to a task processing system, which may be deployed on an Android operating system and may include a rendering time consumption monitoring module, an idle time slicing module, and a task scheduling module.
In the scene, the rendering starting time and the rendering ending time of the rendering task of each frame of the UI thread on the Android operating system can be determined through the rendering time consumption monitoring module, and the rendering time consumption of the rendering task of each frame can be determined through the rendering starting time and the rendering ending time. The idle time slicing module may obtain the rendering time consumption of each frame of the rendering task monitored by the rendering time consumption monitoring module, and then determine the idle time slice of each frame according to the total time length and the rendering time consumption of each frame, that is, a difference value between the total time length and the rendering time consumption of each frame is the time length of the idle time slice. The task scheduling module can divide the time-consuming task on the UI thread into a plurality of subtasks with the same or different task processing time lengths, and the subtasks are matched with the idle time slices determined by the idle time slice module according to the task processing time length of each subtask, so that each subtask is executed in a proper idle time slice.
In the above scenario, because the rendering time of the rendering task of each frame may be monitored, the idle time slice of each frame may be obtained, and the time-consuming task may be allocated to a suitable idle time slice for execution, so that the problems of stumbling and frame skipping of the UI thread may be avoided, and the time utilization rate of the UI thread may also be improved.
Exemplary method
In connection with the application scenario of fig. 1, a task processing method according to an exemplary embodiment of the present disclosure is described below with reference to fig. 2. It should be noted that the above application scenarios are only illustrated for the convenience of understanding the spirit and principles of the present disclosure, and the embodiments of the present disclosure are not limited in any way in this respect. Rather, embodiments of the present disclosure may be applied to any scenario where applicable.
Referring to fig. 2, fig. 2 is a schematic flowchart of a task processing method according to an embodiment of the present disclosure, and as shown in fig. 2, the task processing method includes the following steps:
s201: an idle temporal slice of the current frame is determined.
In this step, the start time of the idle time slice is the time when the UI thread starts to idle, and the end time of the idle time slice is the end time of the current frame.
Specifically, the screen refresh frequency of the same operating system is fixed, and therefore, the duration of each frame is fixed, and the UI thread performs rendering tasks at each frame, and therefore, there may be idle time slices at each frame. The starting time of the idle time slice is the time when the UI thread starts to idle at the current frame, namely the execution ending time of the rendering task of the current frame; the end time of the idle time slice is the end time of the current frame, that is, the idle time slice is a time period from the end of the execution of the rendering task of the current frame to the end of the current frame.
S202: and acquiring a target task of which the task processing duration is less than or equal to the idle time slice.
Specifically, the task processing time of the time-consuming task executed by the UI thread is too long, and may exceed the time of the idle time slice, which may cause the stutter and frame skipping of the UI thread, therefore, when task scheduling is performed, in order to avoid the stutter and frame skipping problem of the UI thread, after the idle time slice of the current frame is determined, a target task suitable for being executed in the idle time slice may be determined, that is, a target task whose task processing time is less than or equal to the idle time slice is obtained, for example, if the idle time slice of the current frame is 3ms, the target task is a task of 3ms or less. Therefore, when the target task is executed, the UI thread does not have the problem of pause or frame skipping.
S203: within the idle time slice, the target task is executed.
Specifically, after the target task is obtained, the UI thread may execute the target task in the idle time slice, and since the task processing duration of the target task is less than or equal to the idle time slice, the UI thread does not have the problems of jamming and frame skipping.
According to the task processing method, the idle time slice of the current frame is determined, and then the target task with the task processing duration less than or equal to the idle time slice is obtained, so that the problems of blocking and frame skipping cannot occur when the UI thread executes the target task in the idle time slice, and in addition, the time utilization rate of the UI thread can be improved.
In one embodiment of the present disclosure, acquiring a target task with a task processing duration less than or equal to an idle time slice includes: the method comprises the steps that a task list is obtained, wherein the task list comprises at least one task queue, the task processing time length of a task to be processed contained in each task queue is the same, and the task processing time lengths of the tasks to be processed contained in different task queues are different; determining a first task queue in a task list, wherein the task processing time length corresponding to the first task queue is less than or equal to the idle time slice; a target task is determined in a first task queue.
In this embodiment, when the target task whose task processing duration is less than or equal to the idle time slice is obtained, a task list including at least one task queue may be obtained first, the task processing duration of the to-be-processed task included in each task queue in the task list is the same, and the task processing durations of the to-be-processed tasks included in different task queues are different. After the task list is obtained, a corresponding first task queue may be determined in the task list according to the idle time slice, and then a target task is determined in the first task queue.
Specifically, when the target task is determined, a first task queue may be determined in the task list, and the number of the first task queues may be multiple, for example, if the duration of the idle time slice is 5ms, there may be 5 first task queues, which are respectively a task queue corresponding to 1ms, a task queue corresponding to 2ms, a task queue corresponding to 3ms, a task queue corresponding to 4ms, and a task queue corresponding to 5 ms. When the target task is determined in the first task queue, the first task in the task queue corresponding to 1ms may be determined as the target task, the first task in the task queue corresponding to 5ms may be determined as the target task, or the first task in any one of the 5 task queues may be determined as the target task. By determining the idle time slice and determining a proper target task through the task list, the problems of pause and frame skipping caused by too long time consumption of the UI thread to execute the task can be avoided, and the time utilization rate of the UI thread can be improved.
Alternatively, the task queues in the task list may be a linked list structure.
In an embodiment of the present disclosure, before acquiring the task list, the method further includes: constructing at least one task queue in a task list by adopting a linked list structure; acquiring a task to be processed; and adding the acquired task to be processed to a second task queue in the task list to obtain the task list, wherein the task processing time length corresponding to the second task queue is the same as the task processing time length of the acquired task to be processed.
In this embodiment, taking an Android operating system as an example, the refresh frequency of the screen is 60Hz/s, that is, 16.6 ms/frame, and therefore, the frame rate is recalled every 16.6ms, so that the task processing duration of the efficient reading task is required. Therefore, at least one task queue in the task list can be constructed by adopting a linked list structure, and the adding and deleting efficiency of the tasks stored in the task queue and the query efficiency of the task processing time length are improved.
Specifically, the task list may be implemented by using a hash mapping (hash map) table, where the hash map table includes a keyword KEY and a VALUE, where the KEY is INT type, the task processing duration of the task is used as the KEY, and a task queue corresponding to the VALUE is a linked list structure and is used to store all tasks corresponding to the current task processing duration KEY. As shown in fig. 3, fig. 3 is a schematic structural diagram of a task list according to an embodiment of the present disclosure, in fig. 3, a KEY takes 1ms to 10ms as an example, the KEY increases by 1ms, the VALUE takes 1ms to 10ms as an example, and linked lists storing tasks are respectively corresponding to each other, and each linked list takes 4 tasks as an example. In practical application, the value of the KEY can be modified as required, and tasks stored in the linked list can be added or deleted as required.
Specifically, after the task list is constructed, the task to be processed may be obtained, then the task processing duration of the task to be processed is determined, and the task to be processed is stored in the corresponding linked list, that is, the second task queue, according to the task processing duration of the task to be processed.
Alternatively, the task to be processed may be started to fetch when the UI thread is detected to be idle.
In an embodiment of the present disclosure, adding the obtained task to be processed to a second task queue in a task list includes: in response to the fact that the task processing duration of the obtained tasks to be processed is smaller than or equal to a preset value, adding the obtained tasks to be processed to a second task queue, wherein the number of the second task queue is one; in response to the fact that the task processing duration of the obtained task to be processed is larger than a preset value, splitting the obtained task to be processed to obtain a plurality of subtasks; and adding a plurality of subtasks to a second task queue according to the task processing duration of the subtasks, wherein the number of the second task queue is multiple.
In this embodiment, when adding the task to be processed to the second task queue, the task processing time of the task to be processed may be determined first, and if a task queue that can be matched exists in the current task list, for example, the task processing time of the task to be processed is 6ms, and a linked list corresponding to 6ms exists in the task list, the task to be processed may be stored in the linked list corresponding to 6ms, where the second task queue is the linked list corresponding to 6 ms; if no task queue which can be matched exists in the current task list, for example, the task processing time of the task to be processed is 10ms, a linked list corresponding to 10ms does not exist in the task list, and a linked list corresponding to 3ms and a linked list corresponding to 4ms exist, the task to be processed can be split, two subtasks of 3ms and one subtask of 4ms are obtained, then the subtasks are stored in the corresponding linked lists, and at this time, the second task queue is the linked list corresponding to 3ms and the linked list corresponding to 4 ms.
Optionally, the task to be processed is stored in the task list, and a suitable target task can be matched in the task list according to the idle time slice, so as to execute the target task, thereby improving the efficiency of determining the target task, avoiding the pause and frame skipping of the UI thread when executing the task, and improving the time utilization rate of the UI thread.
In one embodiment of the present disclosure, further comprising: determining the historical task processing duration of the acquired task to be processed within a preset time range; and determining the maximum value in the historical task processing time length as the acquired task processing time length of the task to be processed.
In this embodiment, each to-be-processed task is in a different operating system, and task processing durations of the to-be-processed tasks at different times may also be different in the same operating system, so that historical task processing durations of the to-be-processed tasks within a preset time range may be obtained, then a maximum value of the historical task processing durations may be determined, and the maximum value is determined as a task processing duration of a current to-be-processed task, thereby ensuring that the problems of stumbling and frame skipping do not occur when a UI thread executes the to-be-processed task. Even though the read task processing time length of the to-be-processed task may be smaller than the actual execution time length of the to-be-processed task, the stutter and the frame skipping of the UI thread can be ignored only by a difference of a few milliseconds.
For example, if the idle time slice is 6ms, the task to be processed that can be completed within 6ms needs to be determined. The first task processing duration of the current task to be processed may be a default duration (an actual task execution duration obtained after the developer executes on the operating system) provided by the developer, after the task to be processed is executed once, the actual task processing duration on the current operating system may be stored, and when the task processing duration of the task to be processed is obtained subsequently, the maximum value of the historical task processing duration may be taken out to serve as the task processing duration of the task to be processed. Each pending task may be saved the last 5 times the task processing duration. As shown in fig. 4.
Fig. 4 is a schematic diagram of determining task processing durations of tasks according to an embodiment of the present disclosure, in fig. 4, taking a task a as an example, there is no historical task processing duration when the task processing duration of the task a is read for the first time, so that the task processing duration for the first time is a default duration of 3ms, when the task a is executed for the first time, the actual task time is 5ms, and 5ms is saved; the task processing time for reading the task A for the second time is 5ms, the actual task time consumption is 4ms when the task A is executed for the second time, and 5ms and 4ms are stored; the task processing time for reading the task A for the third time is 5ms, the actual task time consumption is 7ms when the task A is executed for the third time, and 5ms, 4ms and 7ms are stored; the task processing time for reading the task A for the fourth time is 7ms, the actual task time consumption is 6ms when the task A is executed for the fourth time, and 5ms, 4ms, 7ms and 6ms are stored; the task processing time for reading the task A for the fifth time is 7ms, the actual task time consumption is 4ms when the task A is executed for the fifth time, and 5ms, 4ms, 7ms, 6ms and 4ms are saved; the task processing time for reading the task A for the sixth time is 7ms, the actual task time is 3ms when the task A is executed for the sixth time, and 4ms, 7ms, 6ms, 4ms and 3ms are stored.
Specifically, the data of the historical task processing duration of all the tasks to be processed are stored in a Secure Digital Card (SD Card for short), when the APP of the intelligent terminal is started, the sub-thread loads the data of the task processing duration and loads the data into the operating Memory of the intelligent terminal, so as to accelerate the speed of subsequently reading the task processing duration. After the execution of the current task to be processed is finished, the acquired processing duration of the current task needs to be updated into an operating memory, and when the APP page is closed, data are uniformly written into the SD card.
Specifically, after the historical task processing duration of the task to be processed is determined, the task to be processed and the historical task processing duration can be bound, so that the task processing duration of the task to be processed can be rapidly read in the follow-up process, and the task to be processed matched with the idle time slice can be rapidly acquired.
In an embodiment of the present disclosure, before adding the obtained task to be processed to the second task queue in the task list, the method further includes: and binding the task to be processed with the life cycle of the page where the current frame is located.
In this embodiment, in order to avoid memory resource waste caused by the fact that the to-be-processed task is not deleted after the page is destroyed, the to-be-processed task and the life cycle of the page where the current frame is located may be bound, so that the bound to-be-processed task is also automatically deleted after the page is destroyed, thereby avoiding memory leakage.
Specifically, after the to-be-processed task and the life cycle of the page where the current frame is located are bound, the to-be-processed task may be added to the task list.
In an embodiment of the present disclosure, after the target task is executed in the idle time slice, the method further includes: determining and storing the execution duration of the target task in the idle time slice; and updating the idle time slice according to the execution duration.
In this embodiment, after the UI thread executes the target task in the current idle time slice, the idle time slice of the current frame may change, so that the execution duration of the target task in the idle time slice may be determined and stored, and then the execution duration of the target task is subtracted from the duration of the idle time slice before the target task is executed to obtain a new idle time slice, thereby updating the idle time slice, facilitating subsequent continuous matching of the executable task, and avoiding waste of the idle time slice.
In one embodiment of the present disclosure, at least one task queue in the task list is arranged according to the order of the corresponding task processing time lengths from small to large; the task processing method further comprises the following steps: in response to monitoring flag information for indicating task scheduling timeout, determining a first non-empty task queue in a task list as a third task queue; and acquiring the first task in the third task queue for execution.
In this embodiment, the task list may include a plurality of task queues, and the KEY corresponding to each task queue is the task processing time length of the task to be processed in the task queue, so as to facilitate matching between the task to be processed and the idle time slice, and also facilitate executing the task to be processed, the task queues may be sorted in the order of the KEY from small to large.
Specifically, taking the Android operating system as an example, the duration of each frame is 16.6ms, and therefore, the maximum duration of the idle time slice does not exceed 16.6ms. When different operating systems or models of intelligent terminals are different, due to machine performance differences, actual execution time of each task to be processed may exceed 16.6ms, so that some tasks to be processed cannot be matched with the duration of an idle time slice all the time, and task scheduling is overtime. Therefore, when the task queue is within the preset duration, for example, within 1s, no task to be processed is scheduled to be executed (under the condition of 60Hz, 60 frame rate calls will be performed in 1s, that is, 60 task scheduling executions will be performed), but the task queue is not empty, it may be said that there is a task to be processed whose scheduling is abnormally overtime currently, and in order to ensure normal execution of all tasks to be processed, flag information of task scheduling overtime may be set. When the flag information used for indicating the task scheduling timeout is monitored, the first non-empty task queue in the task list, namely the first task in the third task queue, is directly obtained to be executed, and the idle time slice of the current frame does not need to be obtained, so that all the added tasks to be processed in the task list can be executed no matter whether the idle time slice is matched or not.
Optionally, after monitoring flag information indicating that the task scheduling is overtime, the current abnormal scheduling task may be reported to a developer, and the developer determines an abnormal reason of the abnormal scheduling, where the abnormal reason may include that the machine performance of the intelligent terminal is abnormal and/or the abnormal scheduling task is not split reasonably.
Optionally, when a task to be executed is acquired from the task list, whether a task element exists may be queried in the task list, and if the task element does not exist, or the existing task element does not match the idle time slice, it is determined that an executable sub-task does not exist in the task list.
In one embodiment of the present disclosure, further comprising: and after the execution of the task is completed, deleting the task which is completed in the corresponding task queue.
In this embodiment, in order to save the storage space of the task list, after the task is completed, the completed task may be deleted in the task queue. When executing the tasks in the task queue, because the task processing time lengths of all the tasks in the same task queue are the same, the execution can be started from the first task in the task queue, the task is deleted after the execution is finished, and then the first task in the task queue after the deletion processing is executed again next time, so that all the tasks in the task queue are ensured to be unexecuted, and the efficiency of querying the tasks in the task list can be further improved.
In an embodiment of the present disclosure, a flow of the UI thread executing the task may also be as shown in fig. 5, where fig. 5 is a schematic flow diagram of the UI thread executing the task according to an embodiment of the present disclosure, and in fig. 5, the UI thread executing the task may include the following steps:
s501: it is determined whether there are pending tasks that need to be added to the task list.
Specifically, if present, the process proceeds to step S502, and if not, the process proceeds to step S504.
S502: and carrying out data binding processing on the task to be processed.
Specifically, the task to be processed is bound with the life cycle of the page where the current frame is located, and the task to be processed is bound with the processing duration of the historical task.
S503: and adding a task to be processed.
Specifically, whether to split the task to be processed is determined according to the task processing duration of the task to be processed, if the task to be processed is not split, the task to be processed is added to an appropriate task queue in the task list according to the task processing duration of the task to be processed, and if the task to be processed is split, each subtask is added to an appropriate task queue in the task list according to the task processing duration of the subtask obtained after splitting.
S504: it is determined whether there are executable tasks in the task list.
Specifically, if the current value is present, the process proceeds to step S505, and if the current value is not present, the process ends.
S505: it is determined whether flag information indicating a task schedule timeout currently exists.
Specifically, if not, the process goes to step S506, and if so, the process goes to step S510.
S506: an idle time slice is obtained.
S507: a task queue is determined in the task list that matches the free time slice.
S508: it is determined whether a task exists in the task queue that matches the free time slice.
Specifically, if the current value is present, the process proceeds to step S509, and if the current value is not present, the process ends.
S509: the first task in the task queue that matches the free time slice is executed.
S510: a first task of a first non-empty queue in a task list is obtained.
S511: a first task of a first non-empty queue is executed.
In one embodiment of the present disclosure, determining an idle temporal slice of a current frame comprises: acquiring the starting time and the ending time of the rendering task of the current frame; determining the rendering duration of the rendering task according to the starting time and the ending time; and determining the difference value of the refreshing time length and the rendering time length of the current frame as an idle time slice, wherein the refreshing time length is determined by the refreshing frequency of a user interface, and the refreshing time length is greater than or equal to the rendering time length.
In this embodiment, taking the Android operating system as an example, the screen refresh is 60Hz/s, that is, 16.6 ms/frame, and since the system starts to perform the calculation and rendering of the page view tree when receiving the refresh signal (that is, the vertical synchronization signal VSYNC signal), each frame needs to receive the VSYNC signal to start to perform the rendering task, and before the next frame of VSYNC signal arrives, the rendering task of the current frame needs to be completed. The rendering task on the operating system is divided into two stages, which are the measurement, layout, and drawing of the page view tree in the APP calculation stage, and the rendering at the system level, as shown in fig. 6.
Fig. 6 is a schematic diagram illustrating an execution process of a rendering task according to an embodiment of the disclosure, in fig. 6, taking 8 frames as an example, a duration of each frame is 16.6ms, and the rendering task is started to be executed every frame when a vertical synchronization signal VSYNC signal is received. The APP calculation stage is executed in the UI thread, a rendering (render) function of each frame starts to execute measurement, layout and drawing of the page view tree, after the rendering function finishes the measurement, layout and drawing of the page view tree, the rendering work of the UI thread of the current frame can be considered to be finished, and the next VSYNC signal is waited to be received; the system rendering stage is executed in other threads and/or processes, the system starts rendering after the render function finishes the measurement, layout and drawing of the page view tree, and the view is rendered on the screen, so that the UI thread starts idling after the render function finishes the measurement, layout and drawing of the page view tree, other time-consuming tasks can be executed by utilizing the idle time of the UI thread, the time utilization rate of the UI thread is improved, and the problems of pause and frame skipping caused by long time for the UI thread to execute other time-consuming tasks can be avoided.
Specifically, in the APP calculation stage, since the complexity of the page view tree required to be calculated for each frame may be different, the render time consumption of each frame shown in fig. 6 is also different, so that the render time consumption of the APP calculation stage, i.e., the start time and the end time of the rendering task of each frame, needs to be monitored after each VSYNC signal arrives. According to the starting time and the ending time, the rendering time length of the rendering task, that is, render time length can be determined, so that the difference value between the refresh time length and the rendering time length of the current frame can be determined as an idle time slice, and the refresh time length is 16.6ms in fig. 6. For example, if the refresh duration of the current frame is 16.6ms and the render time, i.e., rendering duration, is 6ms, the idle time slice is 16.6-6=10.6ms.
In one embodiment of the present disclosure, acquiring a rendering start time and a rendering end time of a current frame includes: calling a first monitoring callback function of the current frame, and determining the rendering starting time, wherein the first monitoring callback function is used for monitoring the starting time of a rendering task; and calling a second monitoring callback function of the current frame to determine the rendering ending time, wherein the second monitoring callback function is used for monitoring the ending time of the rendering task.
In this embodiment, in the APP calculation stage of the current frame, a chord graph player similar to the computation of the APP view tree and the screen interactive rendering may be introduced into the render function, the chord graph player object monitors the VSYNC signal, after the VSYNC signal arrives, the render is notified to perform the computation processing of the APP view tree, and after the computation processing of the APP view tree is completed, the chord graph player object delivers the computed data to the screen for rendering. Alternatively, the chord graph object may be used to determine the start time and the end time of the rendering task by means of reflection of a Java Virtual Machine (JVM).
Specifically, the start time and the end time of the rendering task of each frame are determined through a system HOOK (HOOK) mechanism, that is, the start time and the end time of the rendering task of each frame are determined through a snoop callback function, and the snoop callback function includes a first snoop callback function and a second snoop callback function, where the first snoop callback function may also be referred to as a start rendering snoop callback function, and the second snoop callback function may also be referred to as an end rendering snoop callback function. Determining the start time and the end time of the rendering task for each frame may be as shown in fig. 7.
Fig. 7 is a schematic diagram illustrating determining a start time and an end time of a current frame rendering task according to an embodiment of the present disclosure, in fig. 7, in a render process of a page view tree, four callback functions may be included, which are an input callback function input _ callback, an animation callback function animation _ callback, a traversal callback function traversal _ callback, and a commit callback function commit _ callback, respectively, and the render completes measurement, layout, and drawing of the page view tree through the four callback functions. When the starting time and the ending time of the rendering task are determined, a rendering and listening start callback function can be inserted after a VSYNC signal is received and before an input _ callback, and a rendering and listening ending callback function can be inserted after the measurement, layout and drawing of the page view tree are ended, namely after a reverse _ callback, so that the starting time of the rendering task can be determined by the rendering and listening start callback function, and the ending time of the rendering task can be determined by the rendering and listening ending callback function. Therefore, the idle time slice can be determined, so that the time utilization rate of the UI thread can be improved, and the problems of blocking and frame skipping caused by long time for the UI thread to execute other time-consuming tasks can be avoided.
Alternatively, in fig. 7, since the commit _ callback consumes 0 or is infinitely close to 0, the end rendering listening callback function may be inserted after the traversal _ callback, or after the commit _ callback if there is a task to be executed in the commit _ callback in the following.
In an embodiment of the present disclosure, a flow of determining an idle time slice may also be as shown in fig. 8, where fig. 8 is a schematic flowchart of a flow of determining an idle time slice according to an embodiment of the present disclosure, and in fig. 8, determining an idle time slice may include the following steps:
s801: the Choroegraph object of the current frame is obtained.
Specifically, in the APP start phase, the chord graphics object of the current frame system may be acquired.
S802: it is determined whether a vertical synchronization signal VSYNC signal is monitored.
Specifically, if yes, the process proceeds to step S803, and if no, the process ends.
S803: and injecting a rendering and listening starting callback function into the Choreographer object, and determining the starting time of the rendering task through the rendering and listening starting callback function.
Specifically, before the rendering-and-listening callback function is injected, a rendering-and-listening callback function needs to be created, the rendering-and-listening callback function is injected into the chord graph object by the developer for the first time, that is, when the VSYNC signal is received for the first time, the rendering-and-listening callback function is injected into the chord graph object by the developer, and when the VSYNC signal is received subsequently, the rendering-and-listening callback function can be automatically injected into the chord graph object, so that the rendering task starting time of each frame is monitored, and the rendering task starting time of each frame is recorded.
S804: and injecting a rendering and listening ending callback function into the Choreographer object, and determining the ending time of the rendering task through the rendering and listening ending callback function.
Specifically, before injecting the rendering and listening callback function, the rendering and listening callback function to be completed needs to be created, the rendering and listening callback function to be completed is injected into the chord graph object by the developer for the first time, that is, the rendering and listening callback function to be completed is inserted into the foreground _ callback by the developer, and after the measurement, layout and drawing of the page view tree of each subsequent frame are completed, the rendering and listening callback function to be completed can be automatically inserted into the background _ callback, so that the rendering task to be monitored for each frame is completed, and the rendering task to be monitored for each frame is completed.
S805: the free time slice is determined by the start time and the end time.
Specifically, after the rendering task of each frame is monitored to be finished, the rendering time consumption of the rendering task can be determined through the difference between the finishing time and the starting time, and therefore the idle time slice is determined through the difference between the time length of each frame and the rendering time consumption.
According to the task processing method, fragment time management of the UI thread is achieved through three parts, and in the frame rate time consumption monitoring part, a monitoring callback function is injected through a HOOK system object Choroegraph to obtain the rendering starting time and the rendering ending time of the current frame, so that the time consumption condition of the rendering task of the current frame is determined. And generating an available idle time slice of the current frame in the idle time slice part, and then acquiring an executable task in the current idle time slice through the task scheduling part. The task scheduling part is mainly responsible for recording the execution time consumption situation of each task in a current central processing unit (CPU for short), and meanwhile, a task time consumption recording table is generated by reading the time consumption data of the historical task execution in the CPU during APP initialization, so that the task with more accurate idle time slice matching time is given, then the task is executed, and the situations of UI thread frame skipping and blocking are avoided.
Therefore, the technical scheme of the present disclosure can accurately monitor the rendering time of the rendering task of each frame, and can evaluate the performance of the online user more accurately; the problems of frame skipping and blocking of the UI thread can be avoided, and the utilization rate of fragment time of the UI thread can be improved; the automatic learning function can be realized on CPUs of different models, the execution time consumption of each task can be saved to the local after the first time of task execution time consumption is obtained, and the task can be automatically scheduled for execution when the task is used again subsequently, so that the problem of inaccurate task time consumption scheduling caused by model CPU difference is solved.
Exemplary Medium
Having described the method of the exemplary embodiment of the present disclosure, next, a storage medium of the exemplary embodiment of the present disclosure will be described with reference to fig. 9.
Referring to fig. 9, a storage medium 90 stores therein a program product for implementing the above method according to an embodiment of the present disclosure, which may employ a portable compact disc read only memory (CD-ROM) and include computer-executable instructions for causing a computing device to perform a task processing method provided by the present disclosure. However, the program product of the present disclosure is not limited thereto.
The program product of the present disclosure may employ 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 electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A readable signal medium may include a propagated data signal with computer-executable instructions embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. The readable signal medium may also be any readable medium other than a readable storage medium.
Computer-executable instructions for carrying out operations of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer executable instructions may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the 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 kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN).
Exemplary devices
After introducing the media of the exemplary embodiment of the present disclosure, next, a task processing device of the exemplary embodiment of the present disclosure is described with reference to fig. 10 for implementing the method in any of the method embodiments described above, which has similar implementation principles and technical effects, and is not described herein again.
Fig. 10 is a schematic configuration diagram of a task processing device according to an embodiment of the present disclosure, and as shown in fig. 10, the task processing device 1000 includes:
a determining module 1001, configured to determine an idle time slice of a current frame, where a start time of the idle time slice is a time when a user interface UI thread starts idling, and an end time of the idle time slice is an end time of the current frame;
an obtaining module 1002, configured to obtain a target task whose task processing duration is less than or equal to an idle time slice;
an executing module 1003, configured to execute the target task in the idle time slice.
Optionally, the obtaining module 1002 obtains the target task with the task processing duration less than or equal to the idle time slice by: the method comprises the steps that a task list is obtained, wherein the task list comprises at least one task queue, the task processing time length of a task to be processed contained in each task queue is the same, and the task processing time lengths of the tasks to be processed contained in different task queues are different; determining a first task queue in a task list, wherein the task processing time length corresponding to the first task queue is less than or equal to the idle time slice; a target task is determined in a first task queue.
Optionally, the obtaining module 1002 is further configured to construct at least one task queue in the task list by using a linked list structure before obtaining the task list; acquiring a task to be processed; and adding the acquired task to be processed to a second task queue in the task list to obtain the task list, wherein the task processing time length corresponding to the second task queue is the same as the task processing time length of the acquired task to be processed.
Optionally, the obtaining module 1002 adds the obtained task to be processed to the second task queue in the task list by: in response to the fact that the task processing duration of the obtained tasks to be processed is smaller than or equal to a preset value, adding the obtained tasks to be processed to a second task queue, wherein the number of the second task queue is one; in response to the fact that the task processing duration of the obtained task to be processed is larger than a preset value, splitting the obtained task to be processed to obtain a plurality of subtasks; and adding a plurality of subtasks to a second task queue according to the task processing duration of the subtasks, wherein the number of the second task queue is multiple.
Optionally, the task processing device further includes: the first processing module (not shown) is used for determining the historical task processing time of the acquired task to be processed within a preset time range; and determining the maximum value in the historical task processing time length as the acquired task processing time length of the task to be processed.
Optionally, the obtaining module 1002 is further configured to perform binding processing on the to-be-processed task and a life cycle of a page where the current frame is located before adding the obtained to-be-processed task to the second task queue in the task list.
Optionally, the task processing device further includes: an updating module (not shown) for determining and storing an execution duration of the target task in the idle time slice after the target task is executed in the idle time slice; and updating the idle time slice according to the execution duration.
Optionally, at least one task queue in the task list is arranged according to the sequence of the corresponding task processing duration from small to large; the task processing device further includes: a second processing module (not shown) for determining a first non-empty task queue in the task list as a third task queue in response to monitoring flag information indicating that the task schedule is overtime; and acquiring the first task in the third task queue for execution.
Optionally, the task processing device further includes: and a deleting module (not shown) for deleting the task whose execution is completed in the corresponding task queue after the task execution is completed.
Optionally, the determining module 1001 realizes determining the idle time slice of the current frame by: acquiring the starting time and the ending time of the rendering task of the current frame; determining the rendering duration of the rendering task according to the starting time and the ending time; and determining the difference value of the refreshing time length and the rendering time length of the current frame as an idle time slice, wherein the refreshing time length is determined by the refreshing frequency of a user interface, and the refreshing time length is greater than or equal to the rendering time length.
Optionally, the determining module 1001 obtains the rendering start time and the rendering end time of the current frame by: calling a first monitoring callback function of the current frame, and determining the rendering starting time, wherein the first monitoring callback function is used for monitoring the starting time of a rendering task; and calling a second monitoring callback function of the current frame to determine the rendering ending time, wherein the second monitoring callback function is used for monitoring the ending time of the rendering task.
Exemplary computing device
Having described the methods, media, and apparatus of the exemplary embodiments of the present disclosure, a computing device of the exemplary embodiments of the present disclosure is next described with reference to fig. 11.
The computing device 1100 shown in fig. 11 is only one example and should not impose any limitations on the functionality or scope of use of embodiments of the present disclosure.
Fig. 11 is a schematic structural diagram of a computing device according to an embodiment of the disclosure, and as shown in fig. 11, the computing device 1100 is embodied in the form of a general purpose computing device. Components of computing device 1100 may include, but are not limited to: at least one processing unit 1101, at least one storage unit 1102, and a bus 1103 that couples the various system components (including the processing unit 1101 and the storage unit 1102). Wherein computer execution instructions are stored in at least one storage unit 1102; the at least one processing unit 1101 includes a processor that executes the computer-executable instructions to implement the methods described above.
The bus 1103 includes a data bus, a control bus, and an address bus.
The storage unit 1102 may include readable media in the form of volatile memory, such as Random Access Memory (RAM) 1121 and/or cache memory 1122, and may further include readable media in the form of non-volatile memory, such as Read Only Memory (ROM) 1123.
It should be noted that although in the above detailed description several units/modules or sub-units/modules of the task processing means are mentioned, such a division is merely exemplary and not mandatory. Indeed, the features and functionality of two or more of the units/modules described above may be embodied in one unit/module, in accordance with embodiments of the present disclosure. Conversely, the features and functions of one unit/module described above may be further divided into embodiments by a plurality of units/modules.
Further, while the operations of the disclosed methods are depicted in the drawings in a particular order, this does not require or imply that these operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
While the spirit and principles of the present disclosure have been described with reference to several particular embodiments, it is to be understood that the present disclosure is not limited to the particular embodiments disclosed, nor is the division of aspects, which is for convenience only as the features in such aspects may not be combined to benefit. The disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.
Claims (10)
1. A method for processing a task, comprising:
determining an idle time slice of a current frame, wherein the starting time of the idle time slice is the time when a User Interface (UI) thread starts to idle, and the ending time of the idle time slice is the ending time of the current frame;
acquiring a target task of which the task processing duration is less than or equal to the idle time slice;
and executing the target task in the idle time slice.
2. The task processing method according to claim 1, wherein the obtaining of the target task whose task processing duration is less than or equal to the idle time slice comprises:
the method comprises the steps of obtaining a task list, wherein the task list comprises at least one task queue, the task processing time length of a task to be processed contained in each task queue is the same, and the task processing time lengths of the tasks to be processed contained in different task queues are different;
determining a first task queue in the task list, wherein the task processing duration corresponding to the first task queue is less than or equal to the idle time slice;
determining the target task in the first task queue.
3. The task processing method according to claim 2, wherein before the obtaining the task list, the method further comprises:
constructing at least one task queue in a task list by adopting a linked list structure;
acquiring a task to be processed;
and adding the acquired task to be processed to a second task queue in the task list to obtain the task list, wherein the task processing time length corresponding to the second task queue is the same as the task processing time length of the acquired task to be processed.
4. The task processing method according to claim 3, wherein the adding the acquired to-be-processed task to a second task queue in the task list includes:
in response to that the task processing duration of the acquired task to be processed is smaller than or equal to a preset value, adding the acquired task to be processed to the second task queue, wherein the number of the second task queue is one;
in response to the fact that the task processing duration of the obtained task to be processed is larger than the preset value, splitting the obtained task to be processed to obtain a plurality of subtasks; and adding the plurality of subtasks to the second task queue according to the task processing duration of the subtasks, wherein the number of the second task queue is multiple.
5. The task processing method according to claim 4, further comprising:
determining the historical task processing duration of the acquired task to be processed within a preset time range;
and determining the maximum value in the historical task processing time length as the acquired task processing time length of the task to be processed.
6. The task processing method according to any one of claims 2 to 5, wherein at least one task queue in the task list is arranged in order of the corresponding task processing duration from small to large; the task processing method further comprises the following steps:
in response to monitoring flag information for indicating task scheduling timeout, determining a first non-empty task queue in the task list as a third task queue;
and acquiring a first task in the third task queue for execution.
7. The task processing method according to any one of claims 1 to 5, wherein the determining the idle time slice of the current frame comprises:
acquiring the starting time and the ending time of the rendering task of the current frame;
determining the rendering duration of the rendering task according to the starting time and the ending time;
and determining the difference value between the refreshing time length of the current frame and the rendering time length as the idle time slice, wherein the refreshing time length is determined by the refreshing frequency of a user interface, and the refreshing time length is greater than or equal to the rendering time length.
8. A medium having stored therein computer-executable instructions for implementing a method of task processing as claimed in any one of claims 1 to 7 when executed by a processor.
9. A task processing apparatus, comprising:
the determining module is used for determining an idle time slice of a current frame, wherein the starting time of the idle time slice is the time when a User Interface (UI) thread starts to idle, and the ending time of the idle time slice is the ending time of the current frame;
the acquisition module is used for acquiring a target task of which the task processing duration is less than or equal to the idle time slice;
and the execution module is used for executing the target task in the idle time slice.
10. A computing device, comprising: a processor, and a memory coupled to the processor;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored by the memory to implement the method of task processing according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310014439.9A CN115981822A (en) | 2023-01-05 | 2023-01-05 | Task processing method, medium, device and computing equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310014439.9A CN115981822A (en) | 2023-01-05 | 2023-01-05 | Task processing method, medium, device and computing equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115981822A true CN115981822A (en) | 2023-04-18 |
Family
ID=85966557
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310014439.9A Pending CN115981822A (en) | 2023-01-05 | 2023-01-05 | Task processing method, medium, device and computing equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115981822A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117097883A (en) * | 2023-10-20 | 2023-11-21 | 荣耀终端有限公司 | Frame loss fault cause determining method, electronic equipment and storage medium |
-
2023
- 2023-01-05 CN CN202310014439.9A patent/CN115981822A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117097883A (en) * | 2023-10-20 | 2023-11-21 | 荣耀终端有限公司 | Frame loss fault cause determining method, electronic equipment and storage medium |
CN117097883B (en) * | 2023-10-20 | 2024-04-12 | 荣耀终端有限公司 | Frame loss fault cause determining method, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20220083395A1 (en) | Scheduling system for computational work on heterogeneous hardware | |
US8769548B2 (en) | Media player instance managed resource reduction | |
US10871985B2 (en) | Displaying media files between changes in states of an application client | |
CN107766128B (en) | Method and device for starting application | |
KR102490908B1 (en) | Resource scheduling method and terminal device | |
US20100211933A1 (en) | Debugging and perfomance analysis of applications | |
US20210256427A1 (en) | Automated Computer Operating System Optimization | |
EP2581829B1 (en) | Dynamic scheduling for frames representing views of a geographic information environment | |
CN110990132B (en) | Asynchronous task processing method and device, computer equipment and storage medium | |
CN115981822A (en) | Task processing method, medium, device and computing equipment | |
CN110908866A (en) | Software monitoring method and related equipment | |
CN111880879A (en) | Playing method, device, equipment and storage medium of dynamic wallpaper | |
CN112464120A (en) | Data visualization display method and device, electronic equipment and storage medium | |
CN113407138B (en) | Application program picture processing method and device, electronic equipment and storage medium | |
US20230116940A1 (en) | Multimedia resource processing | |
CN109491771B (en) | Task processing method based on system performance optimization and related equipment | |
CN113391896B (en) | Task processing method and device, storage medium and electronic equipment | |
CN116737472A (en) | Method and device for testing memory time sequence training process | |
CN114327900B (en) | Method for preventing memory leakage by managing thread call in double-buffer technology | |
CN115934291A (en) | Task execution method and device, electronic equipment and storage medium | |
CN114202608A (en) | Method, apparatus, device, medium, and program product for image rendering | |
CN113821205A (en) | Method and device for controlling small program page parameters, medium and electronic equipment | |
CN111190725A (en) | Task processing method and device, storage medium and server | |
CN108269104B (en) | Media information delivery method, delivery engine server and media information delivery system | |
CN113626244B (en) | ANR abnormal data collection method, display method, device and equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |