Skip to content

perf(datagrid): cache column index lookup in selection drawing#1742

Open
desperadoxhy wants to merge 1 commit into
TableProApp:mainfrom
desperadoxhy:perf/datagrid-selection-column-cache
Open

perf(datagrid): cache column index lookup in selection drawing#1742
desperadoxhy wants to merge 1 commit into
TableProApp:mainfrom
desperadoxhy:perf/datagrid-selection-column-cache

Conversation

@desperadoxhy

Copy link
Copy Markdown
Contributor

问题

GridSelectionOverlay.frame 与 DataGridRowView.drawCellSelectionFill 每次 draw 对每个选中列调 DataGridView.tableColumnIndex(内部 tableView.column(withIdentifier:) 线性扫 tableColumns)。拖选 N 列 × 每行 × 多次 draw = O(N²),列多 + 选区大时滚动卡。

方案

在 TableViewCoordinator 缓存 columnIndexByDataIndex: [Int: Int],draw 时直接读。失效点:列增删/重排/隐藏(reconcile 后)、用户拖列(tableViewColumnDidMove)、schema 变化、teardown。列宽不影响 index,不在 resize 时失效。

验证

  • BUILD SUCCEEDED
  • ColumnIndexCacheTests 5 个:解析正确、重复调用稳定、列重排后失效反映新顺序、schema 变化失效、越界返回 nil
  • 既有 CellSelectionTests + DataGridSelectionTests 全过

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, you need to sign our Contributor License Agreement.

To sign, please comment below with:

I have read the CLA Document and I hereby sign the CLA.


I have read the CLA Document and I hereby sign the CLA.


xuhengyu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@desperadoxhy

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA.

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.

1 participant