Skip to content

Avoid template engine initialization for generic help - #56231

Merged
JeremyKuhne merged 1 commit into
dotnet:mainfrom
JeremyKuhne:optimize-new-help-environment-creation
Sep 10, 2026
Merged

JeremyKuhne merged 1 commit into
dotnet:mainfrom
JeremyKuhne:optimize-new-help-environment-creation

Conversation

@JeremyKuhne

Copy link
Copy Markdown
Member

Summary

  • handle generic dotnet new --help and dotnet new create --help before creating the Template Engine host and environment
  • preserve the existing Template Engine initialization path for template-specific help
  • add coverage proving generic help does not construct the host

Performance

Measured with a Windows x64 Release ReadyToRun 11.0.100-dev SDK, alternating fresh processes, isolated CLI homes, and equivalent prepared template state.

  • 30/30 paired runs were faster with byte-for-byte equivalent output
  • median elapsed time fell from 139.913 ms to 109.444 ms: 21.79% faster
  • median sampled allocation across five EventPipe gc-verbose pairs fell from 1,915,480 B to 1,490,776 B: 424,704 B (22.17%) lower
  • the CreateEnvironmentSettings and NewCommandParser.CreateHost allocation subtrees were absent from all candidate captures
  • GC count remained zero in every capture

GCAllocationTick values vary at sampling granularity.

Testing

  • HelpTests: 37/37 passed on Release net11.0
  • product-backed DotnetNewHelpTests: 38/38 passed on Release net11.0
  • mutation check: restoring eager environment creation causes both generic-help host-count cases to fail

Copilot AI lite review requested due to automatic review settings September 10, 2026 02:36
@JeremyKuhne
JeremyKuhne requested a review from a team as a code owner September 10, 2026 02:36
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrowly scoped changes preserve template-specific behavior; the remaining coverage suggestion is a non-blocking nit.

Pull request overview

Improves generic dotnet new help performance by avoiding unnecessary Template Engine initialization while preserving template-specific help behavior.

Changes:

  • Adds early handling for generic help.
  • Preserves host initialization for template-specific help.
  • Adds regression coverage for host construction.
File summaries
File Description
test/Microsoft.TemplateEngine.Cli.UnitTests/ParserTests/HelpTests.cs Verifies generic help does not construct the host.
src/Cli/Microsoft.TemplateEngine.Cli/Commands/NewCommand.Help.cs Skips environment creation for generic help.
src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs Centralizes generic-help handling.
Review details

Suppressed comments (1)

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.Help.cs:95

  • Could you add a product-backed case for dotnet new create console --help (or an equivalent unit test with a non-empty ShortName)? The changed InstantiateCommand.CustomHelpLayout branch is the only direct-create path that preserves template-specific help, but the current coverage exercises only generic create and legacy new <template> help. A regression that routes a non-empty ShortName to generic help or fails to initialize the environment for this subcommand would therefore go undetected.
                if (TryWriteCommandHelp(context, instantiateCommandArgs))
                {
                    return;
                }

                using IEngineEnvironmentSettings environmentSettings = CreateEnvironmentSettings(instantiateCommandArgs, context.ParseResult);
                WriteHelp(context, instantiateCommandArgs, environmentSettings);
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

@JeremyKuhne
JeremyKuhne merged commit 2232504 into dotnet:main Sep 10, 2026
24 checks passed
@JeremyKuhne
JeremyKuhne deleted the optimize-new-help-environment-creation branch September 10, 2026 17:33
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 11, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — fbf321b8 Deployed Sep 10, 2026 by JeremyKuhne via pre_activation #4101
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.

3 participants