Skip to content

Commit

Permalink
dumps/serialize_to_writer: insert BufWriter to speed up serialization
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lschuermann committed Oct 20, 2024
1 parent d023aaa commit 38d0b0c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn serialize_to_writer_impl<T: Serialize, W: Write>(
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)
Expand Down

0 comments on commit 38d0b0c

Please sign in to comment.