Skip to content

perf: optimize buffer handling and fragment gecoding#128

Open
ppmpreetham wants to merge 2 commits into
denoland:mainfrom
ppmpreetham:main
Open

perf: optimize buffer handling and fragment gecoding#128
ppmpreetham wants to merge 2 commits into
denoland:mainfrom
ppmpreetham:main

Conversation

@ppmpreetham

Copy link
Copy Markdown

Improves memory efficiency and reduces CPU overhead in the WebSocket writing and fragment processing logic. Shifted to ownership transfers and in-place mutations and reduced the number of heap allocations and eliminate unnecessary buffer zero-initializations.

Operation Before this PR After this PR
Write Header Allocation + Zero-init + Copy Allocation + Copy
Decode Text $O(n)$ Copy to new Vec $O(1)$ Ownership transfer / Truncate

avoids zero-filling the vec when resizing and simplifies the write logic.
@ppmpreetham

Copy link
Copy Markdown
Author

@littledivy , could you please check this?

@divybot

divybot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Maintenance scan note: since this is a performance PR, it needs reproducible benchmark evidence before it is reviewable. Please add the exact commands, environment, and raw before/after numbers for the src/frame.rs write path and fragmented text path.

A small regression/perf test around fragmented text frames would also help pin that the ownership-transfer change preserves the partial UTF-8 behavior from #123. The code diff is small, but without raw numbers it is hard to tell whether the extra temporary header buffer in Frame::write is a net win across payload sizes.

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.

2 participants