Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize CommandRunner and Commands #4683

Merged
merged 1 commit into from
May 17, 2021

Conversation

paulbalandan
Copy link
Member

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • Conforms to style guide

@paulbalandan
Copy link
Member Author

@MGatner this optimization made all test cases of CommandRunnerTest to be all under 0.50 s.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

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

Glad you cracked this egg! Moving the discovery to the constructor could cause some people problems, but generally I think it is a better design. Maybe see if we can get another review from @lonnieezell or @samsonasik on that point? Otherwise just a couple of tweaks.

system/CLI/CommandRunner.php Outdated Show resolved Hide resolved
system/CLI/Commands.php Outdated Show resolved Hide resolved
tests/system/CLI/CommandRunnerTest.php Outdated Show resolved Hide resolved
tests/system/CLI/CommandRunnerTest.php Outdated Show resolved Hide resolved
@lonnieezell
Copy link
Member

I typically prefer not to do things like that in a constructor but in this case I don't see a problem with it. Commands aren't something that are called all of the time, and testing is where that has the tendency to be the biggest issue. But that's why we're moving it now so it looks good to me!

@paulbalandan
Copy link
Member Author

Glad you cracked this egg! Moving the discovery to the constructor could cause some people problems, but generally I think it is a better design. Maybe see if we can get another review from @lonnieezell or @samsonasik on that point? Otherwise just a couple of tweaks.

I have pondered on this and I don't think moving discovery to the constructor would give us problems. Discovery essentially fills up the $commands array prop with the discovered commands. Current design shows that every invoke of run we call discoverCommands which in turn returns early if the $commands prop is already populated. So this prop is never overwritten. Moving the discovery at constructor initialization would be a big gain, as the tests demonstrate.

@MGatner MGatner merged commit de9f474 into codeigniter4:develop May 17, 2021
@paulbalandan paulbalandan deleted the command-runner branch May 17, 2021 13:18
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.

4 participants