redwood icon indicating copy to clipboard operation
redwood copied to clipboard

[RFC]: CLI Speed Improvement

Open peterp opened this issue 2 years ago • 8 comments

Summary

The CLI is a bit slow. It takes ~1150ms to run redwood --help. I believe speed is part of DX and we should aim for ~300ms response time in the CLI.

Benchmark 1: node node_modules/@redwoodjs/cli/dist/index.js --help
  Time (mean ± σ):      1.146 s ±  0.004 s    [User: 1.139 s, System: 0.200 s]
  Range (min … max):    1.141 s …  1.151 s    10 runs

Detailed proposal

We're also using yargs at Snaplet and the approach we've taken is to separate the handlers (the logic that the CLI runs) from the structure that the CLI runs. We do this by asynchronously importing the code from the handler.

But first, let's figure out what makes the CLI slow: Normal: 1.143 s Removing all the commands: 686.5 ms Removing all the middleware: 119.8 ms

So with these results we can see that middleware adds an additional 500 ms (Surprizing!), and all the commands add another 600 ms.

[As I'm working on this I'll update the issue with additional information]

Are you interested in working on this?

  • [x] I'm interested in working on this

peterp avatar Jul 23 '22 16:07 peterp

In addition to the speed, I want to bring up the problem with the Prompt Windows. Why does redwoodjs's CLI raise so many Prompt Windows which only stay for a little while. Can we simply disable this?

TristanWYL avatar Jul 24 '22 03:07 TristanWYL

Update, a ton of time is spent in lib/index.js. This is where we import everything and the kitchen sink. I'm going to split the largest imports into seperate files: babel, prettier, listr image

peterp avatar Jul 24 '22 06:07 peterp

@peterp Interesting! May we know how did you make this graph?

TristanWYL avatar Jul 24 '22 07:07 TristanWYL

@TristanWYL Assuming you're on windows, see #5728.

Thx for letting me know!

TristanWYL avatar Jul 24 '22 08:07 TristanWYL

@TristanWYL That's 0x

npx 0x -o node_modules/@redwoodjs/cli/dist/index.js --help

peterp avatar Jul 25 '22 09:07 peterp

@TristanWYL That's 0x

Awesome! Thanks so much

TristanWYL avatar Jul 28 '22 08:07 TristanWYL

Even though #6028 was merged, I'll reopen this as we plan on making more improvements.

jtoar avatar Jul 28 '22 10:07 jtoar

I just had a idea to improve performance What if we create CLI as standalone built with Non Javascript Language For Example vlang ( Fastest programming language )

AjayTheWizard avatar Aug 06 '22 11:08 AjayTheWizard