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

Question: how to make swc-node to use less memory #730

Open
erfanium opened this issue Sep 6, 2023 · 3 comments
Open

Question: how to make swc-node to use less memory #730

erfanium opened this issue Sep 6, 2023 · 3 comments

Comments

@erfanium
Copy link

erfanium commented Sep 6, 2023

I use @swc-node to run TypeScript backend in production. because i don't like to add a build step to my workflow, on-the-fly transpilation just makes life easier

everything works fine, but the extra memory usage caused by swc is a downside to me.

to reproduce:

import { memoryUsage } from "node:process";

setInterval(() => {
  console.log(memoryUsage());
}, 2000);

node main.js: rss: 45MB, heapTotal: 6MB, heapUsed: 6MB, external: 421KB, arrayBuffers: 18KB
deno main.ts: rss: 52MB, heapTotal: 11MB, heapUsed: 10MB, external: 76KB, arrayBuffers: 0
node -r @swc-node/register main.ts: rss: 102MB, heapTotal: 30MB, heapUsed: 23MB, external: 592KB, arrayBuffers: 57KB

There is a huge gap here. I was able to 60% reduce one of my project rss, just by compiling the source code before runtime.

I wonder is there anyway to consume less memory for production usage? maybe unload/free the swc compiler after a while during runtime.

I can work on a PR, but i have no idea to start

@Brooooooklyn
Copy link
Member

Don't use register in production, it's for development usage

@erfanium
Copy link
Author

erfanium commented Sep 7, 2023

@Brooooooklyn
well there is a similar threads in ts-node: TypeStrong/ts-node#104 i can reference. that's an old debate

Many are using ts-node in production, so maybe it's better to create this module not only for development usage

@yeliex
Copy link
Contributor

yeliex commented Mar 4, 2024

You can use it in production for free, but it is not recommended. and I guess it would never be officially supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants