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

fix(core): reduce time it takes to require nx commands #28884

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

FrozenPandaz
Copy link
Collaborator

Current Behavior

nx/src/command-line/nx-commands takes ~88-91ms on my machine to require which needs to happen for every single Nx command.

Expected Behavior

nx/src/command-line/nx-commands takes ~30-33ms on my machine to require.

Related Issue(s)

Fixes #

Copy link

vercel bot commented Nov 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Nov 11, 2024 8:56pm


export const yargsInitCommand: CommandModule = {
command: 'init',
describe:
'Adds Nx to any type of workspace. It installs nx, creates an nx.json configuration file and optionally sets up remote caching. For more info, check https://nx.dev/recipes/adopting-nx.',
builder: (yargs) => withInitOptions(yargs),
builder: async (yargs) => (await import('./init')).withInitOptions(yargs),
Copy link
Member

Choose a reason for hiding this comment

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

This change shouldn't make much functional difference, and I'd prefer to keep builder inside command-object. The builders have to run for every command anyway and the idea of the dynamic require on the handler is to avoid pulling in things required for implementation on every command. Having this here defeats that purpose.

If you wanted to pull builder logic / withInitOptions into a separate file, it'd need to be a different file than the implementation logic, and I don't think its worth it. It's not like the yargs stuff is pulling in more than any other command.

@FrozenPandaz FrozenPandaz marked this pull request as ready for review November 11, 2024 22:17
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner November 11, 2024 22:17
@FrozenPandaz FrozenPandaz merged commit c21b039 into master Nov 11, 2024
6 checks passed
@FrozenPandaz FrozenPandaz deleted the perf branch November 11, 2024 22:18
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants