From 10c82e23e08a1d999594b987a31cbd57173444ef Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 24 Dec 2023 09:50:10 +0100 Subject: [PATCH] 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. --- gix-commitgraph/fuzz/Cargo.toml | 2 +- gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gix-commitgraph/fuzz/Cargo.toml b/gix-commitgraph/fuzz/Cargo.toml index 76fcd577e33..b15f90419ea 100644 --- a/gix-commitgraph/fuzz/Cargo.toml +++ b/gix-commitgraph/fuzz/Cargo.toml @@ -11,7 +11,7 @@ cargo-fuzz = true anyhow = "1.0.76" arbitrary = { version = "1.3.2", features = ["derive"] } libfuzzer-sys = "0.4" -tempfile = "3.8.1" +memmap2 = "0.9.0" [dependencies.gix-commitgraph] path = ".." diff --git a/gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs b/gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs index a2011233e0d..f6894f33bd0 100644 --- a/gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs +++ b/gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs @@ -1,17 +1,17 @@ #![no_main] use anyhow::Result; -use arbitrary::Arbitrary; use gix_commitgraph::File; use libfuzzer_sys::fuzz_target; -use std::fs; use std::hint::black_box; -use tempfile::NamedTempFile; fn fuzz(data: &[u8]) -> Result<()> { - let named_temp_file = NamedTempFile::new()?; - fs::write(named_temp_file.path(), data).expect("Unable to write fuzzed file"); - let file = File::try_from(named_temp_file.path())?; + let data = { + let mut d = memmap2::MmapMut::map_anon(data.len())?; + d.copy_from_slice(data); + d.make_read_only()? + }; + let file = File::new(data, "does not matter".into())?; _ = black_box(file.iter_base_graph_ids().count()); _ = black_box(file.iter_commits().count());