GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(webpack-cli): cache schema arguments and use map lookups for options by alexander-akait · Pull Request #4760 · webpack/webpack-cli

Conversation

@alexander-akait

@alexander-akait alexander-akait commented May 26, 2026

Copy link
Copy Markdown
Member

Building CLI argument metadata from the webpack/dev-server schema walks a
large JSON schema and was repeated within a single run (once per command and
again in loadConfig). Memoize it per webpack module and schema. Replace the
linear .find() scans over the full option list with map/set lookups when
matching CLI options in loadConfig and the serve command.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
claude added 8 commits May 26, 2026 12:46
@claude
perf(webpack-cli): cache schema arguments and use map lookups for opt…
67d4691
…ions

Building CLI argument metadata from the webpack/dev-server schema walks a
large JSON schema and was repeated within a single run (once per command and
again in loadConfig). Memoize it per webpack module and schema. Replace the
linear `.find()` scans over the full option list with map/set lookups when
matching CLI options in loadConfig and the serve command.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): apply CLI options from cached arguments map in loa…
01dd6ec
…dConfig

`loadConfig` rebuilt a full `schemaToOptions` array (~850 objects) and a
lookup map on every run just to match passed CLI options. The cached
`getArguments()` result is already a name-keyed map of exactly the metadata
`processArguments` consumes, so index it directly. Also hoist the per-call
`flagsWithAlias` array in `makeOption` to a module-level Set.

This roughly halves the time spent in `loadConfig` and removes ~850 object
allocations plus a Map per build invocation.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): read directories once for default config discovery
f4ae979
When no `--config` is passed, config discovery probed every
`<name><ext>` combination (3 base names x ~35 extensions = ~100 paths)
with a separate sequential `fs.access` call. For config-less builds these
all fail, costing ~5-6ms of serialized syscalls.

Read each candidate directory once with `readdir`, match names in the same
priority order in memory, and confirm the chosen file with a single
`access` (preserving exact existence semantics for e.g. broken symlinks).
This keeps the common "config exists" path fast while cutting the
no-config case from ~100 syscalls to ~2.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): create colors lazily to avoid loading webpack when…
5b4e29e
… unused

`#createColors` loads the webpack package to obtain color helpers, but the
constructor ran it eagerly on every invocation. Commands like `version` and
`info` never otherwise need webpack, so they paid for loading it. Make
`colors` a lazy getter so the webpack require only happens when colored
output is actually produced.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): hold cached argument metadata via WeakRef
10cdeeb
The per-schema argument metadata cached for option parsing is large
(~1MB for webpack, ~1.85MB including dev-server) but is only needed
while setting up a command. Storing it via WeakRef lets the GC reclaim
it once setup completes, which matters for long-running serve/watch
sessions. A cache miss simply rebuilds it; in practice V8 keeps the
target alive across the short setup window, so the dedup within a run
(only one schema walk) is preserved.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): stop retaining serve option arrays for the whole s…
cb24a16
…ession

The serve command stashed the full webpack and dev-server option arrays
(~900KB) in its command context, which lives for the entire dev-server
session even though the arrays are only needed during setup. Build the
arrays transiently in the `options` callback for registration, and derive
the action's lightweight lookups (built-in option name set, dev-server arg
metadata) from the cached `getArguments` map instead. The large arrays are
now reclaimable after startup.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
fix(webpack-cli): make default config discovery matching case-insensi…
48e97b7
…tive

The readdir-based discovery matched entry names case-sensitively, which
differed from the previous `fs.access` behavior on case-insensitive
filesystems (a config named e.g. `Webpack.Config.js` would no longer be
found). Lowercase the directory entries for the membership check and rely
on the existing `access` confirm for exact existence semantics, so behavior
matches the old `fs.access` on both case-sensitive and case-insensitive
filesystems while keeping the fast no-config path.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
perf(webpack-cli): register only the options present in argv
50a9e7c
Setting up a command registered all ~850 webpack/dev-server options on
commander on every run, which dominated CLI setup time (~28ms) and retained
~1.4MB of Option objects. Register only the options actually present in the
argument tokens instead; unrecognized flags still error, and "did you mean"
suggestions use the full option-name list stashed on the command. Help still
registers every option so it can list them all.

Cuts command-setup time roughly in half and CLI overhead by ~35% for a
typical build, and drops retained heap by ~1.4MB.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
Copilot AI review requested due to automatic review settings May 26, 2026 20:38
@changeset-bot

changeset-bot Bot commented May 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1d130ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@linux-foundation-easycla

linux-foundation-easycla Bot commented May 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA Not Signed

  • ❌ - login: @claude / name: Claude. The commit (01dd6ec, 10cdeeb, 1d130ba, 42a88da, 48e97b7, 50a9e7c, 5b4e29e, 67d4691, b60f44c, cb24a16, edef29d, f4ae979) is not authorized under a signed CLA. Please click here to be authorized. For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

claude[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of alexander-akait May 26, 2026 20:38
View session
@codecov

codecov Bot commented May 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.77049% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.77%. Comparing base (5b33f70) to head (1d130ba).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
packages/webpack-cli/src/webpack-cli.ts 98.77% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4760      +/-   ##
==========================================
+ Coverage   92.37%   92.77%   +0.39%     
==========================================
  Files          14       14              
  Lines        4736     4911     +175     
  Branches      698      734      +36     
==========================================
+ Hits         4375     4556     +181     
+ Misses        359      353       -6     
  Partials        2        2              
Files with missing lines Coverage Δ
packages/webpack-cli/src/webpack-cli.ts 96.18% <98.77%> (+0.12%) ⬆️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b33f70...1d130ba. Read the comment docs.

🚀 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI reviewed May 26, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes webpack-cli startup and command execution by caching expensive schema-derived CLI argument metadata and reducing repeated linear scans and filesystem probes.

Changes:

  • Cache webpack.cli.getArguments(schema) results per webpack module/schema using WeakMap + WeakRef, and reuse the returned name-keyed argument map for option application.
  • Speed up option matching by switching from repeated .find() scans to Set/map lookups, and avoid registering all CLI options with commander unless needed for help.
  • Optimize default-config discovery by reading candidate directories once (via readdir) and confirming matches with fs.access.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/webpack-cli/src/webpack-cli.ts Adds argument metadata caching, commander option-registration optimization, map-based option lookups, and faster default-config discovery; also lazily creates colors.
.changeset/fast-pumas-cache.md Adds a changeset documenting the performance and memory improvements.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/webpack-cli/src/webpack-cli.ts Outdated
Comment on lines +717 to +719
// Short option: the alias is the first character; the rest (if any) is
// an attached value, e.g. `-d<value>` means `-d <value>`.
names.add(token[1]);
Comment thread packages/webpack-cli/src/webpack-cli.ts Outdated
Comment on lines 2494 to 2498
const entries = await readDirectoryEntries(path.dirname(resolvedBase));

if (!entries) {
continue;
}
Comment thread packages/webpack-cli/src/webpack-cli.ts Outdated
Comment on lines +659 to +660
(command as Command & { allOptionNames?: string[] }).allOptionNames = commandOptions.map(
(option) => option.name,
@claude
fix(webpack-cli): address review feedback on lazy option registration
42a88da
- Register every letter of a combined short token (e.g. `-abc`), not just the
  first, so clustered boolean short flags are not dropped and reported as
  unknown options.
- Include the `--no-<name>` negated forms in the stashed option-name list so
  "did you mean" suggestions still work for mistyped negated flags.
- Fall back to per-candidate `access` probing when a directory can't be listed
  (e.g. execute-only permissions), so default-config discovery keeps working
  in restricted-permission directories.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@alexander-akait
alexander-akait requested a review from Copilot May 27, 2026 12:40
Copilot started reviewing on behalf of alexander-akait May 27, 2026 12:40
View session
claude added 3 commits May 27, 2026 12:42
@claude
docs(changeset): condense entry to a single sentence
b60f44c
https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
refactor(webpack-cli): extract default-config discovery into a method
edef29d
Move the candidate-search logic out of `loadConfig` into a dedicated
`#findDefaultConfigFile` private method for readability. No behavior change.

https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
@claude
docs(webpack-cli): condense comments to single sentences
1d130ba
https://claude.ai/code/session_01PEtzv6Xqv2yXQaQsZaeoSF
Copilot AI reviewed May 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-akait
alexander-akait requested a review from Copilot May 27, 2026 13:10
Copilot started reviewing on behalf of alexander-akait May 27, 2026 13:11
View session
Copilot AI reviewed May 27, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-akait
alexander-akait merged commit 183d0e6 into main May 27, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the claude/performance-memory-optimization-VyCIM branch May 27, 2026 13:21
@github-actions github-actions Bot mentioned this pull request May 27, 2026
chore(release): new release #4711
Merged
@claude claude Bot mentioned this pull request Jun 10, 2026
chore(deps): bump webpack-cli from 7.0.2 to 7.0.3 opengovsg/isomer#2421
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@alexander-akait @claude
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.