Skip to content

Commit 10b4f9f

Browse files
committed
perf(oxfmt): make time measurement conditional (#16634)
## Summary - Make time measurement conditional based on output mode to reduce unnecessary overhead - `Instant::now()` is only called when using `--check` mode - Elapsed time calculation moved to only when it's actually displayed ## Test plan - [ ] Verify timing information still appears correctly in `--check` mode - [ ] Confirm no timing overhead in `--write` mode - [ ] Confirm no timing overhead in `--list-different` mode - [ ] Run `cargo check -p oxfmt` passes - [ ] Run `just fmt` completes successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 02f59ba commit 10b4f9f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

apps/oxfmt/src/cli/service.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl FormatService {
3535
tx_success: &mpsc::Sender<SuccessResult>,
3636
) {
3737
rx_entry.into_iter().par_bridge().for_each(|entry| {
38-
let start_time = Instant::now();
38+
let start_time = matches!(self.output_options, OutputOptions::Check).then(Instant::now);
3939

4040
let path = entry.path();
4141
let Ok(source_text) = utils::read_to_string(path) else {
@@ -72,8 +72,6 @@ impl FormatService {
7272
}
7373
};
7474

75-
let elapsed = start_time.elapsed();
76-
7775
// Write back if needed
7876
if matches!(self.output_options, OutputOptions::Write) && is_changed {
7977
fs::write(path, code)
@@ -92,9 +90,9 @@ impl FormatService {
9290
// Normalize path separators for consistent output across platforms
9391
.cow_replace('\\', "/")
9492
.to_string();
95-
let elapsed = elapsed.as_millis();
9693

9794
if matches!(self.output_options, OutputOptions::Check) {
95+
let elapsed = start_time.unwrap().elapsed().as_millis();
9896
SuccessResult::Changed(format!("{display_path} ({elapsed}ms)"))
9997
} else {
10098
SuccessResult::Changed(display_path)

0 commit comments

Comments
 (0)