From c88da92893d996703041c7ae51f3d9ec205d8db8 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 1 Aug 2024 15:58:42 +0900 Subject: [PATCH] Optimize VectorAnimationThread task control Since we don't need to find & iterate whole tasks for mWorkingTasks and mCompletedTasks, let we use more faster container, instead of linear. Change-Id: I34dc1d884b4853c681e55f89dd0ddd79ecce5b5c Signed-off-by: Eunki, Hong --- .../vector-animation-thread.cpp | 16 +++++++++------- .../vector-animation-thread.h | 7 +++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp index a4992d9f55..a15e423e55 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.cpp @@ -253,10 +253,10 @@ void VectorAnimationThread::MoveTasksToCompleted(VectorAnimationTaskPtr task, bo }); bool needRasterize = false; - auto workingTask = std::find(mWorkingTasks.begin(), mWorkingTasks.end(), task); - if(workingTask != mWorkingTasks.end()) + VectorAnimationTaskSet::const_iterator workingIter = mWorkingTasks.find(task); + if(workingIter != mWorkingTasks.cend()) { - mWorkingTasks.erase(workingTask); + mWorkingTasks.erase(workingIter); } // Check pending task @@ -270,9 +270,10 @@ void VectorAnimationThread::MoveTasksToCompleted(VectorAnimationTaskPtr task, bo if(keepAnimation) { - if(mCompletedTasks.end() == std::find(mCompletedTasks.begin(), mCompletedTasks.end(), task)) + VectorAnimationTaskSet::const_iterator completedIter = mCompletedTasks.lower_bound(task); + if(completedIter == mCompletedTasks.cend() || task < *completedIter) { - mCompletedTasks.push_back(task); + mCompletedTasks.insert(completedIter, task); needRasterize = true; } } @@ -353,12 +354,13 @@ void VectorAnimationThread::Rasterize() if(nextFrameTime <= currentTime) { // If the task is not in the working list - if(std::find(mWorkingTasks.begin(), mWorkingTasks.end(), nextTask) == mWorkingTasks.end()) + VectorAnimationTaskSet::const_iterator workingIter = mWorkingTasks.lower_bound(nextTask); + if(workingIter == mWorkingTasks.cend() || nextTask < *workingIter) { it = mAnimationTasks.erase(it); // Add it to the working list - mWorkingTasks.push_back(nextTask); + mWorkingTasks.insert(workingIter, nextTask); mAsyncTaskManager.AddTask(nextTask); } else diff --git a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h index ac5053b70d..c3a0910c84 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/vector-animation-thread.h @@ -18,6 +18,7 @@ */ // EXTERNAL INCLUDES +#include #include #include #include @@ -180,8 +181,10 @@ private: private: std::vector mAnimationTasks; ///< Animation processing tasks, ordered by next frame time. - std::vector mCompletedTasks; ///< Temperal storage for completed tasks. - std::vector mWorkingTasks; + + using VectorAnimationTaskSet = std::set; + VectorAnimationTaskSet mCompletedTasks; ///< Temperal storage for completed tasks. + VectorAnimationTaskSet mWorkingTasks; ///< Tasks which are currently being processed. Key is the task, value is the number of tasks running. std::vector> mCompletedTasksQueue; ///< Queue of completed tasks from worker thread. pair of task, and rasterize required. ///< It will be moved at begin of Rasterize(). -- 2.34.1