Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: optimize performance when disable animation #6651

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/g6/src/runtime/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,23 +432,25 @@ export class ElementController {
new Ctor({
id,
context: this.context,
style: {
...style,
},
style,
}),
) as Element;

this.shapeTypeMap[id] = type;
this.elementMap[id] = element;

const { stage = 'enter' } = context;
const { stage = 'enter', animation } = context;

const enableAnimation = animation && this.context.options.animation;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The introduction of enableAnimation is a good optimization to prevent unnecessary deep copying of styles when animation is disabled. This change should help in reducing memory usage and improving performance.


this.context.animation?.add(
{
element,
elementType,
stage,
originalStyle: { ...element.attributes },
// <zh/> 当关闭动画时,不需要深拷贝样式
// <en/> When the animation is turned off, there is no need to deep copy the style
originalStyle: enableAnimation ? { ...element.attributes } : element.attributes,
updatedStyle: style,
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/src/spec/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* <en/> Theme Options
* @public
*/
export type ThemeOptions = 'light' | 'dark' | string;
export type ThemeOptions = false | 'light' | 'dark' | string;
2 changes: 1 addition & 1 deletion packages/g6/src/utils/animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ export function getElementAnimationOptions(
localAnimation?: AnimationEffectTiming | boolean,
): STDAnimation {
const { animation: globalAnimation } = options;
if (globalAnimation === false || localAnimation === false) return [];

const userElementAnimation = options?.[elementType]?.animation;
if (userElementAnimation === false) return [];
const useElementStageAnimation = userElementAnimation?.[stage];
if (useElementStageAnimation === false) return [];
if (globalAnimation === false || localAnimation === false) return [];

// 优先级:用户局部动画配置 > 用户动画配置 > 全局动画配置 > 主题动画配置 > 默认动画配置
// Priority: user local animation configuration > user animation configuration > global animation configuration > theme animation configuration > default animation configuration
Expand Down
Loading