T3 app takes up too much RAM

when I start my app with npm run dev acces the nextjs app via localhost, and check the task manager, the windows powershell already takes up 300MB of RAM. I sign in using Discord provider, It takes up More! After that the just becomes unresponsive. And the terminal just goes crazyy. I could hop on a call and share my screen to show what I mean.
95 Replies
kenny
kennyβ€’14mo ago
I am using next-auth with prisma adapters this is what an Account model looks like
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
@@unique([provider, providerAccountId])
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
@@unique([provider, providerAccountId])
}
user model
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
chatId String
chat Chat @relation(fields: [chatId], references: [id])
@@index([chatId])
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
chatId String
chat Chat @relation(fields: [chatId], references: [id])
@@index([chatId])
}
chat model
model Chat {
id String @id @default(cuid())
max_users Int
users User[]
}
model Chat {
id String @id @default(cuid())
max_users Int
users User[]
}
nexxel
nexxelβ€’14mo ago
its typescript what do you expect loll javascript is always very heavy on ram
Dosha
Doshaβ€’14mo ago
if u wish to have small ram usage while still developing in the javascript ecosystem try to use remote development servers and or change the editor the typescript lsp is notoriously bad in terms of stability and ram usage. one of the most common memes in it is the amount of restarting you have to do everytime you change a thing in the server folder to make sure that the types actually cascade correctly
kenny
kennyβ€’14mo ago
To the point where it crashes!? But I use typescript in my other projects and it runs fine
Dosha
Doshaβ€’14mo ago
it always crashes w me idk if this is really an issue or unique
kenny
kennyβ€’14mo ago
Ghmmm Disappointing I think something loops in my code But i can't find it. Started using T3 today.
Dosha
Doshaβ€’14mo ago
Maybe it's trpc related
luka
lukaβ€’14mo ago
eslint/typescript I would say
kenny
kennyβ€’14mo ago
the moment I run npm run dev in my project folder😭 awman it's like it start multiple node.js runtimes
kenny
kennyβ€’14mo ago
kenny
kennyβ€’14mo ago
check this out
kenny
kennyβ€’14mo ago
and why does it make multiple queries like this?
luka
lukaβ€’14mo ago
Next auth
kenny
kennyβ€’14mo ago
Why tho
chip
chipβ€’14mo ago
It stores the session in your db, therefore it has to always check if your session is valid and not expired.
kenny
kennyβ€’14mo ago
And db doesn't exist atm
chip
chipβ€’14mo ago
huh? Doesnt exist? As in "you haven't set up a db yet"?
kenny
kennyβ€’14mo ago
I had not now it does, but still eats all the ram
CaptainStarz
CaptainStarzβ€’14mo ago
How much ram do you have?
barry
barryβ€’14mo ago
something is telling me very little
elpupper
elpupperβ€’14mo ago
looks like 4gb
kenny
kennyβ€’14mo ago
πŸ˜’ 8gb ram I am now running the app in the vsCode terminal would ya look at this
kenny
kennyβ€’14mo ago
kenny
kennyβ€’14mo ago
warn - The server is running out of memory, restarting to free up memory.
error - Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
warn - The server is running out of memory, restarting to free up memory.
error - Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
Even playing GTA5 or Rocket League doesn't do this to my pc npx envinfo --system --binaries:
System:
OS: Windows 10 10.0.19044
CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Memory: 2.35 GB / 7.88 GB
Binaries:
Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD
System:
OS: Windows 10 10.0.19044
CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
Memory: 2.35 GB / 7.88 GB
Binaries:
Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD
kenny
kennyβ€’14mo ago
GitHub
bug: Running my T3 app takes up way too much RAM Β· Issue #1360 Β· t3...
Provide environment information System information: System: OS: Windows 10 10.0.19044 CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz Memory: 2.35 GB / 7.88 GB Binaries: Node: 18.15.0 - C:\Pr...
kenny
kennyβ€’14mo ago
I haven't thought about using turbopack cuz it's still in beta. But might that just resolve my issue??
nexxel
nexxelβ€’14mo ago
i don't think this is a bug my laptop slows down as well when i use next.js i have 8gb ram too
kenny
kennyβ€’14mo ago
Then it's a bug cuz somthing is happening that slows our machines down I can run my other nextjs apps with ease on localhost (Usually they're slow cuz I am not using TurboPack)
jdsl
jdslβ€’14mo ago
I don't think it's a bug with T3. Are you using the app directory? There are a few open issues on the latest next13 about memory.
nexxel
nexxelβ€’14mo ago
t3 will take more ram cause its more intensive on the tsserver
jdsl
jdslβ€’14mo ago
If not, chances are you have a lot of packages running and compiling in background during development mode. It starts to add up quickly with typescript and 3rd party packages.
kenny
kennyβ€’14mo ago
I am using pages bruh, How do we fix that
nexxel
nexxelβ€’14mo ago
you don't its javascript man
kenny
kennyβ€’14mo ago
; (
nexxel
nexxelβ€’14mo ago
not really known for being good at memory management
kenny
kennyβ€’14mo ago
package.json
{
"name": "",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.5",
"@prisma/client": "^4.11.0",
"@tanstack/react-query": "^4.28.0",
"@trpc/client": "^10.18.0",
"@trpc/next": "^10.18.0",
"@trpc/react-query": "^10.18.0",
"@trpc/server": "^10.18.0",
"next": "^13.2.4",
"next-auth": "^4.21.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@types/eslint": "^8.21.3",
"@types/node": "^18.15.5",
"@types/prettier": "^2.7.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.36.0",
"eslint-config-next": "^13.2.4",
"postcss": "^8.4.21",
"prettier": "^2.8.6",
"prettier-plugin-tailwindcss": "^0.2.6",
"prisma": "^4.11.0",
"tailwindcss": "^3.3.0",
"typescript": "^5.0.2"
},
"ct3aMetadata": {
"initVersion": "7.10.3"
}
}
{
"name": "",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"@next-auth/prisma-adapter": "^1.0.5",
"@prisma/client": "^4.11.0",
"@tanstack/react-query": "^4.28.0",
"@trpc/client": "^10.18.0",
"@trpc/next": "^10.18.0",
"@trpc/react-query": "^10.18.0",
"@trpc/server": "^10.18.0",
"next": "^13.2.4",
"next-auth": "^4.21.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "1.12.2",
"zod": "^3.21.4"
},
"devDependencies": {
"@types/eslint": "^8.21.3",
"@types/node": "^18.15.5",
"@types/prettier": "^2.7.2",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.36.0",
"eslint-config-next": "^13.2.4",
"postcss": "^8.4.21",
"prettier": "^2.8.6",
"prettier-plugin-tailwindcss": "^0.2.6",
"prisma": "^4.11.0",
"tailwindcss": "^3.3.0",
"typescript": "^5.0.2"
},
"ct3aMetadata": {
"initVersion": "7.10.3"
}
}
jdsl
jdslβ€’14mo ago
Is your terminal scrolling crazy amounts of stuff as you are working? Just checked the video.
barry
barryβ€’14mo ago
There's not much to do other than having more memory
Joey
Joeyβ€’14mo ago
It even freezes my aws micro ec2
kenny
kennyβ€’14mo ago
Could it be the trpc versions? Cuz I am working on another project thats also using trpc, But it doesnt become unresponsive like this one. It uses the following:
"@trpc/client": "^10.7.0",
"@trpc/next": "^10.7.0",
"@trpc/react-query": "^10.7.0",
"@trpc/server": "^10.7.0",
"@trpc/client": "^10.7.0",
"@trpc/next": "^10.7.0",
"@trpc/react-query": "^10.7.0",
"@trpc/server": "^10.7.0",
When it's running on localhost yeh my prisma db is running on planetscale
jdsl
jdslβ€’14mo ago
It looks like it's throwing a ton of errors in the terminal window in that video. If that's just happening over and over then there is something else going on
kenny
kennyβ€’14mo ago
I suspect that prisma too
jdsl
jdslβ€’14mo ago
No like the stuff it's streaming out is 100% not normal. Something is messed up on your codebase or vscode/windows setup. Also your db keys and nextauth keys are scrolling in that video. You should revoke and make new ones.
kenny
kennyβ€’14mo ago
🫣 missed that thx
jdsl
jdslβ€’14mo ago
It's definitely throwing errors and stuck in a loop or something. That needs to be figured out before you change anything else Dude
barry
barryβ€’14mo ago
Dud
jdsl
jdslβ€’14mo ago
jdsl
jdslβ€’14mo ago
Remove that console.log(ctx.prisma) That's gonna kill your machine I just went to pull down your repo and didn't see any console logs, so looked back at the video
luka
lukaβ€’14mo ago
Prisma is heavy too
jdsl
jdslβ€’14mo ago
Yeah I was curious how big that output would be. Logged it a single time to a file:
❯ ls -h test.log
231M Apr 15 04:27 test.log

❯ wc -l < test.log
176855
❯ ls -h test.log
231M Apr 15 04:27 test.log

❯ wc -l < test.log
176855
Sybatron
Sybatronβ€’14mo ago
Look around 4gibs And they opened 2 heavy ram eating browsers i guess vscode with lots of extensions and there goes the ram I guess it's time to optimize queries and the ways you debug πŸ˜… And other stuff if machine can't handle it at this stage Before continuing
elpupper
elpupperβ€’14mo ago
elpupper
elpupperβ€’14mo ago
my t3 app is almost finished and ive never seen it go about 2 gb
Sybatron
Sybatronβ€’14mo ago
From what i can see theirs is around 1.5Gibs But the CPU is being eaten for sure πŸ˜…
elpupper
elpupperβ€’14mo ago
not for me 2% when i go to admin dashboard it sky rockets to 10% then back down to 5 still 1.5 gb of mem
barry
barryβ€’14mo ago
so his cpu is banana poo
elpupper
elpupperβ€’14mo ago
prolly got a laptop at that point u should just look into using linux windows got too much bloat
elpupper
elpupperβ€’14mo ago
all i have is chrome vscode and discord open
Sybatron
Sybatronβ€’14mo ago
I mean they have 8 gibs ram i dont think its only win problem just old machine or low specs
elpupper
elpupperβ€’14mo ago
ya linux tho gonna buy you some time before u have to buy new pc/upgrade
kenny
kennyβ€’14mo ago
It didn't make a difference man It wasnt there before no I wanted to log prisma to check what it looks like. And I am no longer using the getAll query Look, when I develop I always have chrome, postman, powershell, etc open. I just never had this happen to me before. what are your device's specs I have an i5 you've gotta be kiddin well you have a lot of ram my point is a create-t3-app shouldn't take up that much ram. Not very developer friendly. So I can't run a t3 app on my machine. I'd rather look for alternatives. Cuz at this point runnig a t3 app take up more ram than playing GTA5+Rocket League
barry
barryβ€’14mo ago
i5 doesnt mean anything rly an i5 can be shit an i5 can also be good
kenny
kennyβ€’14mo ago
what does that mean πŸ˜† As long as I can play a game on high graphics its good.
barry
barryβ€’14mo ago
games are mainly using your gpu
kenny
kennyβ€’14mo ago
cpu too
barry
barryβ€’14mo ago
but yh sounds like a potato pc
kenny
kennyβ€’14mo ago
and ram I've never been dissed so much when asking for help xD Dayum. The weird things is. Now it doesn't take up that much RAM.
kenny
kennyβ€’14mo ago
What's going on here. Running the t3 app in windows powershell
Sybatron
Sybatronβ€’14mo ago
Did it cache something that's why it took less? Or some vs code extensions affect the ram?
kenny
kennyβ€’14mo ago
I have no idea It's this I think. Yeh you're right
jdsl
jdslβ€’14mo ago
Node will keep those long running processes too. Even if you quit everything, they will still be there for awhile if you remove the code and relaunch. Restart your computer or make sure you manually kill those processes. I use mac so I'm not sure how windows works. I would make sure you restart your computer fully today if you haven't in awhile.
kenny
kennyβ€’14mo ago
Will do. I'll continue with my project And marked this as solved if i don't run into anything similar.
jordanmckoy
jordanmckoyβ€’14mo ago
I do this, because my poor machine just throws a fit if I try to run even base next
elpupper
elpupperβ€’14mo ago
amd epyc 9654 32gb
kenny
kennyβ€’14mo ago
How do you
jordanmckoy
jordanmckoyβ€’14mo ago
Well I just happen to have a VPS that i have access to
kenny
kennyβ€’14mo ago
a machine like that would cost me an arm
elpupper
elpupperβ€’14mo ago
the gpus cost a leg then πŸ˜‚
jordanmckoy
jordanmckoyβ€’14mo ago
4 core arm cpu with 24gb of ram from oracle free tier
elpupper
elpupperβ€’14mo ago
in the windows vm tho i only use 10 cores
jordanmckoy
jordanmckoyβ€’14mo ago
I connect with it via ssh through vscodes server
kenny
kennyβ€’14mo ago
interesting
jordanmckoy
jordanmckoyβ€’14mo ago
Look up remote extension in vscode extension tab
elpupper
elpupperβ€’14mo ago
i suggest buying something like rasberrypi and deploying a test env there
kenny
kennyβ€’14mo ago
that sounds interesting How do I do that
elpupper
elpupperβ€’14mo ago
multiple ways u can do that you can setup git actions so that anytime you push a commit on the repo it automatically re-deploys but honestly at that point u could probably just use vercel or do what tropic is doing
kenny
kennyβ€’14mo ago
ah and then ssh to my server of choice?
jordanmckoy
jordanmckoyβ€’14mo ago
yerp
JacobMGEvans
JacobMGEvansβ€’14mo ago
Possibly No Not the definition of a software bug
kenny
kennyβ€’14mo ago
in my code what would you call it
elpupper
elpupperβ€’14mo ago
are u following a tutorial?
kenny
kennyβ€’14mo ago
I'm just working on a personal project.
JacobMGEvans
JacobMGEvansβ€’14mo ago
Its not the code which Nexxel explained several times at this point. Its a limitation of the tooling in JS and whatever your hardware is.
kenny
kennyβ€’14mo ago
Betitis