History

Let commitgraph fuzzer use the latest API

This increases performance by 4x while reducing kernel load to not being present at all, down from 90%/nearly 1 CPU.

Sebastian Thiel committed 2 years ago

Commit 672294e1 parent 8613c412 files · +7 −7Browse files

Unified · Split

2 files
  1. gix-commitgraph/fuzz/Cargo.toml +1 −1
  2. gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs +6 −6
gix-commitgraph/fuzz/Cargo.toml+1−1
@@ -11,7 +11,7 @@ cargo-fuzz = true · 10 unmodified lines
1111 anyhow = "1.0.76"
1212 arbitrary = { version = "1.3.2", features = ["derive"] }
1313 libfuzzer-sys = "0.4"
14−tempfile = "3.8.1"
14+memmap2 = "0.9.0"
1515
1616 [dependencies.gix-commitgraph]
1717 path = ".."
gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs+6−6
@@ -1,17 +1,17 @@
11 #![no_main]
22
33 use anyhow::Result;
4−use arbitrary::Arbitrary;
54 use gix_commitgraph::File;
65 use libfuzzer_sys::fuzz_target;
7−use std::fs;
86 use std::hint::black_box;
9−use tempfile::NamedTempFile;
107
118 fn fuzz(data: &[u8]) -> Result<()> {
12− let named_temp_file = NamedTempFile::new()?;
13− fs::write(named_temp_file.path(), data).expect("Unable to write fuzzed file");
14− let file = File::try_from(named_temp_file.path())?;
9+ let data = {
10+ let mut d = memmap2::MmapMut::map_anon(data.len())?;
11+ d.copy_from_slice(data);
12+ d.make_read_only()?
13+ };
14+ let file = File::new(data, "does not matter".into())?;
1515
1616 _ = black_box(file.iter_base_graph_ids().count());
1717 _ = black_box(file.iter_commits().count());