Lazy-load console commands registration to avoid overhead in HTTP requests#23
Conversation
…gisterMakeCommand() Convert eager command class imports to lazy loading using fully qualified class name strings. This prevents autoloading overhead for command classes during HTTP requests. - Removed 20 command class use statements - Updated registerMakeCommand() to use string FQCNs instead of Class::class - Maintains identical functionality via Laravel's lazy command resolution Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce non-console request overhead by making console command registration “lazy” (avoiding eager command class loading/registration work during HTTP requests).
Changes:
- Removed
useimports for allmodule:make:*andmodule:listcommand classes. - Replaced
SomeCommand::classentries with hard-coded fully-qualified class-name strings inregisterMakeCommand().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $this->commands([ | ||
| ModuleMakeComponentCommand::class, | ||
| ModuleMakeConsoleCommand::class, | ||
| ModuleMakeControllerCommand::class, | ||
| ModuleMakeEventCommand::class, | ||
| ModuleMakeFactoryCommand::class, | ||
| ModuleMakeJobCommand::class, | ||
| ModuleListCommand::class, | ||
| ModuleMakeListenerCommand::class, | ||
| ModuleMakeMailCommand::class, | ||
| ModuleMakeModelCommand::class, | ||
| ModuleMakeMiddlewareCommand::class, | ||
| ModuleMakeMigrationCommand::class, | ||
| ModuleMakeNotificationCommand::class, | ||
| ModuleMakeProviderCommand::class, | ||
| ModuleMakePolicyCommand::class, | ||
| ModuleMakeResourceCommand::class, | ||
| ModuleMakeRequestCommand::class, | ||
| ModuleMakeSeederCommand::class, | ||
| ModuleMakeTestCommand::class, | ||
| ModuleMakeViewCommand::class, | ||
| 'NorbyBaru\Modularize\Console\Commands\ModuleMakeComponentCommand', | ||
| 'NorbyBaru\Modularize\Console\Commands\ModuleMakeConsoleCommand', | ||
| 'NorbyBaru\Modularize\Console\Commands\ModuleMakeControllerCommand', | ||
| 'NorbyBaru\Modularize\Console\Commands\ModuleMakeEventCommand', |
There was a problem hiding this comment.
These registrations were changed from ImportedCommand::class to hard-coded class-name strings. Foo\\Bar::class already resolves to a string without requiring the class to be loaded, so this likely doesn’t reduce overhead but does reduce refactor safety (renames won’t be caught) and static analysis/IDE support. Prefer keeping the use ... imports and passing ::class constants.
In registerMakeCommand(), all 17 module:make:* command classes are registered via $this->commands() during every request cycle, including HTTP requests. While autoloadConsoleCommands() correctly checks runningInConsole(), the registerMakeCommand() in register() only checks runningInConsole() at the call site but still eagerly resolves command class autoloading.