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

refactor: perf gains #260

Merged
merged 3 commits into from
Jul 31, 2022
Merged

refactor: perf gains #260

merged 3 commits into from
Jul 31, 2022

Conversation

juliusmarminge
Copy link
Member

Improve CLI Performance

  • I reviewed linter warnings + errors, resolved formatting, types and other issues related to my work
  • The PR title follows the convention we established conventional-commit
  • I performed a functional test on my final commit

Scaffolding a full T3 app can take time. This aims to reduce that time.

For initialization stuff like we do, fs.copySync() is faster than fs.copy() etc. (from what I've read you should only use async version on server stuff when needing cpu power for other stuff)

So I have refactored to take advantage of this. By using sync over async I decreased scaffolding times on my machine from 32 to 28 seconds for a full app.

I also refactored so that we only run a single npm install command at the end, instead of running 5-10 per app.

Might be more things we can do to further decrease scaffolding time?

Screenshots

[Screenshots]

💯

@juliusmarminge
Copy link
Member Author

Correct branch this time

pkgManager === "npm"
? "npx prisma generate"
: `${pkgManager} prisma generate`;
await execa(generateClientCmd, { cwd: projectDir });
Copy link
Member Author

Choose a reason for hiding this comment

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

this will be executed in post install script anyway so no need to run it here too

Copy link
Member

@nexxeln nexxeln left a comment

Choose a reason for hiding this comment

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

So basically most of the async stuff is sync now, so its faster?

Comment on lines +24 to +45
export const dependencyVersionMap = {
// NextAuth.js
"next-auth": "^4.10.2",
"@next-auth/prisma-adapter": "^1.0.4",

// Prisma
prisma: "^4.1.0",
"@prisma/client": "^4.1.0",

// TailwindCSS
tailwindcss: "^3.1.6",
autoprefixer: "^10.4.7",
postcss: "^8.4.14",

// tRPC
"@trpc/client": "10.0.0-alpha.41",
"@trpc/server": "10.0.0-alpha.41",
"@trpc/react": "10.0.0-alpha.41",
"@trpc/next": "10.0.0-alpha.41",
"react-query": "^3.39.2",
superjson: "^1.9.1",
} as const;
Copy link
Member

Choose a reason for hiding this comment

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

Love this

@juliusmarminge
Copy link
Member Author

juliusmarminge commented Jul 27, 2022

So basically most of the async stuff is sync now, so its faster?

Yes changing "fs.async" -> "fs.sync" made some difference (about 5 seconds I think), I read that in some cases it can be upto 6-7 times faster...

Example test: https://adamhooper.medium.com/node-synchronous-code-runs-faster-than-asynchronous-code-b0553d5cf54e but there are others showing simliar results

Then by just adding the dependency to package.json and running a single npm install command at the end also does a lot.

@nexxeln
Copy link
Member

nexxeln commented Jul 29, 2022

Then by just adding the dependency to package.json and running a single npm install command at the end also does a lot.

Makes sense, so is this ready to be merged? We can test it out in beta.

@juliusmarminge
Copy link
Member Author

Then by just adding the dependency to package.json and running a single npm install command at the end also does a lot.

Makes sense, so is this ready to be merged? We can test it out in beta.

I targetted next but maybe we can publish beta from there?

@nexxeln
Copy link
Member

nexxeln commented Jul 29, 2022

Sure

@juliusmarminge juliusmarminge merged commit 6905215 into t3-oss:next Jul 31, 2022
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.

None yet

2 participants