Skip to content

Conversation

@walterlv
Copy link
Member

对于两次 AddHandler 删除委托后的优化效果:

image

上:本次 PR 之前
下:本次 PR 之后

可以看到,耗时减少了,分配也较少了。

@walterlv walterlv requested a review from Copilot September 30, 2025 07:45
Copy link

Copilot AI left a 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 refactors the command line handling architecture to eliminate delegates and optimize memory allocation. The changes also improve parsing performance as a side effect. The core change replaces the delegate-based CommandObjectFactory pattern with an interface-based ICommandObjectMetadata approach that encapsulates both object creation and execution logic.

  • Replaced delegate-based command handling with interface-based metadata classes
  • Consolidated command object creation and execution logic into structured metadata types
  • Removed delegate parameters from parser constructors in favor of direct method calls

Reviewed Changes

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

Show a summary per file
File Description
CommandLineParser.cs Replaced delegate callbacks with direct method calls to ICommandObjectBuilder interface
TaskCommandHandler.cs Refactored anonymous handler classes to use metadata pattern instead of delegates
ICommandRunnerBuilder.cs Updated method signatures to use ICommandObjectMetadata instead of CommandObjectFactory
ICommandHandler.cs Renamed ICommandOptions to ICommandObject and added backward compatibility
ICommandObjectMetadata.cs Added new interface definitions for metadata-based command object handling
CommandRunningContext.cs Moved CommandRunningContext to separate file from CommandObjectFactory.cs
CommandObjectFactory.cs Removed file containing delegate definitions
CommandRunnerBuilderExtensions.cs Updated extension methods to use metadata pattern
CommandRunner.cs Refactored internal storage and execution to use metadata instead of delegates
CommandLineExceptionHandler.cs Added metadata wrapper for exception handlers
CommandLine.cs Removed deprecated As method overload
ModelBuilderGenerator.cs Updated source generator to create metadata classes instead of static factory methods
InterceptorGenerator.cs Updated interceptor generation to instantiate metadata objects
AddHandlers.cs Added performance test for handler addition
CommandLineArguments.cs Added test data for performance benchmarks
Program.cs Updated sample code to use new metadata pattern

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@lindexi lindexi merged commit 2bfe8bf into main Sep 30, 2025
3 checks passed
@lindexi lindexi deleted the t/walterlv/delegate branch September 30, 2025 07:48
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