Skip to content

perf: reduce repeated lookups in select, child ordering, and tree selection - #2031

Draft
aioya wants to merge 5 commits into
varletjs:devfrom
aioya:codex/algorithm-hotspots
Draft

aioya wants to merge 5 commits into
varletjs:devfrom
aioya:codex/algorithm-hotspots

Conversation

@aioya

@aioya aioya commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Checklist

  • Lint and formatting pass
  • Regression tests added for deep tree selection and reactive object values

Change information

Optimize three collection hot paths in priority order, each in a separate implementation commit:

  1. Select/MenuSelect multiple-selection sync builds a Set once per sync. Both the model array and option keys use Vue toRaw, preserving object-value selection with reactive arrays. A regression test covers initial selection and external model updates.
  2. useChildren indexes VNodes once before sorting child instances. First-match and missing-node behavior is retained.
  3. DataTable caches subtree selection checks within one toggle while updating ancestors. A deep-tree regression test covers the resulting selection behavior.

169 tests passed across Select, MenuSelect, Option, Tabs, Collapse, and DataTable. The varlet-use TypeScript check, lint, and formatting passed. Quantitative before/after results are in the PR discussion.

Issues

No issue is being closed. Keeping this PR in draft for maintainer discussion of the performance evidence and implementation trade-offs.

@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@aioya is attempting to deploy a commit to the varletjs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@varlet/cli

npm i https://pkg.pr.new/@varlet/cli@2031

@varlet/icons

npm i https://pkg.pr.new/@varlet/icons@2031

@varlet/import-resolver

npm i https://pkg.pr.new/@varlet/import-resolver@2031

@varlet/preset-tailwindcss

npm i https://pkg.pr.new/@varlet/preset-tailwindcss@2031

@varlet/preset-unocss

npm i https://pkg.pr.new/@varlet/preset-unocss@2031

@varlet/shared

npm i https://pkg.pr.new/@varlet/shared@2031

@varlet/touch-emulator

npm i https://pkg.pr.new/@varlet/touch-emulator@2031

@varlet/ui

npm i https://pkg.pr.new/@varlet/ui@2031

@varlet/use

npm i https://pkg.pr.new/@varlet/use@2031

@varlet/vite-plugins

npm i https://pkg.pr.new/@varlet/vite-plugins@2031

commit: 8f2fedc

@aioya
aioya force-pushed the codex/algorithm-hotspots branch from bb5cf64 to 8f2fedc Compare October 23, 2026 03:39
@aioya

aioya commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

量化对比(隔离算法微基准):在同一台 arm64 macOS 15.8.1、Node v24.21.0 环境中,对改动前后的核心循环使用相同输入;每组先预热,再取 11 次样本的每操作耗时中位数。表中数值是 3 次独立进程运行的中位数,越低越好。每组比较均先检查输出一致。

场景 改动前 改动后 加速
Select:1,000 个对象值选项,Vue reactive 数组中有 500 个已选值 0.169 ms/次 0.035 ms/次 约 4.8×
useChildren:500 个子组件和 500 个 VNode,逆序排序 0.082 ms/次 0.038 ms/次 约 2.1×
DataTable:选择 500 层树的叶子并向上更新所有祖先 1.491 ms/次 0.053 ms/次 约 28×

三次运行的原始结果(改动前 → 改动后,单位 ms/次):

  • Select:0.172 → 0.035;0.167 → 0.034;0.169 → 0.035。
  • useChildren:0.082 → 0.039;0.082 → 0.038;0.079 → 0.038。
  • DataTable:1.538 → 0.053;1.491 → 0.050;1.491 → 0.053。

这是核心算法的合成负载,未计入 Vue 渲染、DOM 和浏览器布局,不能直接换算成用户实际感受到的整组件提速。500 层树特意放大了重复遍历;普通浅树的收益会更小。基准脚本未提交到 PR 分支。

This branch has not been deployed

No deployments
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