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β€’2y 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β€’2y ago
its typescript what do you expect loll javascript is always very heavy on ram
Dosha
Doshaβ€’2y 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β€’2y ago
To the point where it crashes!? But I use typescript in my other projects and it runs fine
Dosha
Doshaβ€’2y ago
it always crashes w me idk if this is really an issue or unique
kenny
kennyβ€’2y ago
Ghmmm Disappointing I think something loops in my code But i can't find it. Started using T3 today.
Dosha
Doshaβ€’2y ago
Maybe it's trpc related
l
lβ€’2y ago
eslint/typescript I would say
kenny
kennyβ€’2y ago
the moment I run npm run dev in my project folder😭 awman it's like it start multiple node.js runtimes
kenny
kennyβ€’2y ago
kenny
kennyβ€’2y ago
check this out
kenny
kennyβ€’2y ago
and why does it make multiple queries like this?
l
lβ€’2y ago
Next auth
kenny
kennyβ€’2y ago
Why tho
chip
chipβ€’2y ago
It stores the session in your db, therefore it has to always check if your session is valid and not expired.
kenny
kennyβ€’2y ago
And db doesn't exist atm
chip
chipβ€’2y ago
huh? Doesnt exist? As in "you haven't set up a db yet"?
kenny
kennyβ€’2y ago
I had not now it does, but still eats all the ram
CaptainStarz
CaptainStarzβ€’2y ago
How much ram do you have?
barry
barryβ€’2y ago
something is telling me very little
elpupper
elpupperβ€’2y ago
looks like 4gb
kenny
kennyβ€’2y ago
πŸ˜’ 8gb ram I am now running the app in the vsCode terminal would ya look at this
kenny
kennyβ€’2y ago
kenny
kennyβ€’2y 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β€’2y 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β€’2y ago
I haven't thought about using turbopack cuz it's still in beta. But might that just resolve my issue??
nexxel
nexxelβ€’2y 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β€’2y 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β€’2y 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β€’2y ago
t3 will take more ram cause its more intensive on the tsserver
jdsl
jdslβ€’2y 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β€’2y ago
I am using pages bruh, How do we fix that
nexxel
nexxelβ€’2y ago
you don't its javascript man
kenny
kennyβ€’2y ago
; (
nexxel
nexxelβ€’2y ago
not really known for being good at memory management
kenny
kennyβ€’2y 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β€’2y ago
Is your terminal scrolling crazy amounts of stuff as you are working? Just checked the video.
barry
barryβ€’2y ago
There's not much to do other than having more memory
Joey
Joeyβ€’2y ago
It even freezes my aws micro ec2
kenny
kennyβ€’2y 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β€’2y 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β€’2y ago
I suspect that prisma too
jdsl
jdslβ€’2y 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β€’2y ago
🫣 missed that thx
jdsl
jdslβ€’2y 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β€’2y ago
Dud
jdsl
jdslβ€’2y ago
jdsl
jdslβ€’2y 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
l
lβ€’2y ago
Prisma is heavy too
jdsl
jdslβ€’2y 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β€’2y 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β€’2y ago
elpupper
elpupperβ€’2y ago
my t3 app is almost finished and ive never seen it go about 2 gb
Sybatron
Sybatronβ€’2y ago
From what i can see theirs is around 1.5Gibs But the CPU is being eaten for sure πŸ˜…
elpupper
elpupperβ€’2y 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β€’2y ago
so his cpu is banana poo
elpupper
elpupperβ€’2y ago
prolly got a laptop at that point u should just look into using linux windows got too much bloat
elpupper
elpupperβ€’2y ago
all i have is chrome vscode and discord open
Sybatron
Sybatronβ€’2y ago
I mean they have 8 gibs ram i dont think its only win problem just old machine or low specs
elpupper
elpupperβ€’2y ago
ya linux tho gonna buy you some time before u have to buy new pc/upgrade
kenny
kennyβ€’2y 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β€’2y ago
i5 doesnt mean anything rly an i5 can be shit an i5 can also be good
kenny
kennyβ€’2y ago
what does that mean πŸ˜† As long as I can play a game on high graphics its good.
barry
barryβ€’2y ago
games are mainly using your gpu
kenny
kennyβ€’2y ago
cpu too
barry
barryβ€’2y ago
but yh sounds like a potato pc
kenny
kennyβ€’2y 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β€’2y ago
What's going on here. Running the t3 app in windows powershell
Sybatron
Sybatronβ€’2y ago
Did it cache something that's why it took less? Or some vs code extensions affect the ram?
kenny
kennyβ€’2y ago
I have no idea It's this I think. Yeh you're right
jdsl
jdslβ€’2y 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β€’2y ago
Will do. I'll continue with my project And marked this as solved if i don't run into anything similar.
tropic
tropicβ€’2y ago
I do this, because my poor machine just throws a fit if I try to run even base next
elpupper
elpupperβ€’2y ago
amd epyc 9654 32gb
kenny
kennyβ€’2y ago
How do you
tropic
tropicβ€’2y ago
Well I just happen to have a VPS that i have access to
kenny
kennyβ€’2y ago
a machine like that would cost me an arm
elpupper
elpupperβ€’2y ago
the gpus cost a leg then πŸ˜‚
tropic
tropicβ€’2y ago
4 core arm cpu with 24gb of ram from oracle free tier
elpupper
elpupperβ€’2y ago
in the windows vm tho i only use 10 cores
tropic
tropicβ€’2y ago
I connect with it via ssh through vscodes server
kenny
kennyβ€’2y ago
interesting
tropic
tropicβ€’2y ago
Look up remote extension in vscode extension tab
elpupper
elpupperβ€’2y ago
i suggest buying something like rasberrypi and deploying a test env there
kenny
kennyβ€’2y ago
that sounds interesting How do I do that
elpupper
elpupperβ€’2y 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β€’2y ago
ah and then ssh to my server of choice?
tropic
tropicβ€’2y ago
yerp
JacobMGEvans
JacobMGEvansβ€’2y ago
Possibly No Not the definition of a software bug
kenny
kennyβ€’2y ago
in my code what would you call it
elpupper
elpupperβ€’2y ago
are u following a tutorial?
kenny
kennyβ€’2y ago
I'm just working on a personal project.
JacobMGEvans
JacobMGEvansβ€’2y 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β€’2y ago
Betitis
Want results from more Discord servers?
Add your server