Skip to content

Commit

Permalink
Let commitgraph fuzzer use the latest API
Browse files Browse the repository at this point in the history
This increases performance by 4x while reducing kernel load to not being
present at all, down from 90%/nearly 1 CPU.
  • Loading branch information
Byron committed Dec 24, 2023
1 parent e2f9448 commit 10c82e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gix-commitgraph/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ".."
Expand Down
12 changes: 6 additions & 6 deletions gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand Down

0 comments on commit 10c82e2

Please sign in to comment.