Skip to content

perf: 复用行列头/数值单元格 以提升百万滚动性能至50FPS#3222

Merged
Alexzjt merged 52 commits intonextfrom
perf/100w_header
Dec 25, 2025
Merged

perf: 复用行列头/数值单元格 以提升百万滚动性能至50FPS#3222
Alexzjt merged 52 commits intonextfrom
perf/100w_header

Conversation

@Alexzjt
Copy link
Contributor

@Alexzjt Alexzjt commented Sep 9, 2025

👀 PR includes

✨ Feature

  • New feature

🎨 Enhance

  • Code style optimization
  • Refactoring
  • Change the UI
  • Improve the performance
  • Type optimization

🐛 Bugfix

  • Solve the issue and close #0

🔧 Chore

  • Test case
  • Docs / demos update
  • CI / workflow
  • Release version
  • Other ()

📝 Description

在S2百万数据交叉表滚动场景下(1649个元素),S2花费了巨量的时间在创建、计算和渲染单元格上,伴随着大量单元格、line、rect、text等Destroy与new。
大量的对象在短时间内被创建然后又被废弃,会导致频繁的垃圾回收和较高的性能开销。
所以有必要采取复用已有DisplayObject这样性能友好的写法来提高性能。

依赖 antvis/G#2001

🖼️ Screenshot

Before After

🔗 Related issue link

🔍 Self-Check before the merge

  • Add or update relevant docs.
  • Add or update relevant demos.
  • Add or update test case.
  • Add or update relevant TypeScript definitions.

Alexzjt and others added 30 commits March 25, 2025 15:47
# Conflicts:
#	packages/s2-core/src/facet/base-facet.ts
…header

# Conflicts:
#	packages/s2-core/src/cell/header-cell.ts
# Conflicts:
#	packages/s2-core/package.json
#	packages/s2-core/src/sheet-type/spread-sheet.ts
#	pnpm-lock.yaml
…header

# Conflicts:
#	packages/s2-core/src/cell/DataCellPool.ts
#	packages/s2-core/src/cell/header-cell.ts
#	packages/s2-core/src/facet/base-facet.ts
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @Alexzjt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求的核心目标是大幅提升表格在百万数据量滚动时的渲染性能,旨在达到 50FPS 的流畅度。这主要通过实现全面的图形对象复用和引入单元格对象池机制来达成,从而减少了不必要的对象创建和销毁,优化了渲染循环。

Highlights

  • 核心性能优化:图形对象复用: 通过引入 batchSetStylecreateOrUpdateRect 等工具函数,实现了单元格(数据单元格、行列头单元格)、边框、背景、文本、链接、条件图标以及网格线等图形元素的复用渲染。这意味着在滚动或更新时,不再频繁创建和销毁图形对象,而是更新现有对象的属性,显著减少了垃圾回收的压力和渲染开销。
  • 单元格对象池机制: 新增了 BaseCellPool 及其子类(ColCellPoolDataCellPoolRowCellPool),为行列头和数据单元格提供了高效的复用和回收机制。当单元格不再可见时,会被放入对象池等待下次复用,进一步提升了大数据量下的滚动性能。
  • 实验性功能开关: 在 s2Options 中引入了 future.experimentalReuseDataCell 实验性功能开关,允许开发者选择性地启用数据单元格的复用特性,便于测试和逐步推广。
  • 渲染引擎配置增强: 现在可以通过 s2Options.rendererConfig 配置 AntV/G 渲染引擎的参数,提供了更灵活的底层渲染控制能力。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

This comment was marked as duplicate.

@github-actions github-actions bot added 🚨 test failed 单元测试挂了 🚨 lint failed 静态检查失败 labels Sep 9, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

本次 PR 旨在通过复用单元格来提升滚动性能,这是一个非常棒的优化方向。代码的改动范围较广,涉及了单元格基类、各种头单元格、数据单元格以及 Facet 和 Header 的实现,核心思路是在已有图形和单元格对象上更新属性,而不是频繁销毁和创建,这能有效减少 GC压力并提升渲染速度。

代码整体实现得很好,特别是引入了单元格对象池(Cell Pool)和一系列工具函数来支持复用逻辑。

我发现了一些可以进一步优化的地方,主要集中在对象池的实现上,希望能帮助你让这次性能优化更加彻底。具体请看我的详细评论。

@Alexzjt
Copy link
Contributor Author

Alexzjt commented Sep 9, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这个 PR 通过引入对象池和复用图形元素(单元格、形状、图标等)来显著提升滚动性能,这是一个非常棒的性能优化。核心改动包括:

  1. 为行头、列头和数据单元格实现了对象池,以减少频繁的对象创建和销毁。
  2. 在单元格渲染逻辑中,对背景、边框、文本、图标等图形元素进行了复用,而不是每次都重新创建。
  3. 引入了 batchSetStyle 工具函数,利用 G 的 setAttributes 批量更新样式,减少不必要的重绘事件,进一步提升性能。
  4. GuiIcon 添加了 reRenderupdatePosition 方法,支持更高效的图标更新。
  5. 通过 future 配置项引入了实验性功能开关 experimentalReuseDataCell,这是一个很好的实践,可以安全地引入重大变更。

整体代码改动清晰地遵循了“复用代替创建”的原则,对提升大数据量下的滚动流畅度有很大帮助。代码质量很高,但有几个可以改进的地方,主要关于类型安全。

# Conflicts:
#	packages/s2-core/src/cell/col-cell.ts
#	packages/s2-core/src/cell/row-cell.ts
#	packages/s2-core/src/facet/header/base.ts
#	packages/s2-core/src/group/grid-group.ts
#	packages/s2-react/playground/components/BigDataSheet.tsx
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2025

Codecov Report

❌ Patch coverage is 67.85714% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.14%. Comparing base (ecdc9c8) to head (edd001a).
⚠️ Report is 736 commits behind head on next.

Files with missing lines Patch % Lines
packages/s2-core/src/cell/pool/col-cell.ts 29.41% 9 Missing and 3 partials ⚠️
packages/s2-core/src/cell/pool/row-cell.ts 29.41% 9 Missing and 3 partials ⚠️
packages/s2-core/src/cell/header-cell.ts 57.14% 3 Missing and 3 partials ⚠️
packages/s2-core/src/cell/base-cell.ts 83.33% 2 Missing and 2 partials ⚠️
packages/s2-core/src/cell/col-cell.ts 77.77% 2 Missing ⚠️
packages/s2-core/src/facet/base-facet.ts 84.61% 0 Missing and 2 partials ⚠️
packages/s2-core/src/facet/header/row.ts 75.00% 0 Missing and 2 partials ⚠️
packages/s2-core/src/utils/g-mini-charts.ts 33.33% 1 Missing and 1 partial ⚠️
...re/src/extends/pivot-chart/cell/chart-data-cell.ts 0.00% 1 Missing ⚠️
packages/s2-core/src/facet/header/col.ts 93.33% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3222      +/-   ##
==========================================
+ Coverage   75.77%   79.14%   +3.37%     
==========================================
  Files         257      222      -35     
  Lines       11994    12183     +189     
  Branches     2464     2736     +272     
==========================================
+ Hits         9088     9642     +554     
+ Misses       1398      887     -511     
- Partials     1508     1654     +146     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot removed 🚨 test failed 单元测试挂了 🚨 lint failed 静态检查失败 labels Dec 15, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 15, 2025

Size Change: +91.5 kB (+14.57%) ⚠️

Total Size: 719 kB

Filename Size Change
./packages/s2-core/dist/s2-extends.min.js 207 kB +48.6 kB (+30.74%) 🚨
./packages/s2-core/dist/s2.min.css 583 B +2 B (+0.34%)
./packages/s2-core/dist/s2.min.js 306 kB +42.9 kB (+16.34%) ⚠️
ℹ️ View Unchanged
Filename Size
./packages/s2-react-components/dist/s2-react-components.min.css 2.55 kB
./packages/s2-react-components/dist/s2-react-components.min.js 124 kB
./packages/s2-react/dist/s2-react.min.css 1.3 kB
./packages/s2-react/dist/s2-react.min.js 38.5 kB
./packages/s2-vue/dist/s2-vue.min.css 1.59 kB
./packages/s2-vue/dist/s2-vue.min.js 38.3 kB

compressed-size-action

@github-actions github-actions bot added the 🚨 lint failed 静态检查失败 label Dec 25, 2025
@github-actions github-actions bot removed the 🚨 lint failed 静态检查失败 label Dec 25, 2025
@Alexzjt Alexzjt merged commit 3bc1ccb into next Dec 25, 2025
9 checks passed
@Alexzjt Alexzjt deleted the perf/100w_header branch December 25, 2025 07:15
@lijinke666
Copy link
Member

🎉 This PR is included in version @antv/s2-v2.4.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lijinke666
Copy link
Member

🎉 This PR is included in version @antv/s2-react-v2.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next 2.0-next 版本的问题 released on @latest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants