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

websocket: reduce memory usage #3393

Merged
merged 1 commit into from
Jul 6, 2024

Conversation

tsctx
Copy link
Member

@tsctx tsctx commented Jul 6, 2024

> $ node memory.js // before
memoryUsage: 104Kib
> $ node memory.js // after
memoryUsage: 68Kib
const socket = new WebSocket("ws://localhost:5001")

socket.onopen = function () {
    const rss = process.memoryUsage.rss()
    socket.send("hi")
    socket.onmessage = function () {
        console.log(`memoryUsage: ${(process.memoryUsage.rss() - rss) / 1024}Kib`)
        socket.close()
    }
}

Refs: websockets/ws@ddfe4a8

@tsctx
Copy link
Member Author

tsctx commented Jul 6, 2024

It is effective because it can greatly reduce memory at the same performance.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@KhafraDev KhafraDev merged commit 64cd7a9 into nodejs:main Jul 6, 2024
31 checks passed
@tsctx tsctx deleted the websocket/reduce-memory-usage branch July 6, 2024 20:44
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

3 participants