Skip to content

Compare column.frozen against false first - #4273

Merged
nstepien merged 1 commit into
mainfrom
frozen-check-order
Nov 1, 2026
Merged

nstepien merged 1 commit into
mainfrom
frozen-check-order

Conversation

@nstepien

@nstepien nstepien commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Most columns aren't frozen, and start-frozen columns are more common than end-frozen ones, so every check of column.frozen now compares against false first, then against 'start'.

Changes

  • getCellStyle, getCellClassname, getColSpan, collectColumns, and the column sort check false first, then 'start'.
  • useViewportColumns and the drag handle compare against false instead of checking truthiness.
  • AGENTS.md lists the rule under its conventions.

The normalization of rawColumn.frozen in useCalculatedColumns stays as it is, since undefined is the most common value there.

Rendered markup doesn't change: renderToString output is byte-identical for grids with unfrozen, start-frozen, and end-frozen columns, with and without colSpan.

Performance

The functions are faster, but whole renders don't change measurably. The change saves about 3 ns per cell, or 1.5 µs for an update of 600 cells, and all the code it touches is 0.2–0.5% of the CPU time of a mount or a scroll.

Measured on the vp pack output with React's production build, on Windows, for 40 columns with 1 start-frozen column. Every measurement ran in a fresh process or page, with the order of the builds rotating between rounds: 10 rounds in Node, 8 in Chromium, 6 in Firefox, and 4 in WebKit. Differences are medians of the per-round differences, and a byte-identical copy of the build usually stayed within ±2%. These runs predate #4258, but this PR's built diff is identical to the measured one.

Time per call, in hot loops:

Function Node 26 Chromium 156 Firefox 157 WebKit 27.2
getCellStyle 9.00 → 8.53 (−5.9%) 9.83 → 8.71 (−11.7%) 7.71 → 7.38 (−4.7%) 4.12 → 3.74 (−9.6%)
getCellClassname 65.7 → 64.4 (−2.3%) 32.3 → 30.7 (−4.6%) 53.3 → 51.3 (−4.1%) 17.8 → 17.1 (−4.5%)

In Node, getColSpan went from 3.68 to 2.76 ns (−25%), sorting 40 columns from 346 to 304 ns (−12%), and useCalculatedColumns from 3.57 to 3.48 µs (−2.5%).

Mean render and commit time per update, in ms, without browser layout, for 10,000 rows:

Update Chromium Firefox WebKit
Mount 1.96 → 1.95 (−0.7%) 5.39 → 5.31 (−1.6%) 4.67 → 4.67 (+0.4%)
Vertical scroll 2.34 → 2.35 (+0.1%) 5.96 → 5.93 (−0.2%) 3.27 → 3.32 (−0.1%)
Horizontal scroll 1.70 → 1.69 (0.0%) 4.06 → 4.07 (+0.4%) 2.55 → 2.53 (+0.2%)
New columns array 0.75 → 0.75 (−0.4%) 2.29 → 2.30 (+0.4%) 0.84 → 0.87 (+4.1%)

In Node, renderToString of 100 rows took 5.37 ms before and 5.40 ms after (+1.2%), also within noise.

There's one exception. In WebKit on Windows, a new columns array renders about 0.03 ms slower with these columns: +6.3%, +4.1%, and +3.9% in three separate runs of 4, 12, and 15 rounds. With 2 start-frozen and 2 end-frozen columns, it's 1–5% faster instead. The getCellStyle and getCellClassname changes each reproduce the slowdown, and a build with only the other changes doesn't. The cause is unknown: it's about 50 ns per cell, more than those two functions cost in total, so it's an indirect effect. It only applies when columns changes, and Safari wasn't tested.

vp run ci passes.

🤖 Generated with Claude Code

Most columns aren't frozen, and start-frozen columns are more common than
end-frozen ones, so check `false` first, then `'start'`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien
nstepien marked this pull request as ready for review November 1, 2026 01:04
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (163a071) to head (4e95d6b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4273   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files          44       44           
  Lines        2204     2208    +4     
  Branches      964      965    +1     
=======================================
+ Hits         2188     2192    +4     
  Misses         16       16           
Files with missing lines Coverage Δ
src/DataGrid.tsx 99.44% <100.00%> (ø)
src/hooks/useCalculatedColumns.ts 100.00% <100.00%> (ø)
src/hooks/useViewportColumns.ts 100.00% <100.00%> (ø)
src/utils/styleUtils.ts 100.00% <100.00%> (ø)
🚀 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.

@nstepien
nstepien merged commit 32a71bc into main Nov 1, 2026
6 checks passed
@nstepien
nstepien deleted the frozen-check-order branch November 1, 2026 01:06
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.

2 participants