Skip to content

perf(postcss-discard-duplicates): bucket rules by selector - #1815

Merged
ludofischer merged 1 commit into
cssnano:masterfrom
dkryaklin:perf/discard-duplicates-bucket
Jun 8, 2026
Merged

perf(postcss-discard-duplicates): bucket rules by selector#1815
ludofischer merged 1 commit into
cssnano:masterfrom
dkryaklin:perf/discard-duplicates-bucket

Conversation

@dkryaklin

@dkryaklin dkryaklin commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

What

Replaces the O(N²) duplicate-rule scan in postcss-discard-duplicates with a single selector-bucketing pass: each rule dedupes only against earlier rules sharing its selector instead of scanning every preceding sibling.

Full default preset over a corpus of 21 released framework CSS files (master = 100% of current time, lower is faster):

master this PR
total time 100% 93% (−7%)

The scan is quadratic even when there are no duplicates, so the win grows with rule count. Synthetic stylesheets of N distinct-selector rules (this plugin only):

rules (N) master this PR
500 100% (1.69 ms) 71% (1.20 ms)
1000 100% (4.84 ms) 52% (2.52 ms)
2000 100% (13.78 ms) 43% (5.90 ms)
4000 100% (45.16 ms) 28% (12.78 ms)

Document order and last-wins semantics are unchanged.

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.80%. Comparing base (a282215) to head (7d8bcc3).
⚠️ Report is 49 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1815      +/-   ##
==========================================
- Coverage   98.82%   98.80%   -0.02%     
==========================================
  Files         124      126       +2     
  Lines       10776    11305     +529     
  Branches       15       15              
==========================================
+ Hits        10649    11170     +521     
- Misses        127      135       +8     

☔ View full report in Codecov by Harness.
📢 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.
@ludofischer
ludofischer force-pushed the perf/discard-duplicates-bucket branch from 693b090 to 7d8bcc3 Compare June 8, 2026 20:59
@ludofischer
ludofischer merged commit c7b3d83 into cssnano:master Jun 8, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants