From 1700bcfd04c7960d4207b8183bfdd752f4b0ce9c Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 22 Sep 2022 11:49:58 -0400 Subject: [PATCH] Box the `BrotliState` value because it is very large This reduces the size of `BrotliDecoder` from 2592 bytes to 8 bytes. Fixes #172 --- src/codec/brotli/decoder.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/codec/brotli/decoder.rs b/src/codec/brotli/decoder.rs index 0eeab3f..648f173 100644 --- a/src/codec/brotli/decoder.rs +++ b/src/codec/brotli/decoder.rs @@ -7,17 +7,18 @@ use std::{ use brotli::{enc::StandardAlloc, BrotliDecompressStream, BrotliResult, BrotliState}; pub struct BrotliDecoder { - state: BrotliState, + // `BrotliState` is very large (over 2kb) which is why we're boxing it. + state: Box>, } impl BrotliDecoder { pub(crate) fn new() -> Self { Self { - state: BrotliState::new( + state: Box::new(BrotliState::new( StandardAlloc::default(), StandardAlloc::default(), StandardAlloc::default(), - ), + )), } } @@ -57,11 +58,11 @@ impl BrotliDecoder { impl Decode for BrotliDecoder { fn reinit(&mut self) -> Result<()> { - self.state = BrotliState::new( + self.state = Box::new(BrotliState::new( StandardAlloc::default(), StandardAlloc::default(), StandardAlloc::default(), - ); + )); Ok(()) }