Skip to content

perf: optimize isGriffelCSSModule, add processAssets timing#826

Draft
layershifter wants to merge 11 commits intomicrosoft:mainfrom
layershifter:perf/griffel-plugin-optimizations
Draft

perf: optimize isGriffelCSSModule, add processAssets timing#826
layershifter wants to merge 11 commits intomicrosoft:mainfrom
layershifter:perf/griffel-plugin-optimizations

Conversation

@layershifter
Copy link
Copy Markdown
Member

Summary

  • Replace buffer content scanning (Buffer.indexOf('/** @griffel:css-start')) with module.identifier().includes(virtualLoaderPath) — avoids reading CSS content for every module
  • Remove unused CSSModule type and isCSSModule function
  • Add process.hrtime.bigint() timing around the processAssets hook (CSS parsing + sorting), reported in stats as "Time spent in processAssets (sort)"

Test plan

  • All webpack-plugin tests pass (47/47)

🤖 Generated with Claude Code

- Replace buffer content scanning with module.identifier() path check
- Remove unused CSSModule type and isCSSModule function
- Add timing for processAssets hook (CSS sorting) to stats output

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@layershifter layershifter requested a review from a team as a code owner March 24, 2026 20:43
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 24, 2026

📊 Bundle size report

✅ No changes found

layershifter and others added 9 commits March 24, 2026 21:50
Adds per-phase timings to TransformResult (parsing, walking, evaluation,
resolving, codeTransform) and per-operation timings in Module (transform/shaker,
ESM→CJS, vm.runInContext, fs.readFileSync). Reported in stats output when
collectStats is enabled.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace per-call vm.createContext() with a single shared context whose
per-module bindings (module, exports, require, __filename, __dirname) are
swapped before each script.runInContext(). This avoids the overhead of
creating a new V8 sandbox for every module evaluation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…uild, dead code removal)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…en nested requires

The shared VM context sandbox gets mutated by nested require() calls,
causing earlier modules to see later modules' exports. Fix by passing
module, exports, require, __filename, __dirname as function parameters
to the wrapper IIFE, capturing them at call time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Cache getVisitors() by node type (avoids array allocations per AST node)
- Replace forEach with for loops in baseVisit and callbacks
- Inline addEdge resolution for non-PromisedNode (skip action queue)
- Replace stack.unshift/shift with push/pop (O(1) instead of O(n))
- Replace stack.find() with reverse for loops (innermost-first)
- Replace visitors.shift() with index-based iteration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove per-phase timings from transformSync, Module, and shaker.
Keep only the existing processAssetsTime and per-file time/evaluationMode stats.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@layershifter layershifter marked this pull request as draft April 7, 2026 08:58
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