Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants