Skip to content

fix(codspeed): changed benches to in-process diff benchmarks to fix codspeed - #433

Open
shadowmkj wants to merge 4 commits into
uutils:mainfrom
shadowmkj:fix/codspeed-benchmarks
Open

shadowmkj wants to merge 4 commits into
uutils:mainfrom
shadowmkj:fix/codspeed-benchmarks

Conversation

@shadowmkj

Copy link
Copy Markdown
Contributor

Summary

This update refactors the performance benchmark suite to execute diff operations in-process rather than via external command-line process calls. Additionally, it introduces codspeed conditional compilation flags to optimize and filter out external binary execution benchmarks during CI runner execution.

Resolves: #430

Key Changes

  • Refactored diffutils_diff benchmarks to use normal_diff::diff directly in-process with pre-loaded file contents.
  • Added #[cfg(not(codspeed))] attributes to conditionally disable external binary execution tests when running under CodSpeed. (It will still run locally)
  • Suppressed stdout and stderr outputs in binary process execution wrappers to eliminate I/O overhead skewing.
  • Configured unexpected_cfgs linter check for the codspeed configuration flag in Cargo.toml.

Verification & Testing

  • Run benchmarks locally to ensure correct execution: cargo bench --bench bench-diffutils
  • Verified compilation with the codspeed cfg flag enabled/disabled.****

@shadowmkj
shadowmkj marked this pull request as ready for review November 22, 2026 16:41
shadowmkj and others added 2 commits November 22, 2026 22:17
since Codspeed cannot trace syscalls into child processes spawned with `std::process::Command`, gate those benchmarks under #[cfg(not(codspeed))] so it still runs locally
@shadowmkj
shadowmkj force-pushed the fix/codspeed-benchmarks branch from ad54efc to 56995d6 Compare November 22, 2026 16:47
@codspeed

codspeed Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

Warning

uutils has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

1 warning

⚠️ 8 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks
🆕 6 new benchmarks
⏩ 16 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 diff_compare_files_different[100] N/A 103.4 ms N/A
🆕 diff_compare_files_different[1000] N/A 10.2 s N/A
🆕 diff_compare_files_equal[100] N/A 1.4 ms N/A
🆕 diff_compare_files_equal[1000] N/A 14.3 ms N/A
🆕 diff_compare_files_equal[10000] N/A 150.5 ms N/A
🆕 diff_compare_files_equal[25000] N/A 378.2 ms N/A

Comparing shadowmkj:fix/codspeed-benchmarks (9d6baad) with main (6f24ee8)

Open in CodSpeed

Footnotes

  1. 16 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@shadowmkj

shadowmkj commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Codspeed is failing due to high memory usage for files above [1000], (before the force-push, maximum of 1MB files was checked)

This is due to the quadratic memory usage of the naive LCS algorithm.

@shadowmkj

Copy link
Copy Markdown
Contributor Author
image

The memory usage while running locally is off the charts. Maybe we should only bench 1MB files maximum for now, and after resolution of #401 , memory usage will be linear, then we can test files upto 25MB

// use diffutilslib::params;
#[cfg(not(codspeed))]
use crate::binary;
use crate::{prepare::*, FILE_SIZE_KILO_BYTES, MB};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MB is not used in this module, it will warn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, forgot to remove this 😅


// bench the actual diff comparison in-process on differing files
#[divan::bench(args = FILE_SIZE_KILO_BYTES)]
fn diff_compare_files_different(bencher: Bencher, bytes: u64) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same code as diff_compare_files_equal, could be dedup with a small helper, no?

@shadowmkj

Copy link
Copy Markdown
Contributor Author

Also, what should we do about the large file tests? Keep it failing?

@shadowmkj
shadowmkj requested a review from sylvestre November 23, 2026 18:37
}

// bench the actual diff comparison in-process on identical files
#[divan::bench(args = FILE_SIZE_KILO_BYTES)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please limit these to [100, 1 * MB] for now, the 10/25 MB runs are what kill the codspeed job
we can go back to FILE_SIZE_KILO_BYTES once #401 is fixed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! Pushing a commit now

@shadowmkj

shadowmkj commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

I've pushed a commit to limit to 1MB maximum for diff_compare_files_different. I haven't changed it for diff_compare_files_equal because memory explosion doesn't happen for that bench. I've also added some comments for other devs to know why one bench does not use larger sizes. lmk if anything else is required

@shadowmkj
shadowmkj requested a review from sylvestre November 24, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: subprocess benchmarks (cmd_*) cause false regressions in CodSpeed simulation

2 participants