Skip to content

perf(removeHiddenElems): cache computed styles - #2280

Open
TrySound wants to merge 1 commit into
svg:mainfrom
TrySound:perf/remove-hidden-elems
Open

perf(removeHiddenElems): cache computed styles#2280
TrySound wants to merge 1 commit into
svg:mainfrom
TrySound:perf/remove-hidden-elems

Conversation

@TrySound

Copy link
Copy Markdown
Member

Summary

  • cache computed styles while removeHiddenElems makes its two traversal passes
  • optionally cache inherited styles in computeStyle, avoiding repeated ancestor traversal and selector matching
  • stop parsing path data after two items because removeHiddenElems only needs to distinguish empty, single-point, and renderable paths

Benchmark

Benchmarked against the regression fixture suite at 77ba065b4e4b4902c8795921287f9cf7, using all Charm and Oxygen icon fixtures:

  • 4,592 SVG files (263 Charm and 4,329 Oxygen)
  • default preset, single pass, floatPrecision: 4
  • two worker threads
  • Node.js 22.23.2 on Linux x86-64
  • phase timings are elapsed time summed across workers
Metric Before After Change
Wall time 209.71s 172.71s -17.6%
removeHiddenElems 58.35s 27.21s -53.4%
removeHiddenElems share 14.6% 8.3% -6.3 pp
removeHiddenElems rank 2nd 4th -2 places

The full after profile was:

Phase Before After After share
convertPathData 70.36s 72.94s 22.1%
removeHiddenElems 58.35s 27.21s 8.3%
minifyStyles 50.95s 51.21s 15.5%
mergePaths 27.86s 28.21s 8.6%
removeUselessStrokeAndFill 23.98s 26.23s 8.0%
convertTransform 18.56s 18.47s 5.6%
cleanupEnableBackground 14.30s 14.19s 4.3%
removeUnknownsAndDefaults 13.16s 13.72s 4.2%
cleanupIds 10.69s 10.48s 3.2%
serializer 3.33s 3.43s 1.0%

Because parallel phase timings include GC and worker contention, unrelated phases vary between runs. The removeHiddenElems result was also checked separately on a deterministic every-tenth-file Oxygen sample (433 files): 6.52s before vs 2.96s after (-54.6%).

Optimized output was compared against the baseline for a deterministic 460-file Charm/Oxygen sample with no differences.

Tests

  • pnpm typecheck
  • pnpm exec vitest run lib/path.test.js lib/style.test.js test/plugins/_index.test.js --exclude '.worktrees/**' (407 tests)
  • ESLint and Prettier on changed files

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