Skip to content

Commit 1a865ab

Browse files
authored
fix(🐛): fix substancial performance regression on RN Web (#3577)
1 parent 4106e96 commit 1a865ab

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

packages/skia/src/sksg/Recorder/Player.ts

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,50 @@ const getZIndex = (command: GroupCommand) => {
6868
return zIndex;
6969
};
7070

71-
const play = (ctx: DrawingContext, _command: Command) => {
72-
const flushPendingGroups = (
73-
// eslint-disable-next-line @typescript-eslint/no-shadow
74-
ctx: DrawingContext,
75-
pendingGroups: PendingGroup[]
76-
) => {
77-
"worklet";
78-
if (pendingGroups.length === 0) {
71+
const flushPendingGroups = (
72+
ctx: DrawingContext,
73+
pendingGroups: PendingGroup[],
74+
playFn: (ctx: DrawingContext, cmd: Command) => void
75+
) => {
76+
"worklet";
77+
if (pendingGroups.length === 0) {
78+
return;
79+
}
80+
pendingGroups
81+
.sort((a, b) =>
82+
a.zIndex === b.zIndex ? a.order - b.order : a.zIndex - b.zIndex
83+
)
84+
.forEach(({ command }) => {
85+
playFn(ctx, command);
86+
});
87+
pendingGroups.length = 0;
88+
};
89+
90+
const playGroup = (
91+
ctx: DrawingContext,
92+
group: GroupCommand,
93+
playFn: (ctx: DrawingContext, cmd: Command) => void
94+
) => {
95+
"worklet";
96+
const pending: PendingGroup[] = [];
97+
group.children.forEach((child) => {
98+
if (isGroup(child)) {
99+
pending.push({
100+
command: child,
101+
zIndex: getZIndex(child),
102+
order: pending.length,
103+
});
79104
return;
80105
}
81-
pendingGroups
82-
.sort((a, b) =>
83-
a.zIndex === b.zIndex ? a.order - b.order : a.zIndex - b.zIndex
84-
)
85-
.forEach(({ command }) => {
86-
play(ctx, command);
87-
});
88-
pendingGroups.length = 0;
89-
};
90-
// eslint-disable-next-line @typescript-eslint/no-shadow
91-
const playGroup = (ctx: DrawingContext, group: GroupCommand) => {
92-
"worklet";
93-
const pending: PendingGroup[] = [];
94-
group.children.forEach((child) => {
95-
if (isGroup(child)) {
96-
pending.push({
97-
command: child,
98-
zIndex: getZIndex(child),
99-
order: pending.length,
100-
});
101-
return;
102-
}
103-
flushPendingGroups(ctx, pending);
104-
play(ctx, child);
105-
});
106-
flushPendingGroups(ctx, pending);
107-
};
106+
flushPendingGroups(ctx, pending, playFn);
107+
playFn(ctx, child);
108+
});
109+
flushPendingGroups(ctx, pending, playFn);
110+
};
108111

112+
const play = (ctx: DrawingContext, _command: Command) => {
109113
if (isGroup(_command)) {
110-
playGroup(ctx, _command);
114+
playGroup(ctx, _command, play);
111115
return;
112116
}
113117
const command = materializeCommand(_command);

0 commit comments

Comments
 (0)