fix(criterion-compat): fix URI formatting when criterion_group!/criterion_main! are bypassed#169
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes CodSpeed Criterion-compat benchmark URI construction when users bypass criterion_group! / criterion_main! (e.g., custom main), ensuring URIs don’t include empty segments and that current_file is derived from the callsite when missing.
Changes:
- Build benchmark URIs from non-empty components (file / macro group / group name / function) to avoid malformed
::sequences. - Derive
current_filefrom#[track_caller]callsite whencriterion_group!didn’t set it. - Add a new bench reproducer for the “custom main” scenario and register it in
Cargo.toml.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/criterion_compat/src/compat/group.rs | Makes URI formatting robust to missing file and/or macro group components. |
| crates/criterion_compat/src/compat/criterion.rs | Adds callsite-based fallback to populate current_file when macros aren’t used. |
| crates/criterion_compat/benches/repro_custom_main.rs | Adds a reproducer bench for bypassing criterion_group!/criterion_main!. |
| crates/criterion_compat/Cargo.toml | Registers the new repro_custom_main bench target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | find_highest_set_bit[255] |
5 ns | 47 ns | -89.36% |
| ❌ | WallTime | bench_array2[1] |
1 ns | 2 ns | -50% |
| ❌ | Simulation | fibo_10 |
90 ns | 119.2 ns | -24.48% |
| ❌ | Simulation | add |
91.4 ns | 120.6 ns | -24.19% |
| ❌ | Simulation | mul |
91.4 ns | 120.6 ns | -24.19% |
| ❌ | Simulation | find_highest_set_bit[42] |
122.2 ns | 151.4 ns | -19.27% |
| ❌ | Simulation | find_highest_set_bit[1024] |
122.2 ns | 151.4 ns | -19.27% |
| ❌ | Simulation | find_highest_set_bit[255] |
122.2 ns | 151.4 ns | -19.27% |
| ❌ | Simulation | find_highest_set_bit[65535] |
122.2 ns | 151.4 ns | -19.27% |
| ❌ | WallTime | iter_batched_per_iteration |
46 ns | 56 ns | -17.86% |
| ❌ | WallTime | iter_batched_ref_large_input |
5 ns | 6 ns | -16.67% |
| ❌ | WallTime | iter_with_setup |
45 ns | 54 ns | -16.67% |
| ❌ | WallTime | iter_batched_large_input |
7 ns | 8 ns | -12.5% |
| ❌ | Simulation | iter_manual_simple |
536.9 ns | 566.1 ns | -5.15% |
| ❌ | Simulation | uppercase_chars_with_counter |
2.1 µs | 2.2 µs | -4.03% |
| ❌ | Simulation | process_items_with_counter |
835.8 ns | 865 ns | -3.37% |
| ⚡ | WallTime | hamiltonian_cycle[5] |
1,439 ns | 902 ns | +59.53% |
| ⚡ | WallTime | vec_copy_with_bytes_counter |
57 ns | 36 ns | +58.33% |
| ⚡ | WallTime | count_set_bits[0] |
11 ns | 7 ns | +57.14% |
| ⚡ | WallTime | string_processing_multi_counter |
574 ns | 370 ns | +55.14% |
| ... | ... | ... | ... | ... | ... |
ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing cod-2324-investigate-issues-with-uri-formatting-in-codspeed-criterion (ec46807) with main (99c7b5a)
74da3b2 to
3fddbb2
Compare
oh wait, that's the one i wanted to fix. i'll have a look |
3fddbb2 to
be00bcf
Compare
Greptile SummaryFixes malformed URIs like
Confidence Score: 5/5Safe to merge — the change is a targeted bug fix with no breaking API surface and a clearly scoped impact limited to URI generation when the standard macros are bypassed. Both code paths (compat layer and criterion fork) are updated consistently, the fix is guarded by an idempotent early-return in No files require special attention. Important Files Changed
|
be00bcf to
8c539a3
Compare
…bypassed When users define a custom main instead of criterion_group!/criterion_main!, current_file and macro_group are never set, producing URIs with empty segments like `::::my_group::my_bench`. Derive current_file from the caller location (track_caller) when the macro did not set it, keeping it inside Criterion, and join URI segments with a shared build_uri helper that skips empty parts so the fork and compat implementations stay in sync.
Covers calling bench functions directly with a custom main, both with and without going through a criterion_group!-generated function.
8c539a3 to
ec46807
Compare

No description provided.