From 38d0b0c9d9e0f01221cc9d718421b87575389799 Mon Sep 17 00:00:00 2001 From: Leon Schuermann Date: Sun, 20 Oct 2024 18:52:06 -0400 Subject: [PATCH] dumps/serialize_to_writer: insert BufWriter to speed up serialization By buffering bincode's output prior to compression, we can achieve a ~30x speedup of syntect in debug builds (such as used in `cargo test`s by default) on a single `SyntaxSetBuilder::build()` call. For Tock's `license-checker` [1] crate using `syntect`, this brings overall test times down from ~75s to 4s on an i7-1360P. This change does not affect release builds much, bringing an individual test down from 0.17 to 0.13 seconds. [1]: https://github.com/tock/tock/tree/a109dd65fb269479ca4fa020af0a54da740eca28/tools/license-checker --- src/dumps.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dumps.rs b/src/dumps.rs index cb3be70..4751070 100644 --- a/src/dumps.rs +++ b/src/dumps.rs @@ -123,7 +123,7 @@ fn serialize_to_writer_impl( use_compression: bool, ) -> Result<()> { if use_compression { - let mut encoder = ZlibEncoder::new(output, Compression::best()); + let mut encoder = std::io::BufWriter::new(ZlibEncoder::new(output, Compression::best())); serialize_into(&mut encoder, to_dump) } else { serialize_into(output, to_dump)