Skip to content

Commit 672294e

Browse files
committed
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.
1 parent 8613c41 commit 672294e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

gix-commitgraph/fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cargo-fuzz = true
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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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());

0 commit comments

Comments
 (0)