From 7aac339178429f38b87c2361a9c661aa5e82c4c8 Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Tue, 3 Jun 2025 10:54:25 +0800 Subject: [PATCH 1/2] fix: clone diffAttrs to avoid recall same animate --- packages/vrender-animate/src/custom/update.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vrender-animate/src/custom/update.ts b/packages/vrender-animate/src/custom/update.ts index 6131bfe02..2e38de631 100644 --- a/packages/vrender-animate/src/custom/update.ts +++ b/packages/vrender-animate/src/custom/update.ts @@ -27,8 +27,8 @@ export class Update extends ACustomAnimate> { let { diffAttrs = {} } = this.target.context ?? ({} as any); const { options } = this.params as any; + diffAttrs = { ...diffAttrs }; if (options?.excludeChannels?.length) { - diffAttrs = { ...diffAttrs }; options.excludeChannels.forEach((channel: string) => { delete diffAttrs[channel]; }); From 07eabe332a779dea499ebb28e467b21a7eeacc0a Mon Sep 17 00:00:00 2001 From: zhouxinyu Date: Tue, 3 Jun 2025 11:08:33 +0800 Subject: [PATCH 2/2] fix: fix issue with performance raf idx repeat --- .../src/common/performance-raf.ts | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/vrender-core/src/common/performance-raf.ts b/packages/vrender-core/src/common/performance-raf.ts index 9d0398f1e..d9d2bae09 100644 --- a/packages/vrender-core/src/common/performance-raf.ts +++ b/packages/vrender-core/src/common/performance-raf.ts @@ -1,17 +1,19 @@ import { application } from '../application'; +let idx = 0; + /** * 性能优化,将requestAnimationFrame的回调函数存储起来,在下一帧执行 */ export class PerformanceRAF { - nextAnimationFrameCbs: FrameRequestCallback[] = []; + nextAnimationFrameCbs: Map = new Map(); private _rafHandle: number | null = null; addAnimationFrameCb(callback: FrameRequestCallback) { - this.nextAnimationFrameCbs.push(callback); + this.nextAnimationFrameCbs.set(++idx, callback); // 下一帧执行nextAnimationFrameCbs this.tryRunAnimationFrameNextFrame(); - return this.nextAnimationFrameCbs.length; + return idx; } /** @@ -20,9 +22,8 @@ export class PerformanceRAF { * @returns 是否移除成功 */ removeAnimationFrameCb(index: number): boolean { - if (index > 0 && index <= this.nextAnimationFrameCbs.length) { - // Set to null instead of empty function to avoid linter error - this.nextAnimationFrameCbs[index - 1] = null; + if (this.nextAnimationFrameCbs.has(index)) { + this.nextAnimationFrameCbs.delete(index); return true; } return false; @@ -31,16 +32,12 @@ export class PerformanceRAF { protected runAnimationFrame = (time: number) => { this._rafHandle = null; const cbs = this.nextAnimationFrameCbs; - this.nextAnimationFrameCbs = []; - for (let i = 0; i < cbs.length; i++) { - if (cbs[i]) { - cbs[i](time); - } - } + this.nextAnimationFrameCbs = new Map(); + cbs.forEach(cb => cb(time)); }; protected tryRunAnimationFrameNextFrame = () => { - if (this._rafHandle !== null || this.nextAnimationFrameCbs.length === 0) { + if (this._rafHandle !== null || this.nextAnimationFrameCbs.size === 0) { return; } this._rafHandle = application.global.getRequestAnimationFrame()(this.runAnimationFrame);