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

fix: too many temporary allocation when serializing data #389

Closed
wants to merge 1 commit into from

Conversation

Totodore
Copy link
Owner

Motivation

When serializing packet, the initial buffer is a Vec<u8> which is then converted to a Bytes. Because len != cap when converting the buffer. A new allocation is made. Leading to a lot of temporary allocations.

Solution

Directly serialize to a BytesMut writer.

@Totodore Totodore force-pushed the fix-temp-alloc-parser branch from 20a6c47 to c86f0e6 Compare October 27, 2024 17:52
@@ -1,7 +1,7 @@
//! This module contains a specialized JSON serializer wrapper that can serialize binary payloads as placeholders.
use std::{cell::UnsafeCell, collections::VecDeque};

use bytes::Bytes;
use bytes::{BufMut, Bytes, BytesMut};

Check warning

Code scanning / clippy

unused imports: BufMut and BytesMut Warning

unused imports: BufMut and BytesMut
@@ -1,7 +1,7 @@
//! This module contains a specialized JSON serializer wrapper that can serialize binary payloads as placeholders.
use std::{cell::UnsafeCell, collections::VecDeque};

use bytes::Bytes;
use bytes::{BufMut, Bytes, BytesMut};

Check warning

Code scanning / clippy

unused imports: BufMut and BytesMut Warning

unused imports: BufMut and BytesMut
@@ -1,7 +1,7 @@
//! This module contains a specialized JSON serializer wrapper that can serialize binary payloads as placeholders.
use std::{cell::UnsafeCell, collections::VecDeque};

use bytes::Bytes;
use bytes::{BufMut, Bytes, BytesMut};

Check warning

Code scanning / clippy

unused imports: BufMut and BytesMut Warning

unused imports: BufMut and BytesMut
@@ -1,7 +1,7 @@
//! This module contains a specialized JSON serializer wrapper that can serialize binary payloads as placeholders.
use std::{cell::UnsafeCell, collections::VecDeque};

use bytes::Bytes;
use bytes::{BufMut, Bytes, BytesMut};

Check warning

Code scanning / clippy

unused imports: BufMut and BytesMut Warning

unused imports: BufMut and BytesMut
@Totodore Totodore force-pushed the fix-temp-alloc-parser branch from c86f0e6 to d193e86 Compare October 27, 2024 17:59
@Totodore Totodore closed this Oct 27, 2024
@Totodore Totodore deleted the fix-temp-alloc-parser branch October 27, 2024 18:30
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.

1 participant