Skip to content

Commit 53196cd

Browse files
committed
perf(@angular/cli): skip eager yargs help message formatting during command execution
Whenever a subcommand is invoked, Yargs eagerly formats and caches the complete command help message via its internal cacheHelpMessage() method. This involves assembling layout tables with cliui, wrapping text with wrap-ansi, and evaluating Unicode string widths with string-width, even when the command succeeds and help output is never requested. Because the Angular CLI explicitly configures showHelpOnFail(false) and handles errors via a custom failure handler, this cached help message is never consumed in either the success or failure paths. Overriding cacheHelpMessage to a no-op when neither --help nor --json-help is requested eliminates roughly 15ms to 20ms of synchronous formatting overhead from the CLI startup path.
1 parent a704f77 commit 53196cd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/angular/cli/src/command-builder/command-runner.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ export async function runCommand(args: string[], logger: logging.Logger): Promis
102102
addCommandModuleToYargs(CommandModule, context);
103103
}
104104

105+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106+
const usageInstance = (localYargs as any).getInternalMethods().getUsageInstance();
105107
if (jsonHelp) {
106-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
107-
const usageInstance = (localYargs as any).getInternalMethods().getUsageInstance();
108108
usageInstance.help = () => jsonHelpUsage(localYargs);
109+
} else if (!help) {
110+
// Yargs eagerly caches and formats the full command help (including table wrapping
111+
// and Unicode string-width calculations via cliui) whenever a subcommand executes,
112+
// in case the command fails. Because showHelpOnFail is disabled, this formatted text
113+
// is never used. Skipping this work avoids non-trivial synchronous overhead during startup.
114+
usageInstance.cacheHelpMessage = () => {};
109115
}
110116

111117
// Add default command to support version option when no subcommand is specified

0 commit comments

Comments
 (0)