Skip to content

Use MallocShallowSizeOf for Brotli stream state - #48220

Merged
Taym95 merged 1 commit into
servo:mainfrom
Taym95:brotli-shallow-size-of
Sep 21, 2026
Merged

Taym95 merged 1 commit into
servo:mainfrom
Taym95:brotli-shallow-size-of

Conversation

@Taym95

@Taym95 Taym95 commented Sep 20, 2026

Copy link
Copy Markdown
Member

Use MallocShallowSizeOf to measure boxxed Brotli state in CompressionStream and DecompressionStream to avoid unsafe call.

Testing: No new tests are required because Box::shallow_size_of performs the identical allocator measurement

Fixes: Part of #30862

@Taym95
Taym95 requested a review from gterzian as a code owner September 20, 2026 12:51
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Sep 20, 2026
match self {
#[cfg(feature = "brotli-compression-stream")]
Encoder::Brotli(encoder) => unsafe { ops.malloc_size_of(&**encoder) },
Encoder::Brotli(encoder) => encoder.shallow_size_of(ops),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you not use

impl<T: MallocSizeOf> MallocSizeOf for Vec<T> {
on the vec by doing encoder.get_ref().size_of() or something similar?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah no nevermind, I see that now you are doing

impl<T> MallocShallowSizeOf for Vec<T> {
which is exactly the same as before, minus the unsafe.

match self {
#[cfg(feature = "brotli-compression-stream")]
Encoder::Brotli(encoder) => unsafe { ops.malloc_size_of(&**encoder) },
Encoder::Brotli(encoder) => encoder.shallow_size_of(ops),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah no nevermind, I see that now you are doing

impl<T> MallocShallowSizeOf for Vec<T> {
which is exactly the same as before, minus the unsafe.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Sep 21, 2026
@Taym95
Taym95 added this pull request to the merge queue Sep 21, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Sep 21, 2026
Merged via the queue into servo:main with commit c4f587d Sep 21, 2026
36 checks passed
@Taym95
Taym95 deleted the brotli-shallow-size-of branch September 21, 2026 08:26
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Sep 21, 2026
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
Use MallocShallowSizeOf to measure boxxed Brotli state in
CompressionStream and DecompressionStream to avoid unsafe call.

Testing: No new tests are required because Box<T>::shallow_size_of
performs the identical allocator measurement

Fixes: Part of servo#30862

Signed-off-by: Taym Haddadi <[email protected]>
hhhwsqhhh pushed a commit to hhhwsqhhh/servo that referenced this pull request Oct 12, 2026
Use MallocShallowSizeOf to measure boxxed Brotli state in
CompressionStream and DecompressionStream to avoid unsafe call.

Testing: No new tests are required because Box<T>::shallow_size_of
performs the identical allocator measurement

Fixes: Part of servo#30862

Signed-off-by: Taym Haddadi <[email protected]>
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.

3 participants