Skip to content

perf: optimize element event distribution and attribute update process - #1944

Merged
wang1212 merged 5 commits into
releasefrom
perf/event
Jun 26, 2025
Merged

perf: optimize element event distribution and attribute update process#1944
wang1212 merged 5 commits into
releasefrom
perf/event

Conversation

@wang1212

@wang1212 wang1212 commented May 28, 2025

Copy link
Copy Markdown
Member

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / Document optimization
  • TypeScript definition update
  • Refactoring
  • Performance improvement
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

#1712

💡 Background and solution

To ensure that the retained business is not affected, enable performance optimization changes by configuring flags.

interface CanvasConfig {
  /**
   * Enabling some features for the future.
   *
   * ! These are some experimental functional features that are currently unstable.
   *
   * future flag, concept referenced from:
   * - https://remix.run/docs/en/main/guides/api-development-strategy#unstable-apis-and-future-flags,
   * - https://remix.run/blog/future-flags
   */
  future?: {
    /**
     * Only implement bubbling propagation for necessary events.
     * At the same time, some events will skip the process of building event objects and
     * directly trigger events themselves.
     */
    experimentalCancelEventPropagation?: boolean;
    /**
     * When enabled, elements are no longer updated in real time, but are updated uniformly before being submitted to the canvas. This is to improve performance and avoid redundant loop logic.
     */
    experimentalAttributeUpdateOptimization?: boolean;
    /**
     * use RIC to avoid frequent calls syncRTree
     */
    experimentalRICSyncRTree?: boolean;
  };
}

// Usage

import { Canvas } from '@antv/g';

const canvas = new Canvas({
    future: {}
});

// or

canvas.getConfig().future = {};

Performance benchmark:

  • experimentalCancelEventPropagation = true / experimentalRICSyncRTree = true

1000 Rect element objects, created and destroyed.

image

Dynamic tick rendering with 5%~10% FPS increase.

📝 Changelog

Language Changelog
🇺🇸 English perf: optimize element event distribution and attribute update process
🇨🇳 Chinese perf: 优化元素事件分发和属性更新流程

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Base automatically changed from release to master May 30, 2025 02:52
Comment thread __tests__/demos/perf/destroy-event.ts Fixed
wang1212 and others added 3 commits June 24, 2025 21:21
* perf: optimize element event distribution and attribute update process

* perf: 增加enableRICSyncRTree

---------

Co-authored-by: wang1212 <mrwang1212@126.com>
wang1212 added 2 commits June 25, 2025 11:25
- Move performance-related configurations from runtime to canvas config
- Introduce experimental feature flags in CanvasConfig for better control
- Optimize event propagation and attribute updates
- Add RIC (RequestIdleCallback) for syncRTree operations
- Improve type safety and code organization
@wang1212
wang1212 changed the base branch from master to release June 26, 2025 07:07
@wang1212
wang1212 marked this pull request as ready for review June 26, 2025 07:08
@wang1212
wang1212 requested a review from Alexzjt June 26, 2025 07:09
Comment thread packages/g-plugin-device-renderer/src/RenderGraphPlugin.ts
Comment thread packages/g-plugin-box2d/src/Box2DPlugin.ts

@Alexzjt Alexzjt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK

@wang1212
wang1212 merged commit 7a9196c into release Jun 26, 2025
4 checks passed
@wang1212
wang1212 deleted the perf/event branch June 26, 2025 11:14
wang1212 added a commit that referenced this pull request Jun 27, 2025
* fix: 🐛 Fix invalid URL links (#1951)

* fix: terminate immediately when the line width is too small to display any characters (#1956)

* docs: update documentation and examples

* fix(svg-renderer): add x and y attributes to foreignObject in SVGRenderer (#1961)

Add support for x and y attributes in foreignObject elements to ensure proper positioning in SVG rendering.

* docs: update documentation formatting and update dependencies

* perf: optimize element event distribution and attribute update process (#1944)

* fix(plugin-box2d): remove trailing slash from BOX2D_UMD_DIR

* perf: optimize element event distribution and attribute update process

* feat: use RIC to avoid frequent calls syncRTree (#1960)

* perf: optimize element event distribution and attribute update process

* perf: 增加enableRICSyncRTree

---------

Co-authored-by: wang1212 <mrwang1212@126.com>

* chore: fix lint error

* refactor: enhance performance optimization with experimental features

- Move performance-related configurations from runtime to canvas config
- Introduce experimental feature flags in CanvasConfig for better control
- Optimize event propagation and attribute updates
- Add RIC (RequestIdleCallback) for syncRTree operations
- Improve type safety and code organization

---------

Co-authored-by: huiyu.zjt <Alexzjt@users.noreply.github.com>

* chore: add changeset

* chore(release): bump version (#1958)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: iaosee <iaosee@outlook.com>
Co-authored-by: huiyu.zjt <Alexzjt@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants