Speed up tidy again - #161201
Speed up tidy again#161201the8472 wants to merge 4 commits into
Conversation
we run it in dev mode by default, so this shaves off a few millis at runtime
this saves ~100ms
|
The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging. cc @davidtwco, @BoxyUwU |
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Thank you! Left some comments.
I don't love implementing our own synchronization primitives in tidy, even if they are supposedly simple 😆 I wonder, what do you think about piggybacking upon higher-level sync primitives (a channel) instead?
pub struct Semaphore {
tx: std::sync::mpsc::SyncSender<()>,
rx: std::sync::Mutex<std::sync::mpsc::Receiver<()>>,
}
impl Semaphore {
pub fn new(count: NonZeroUsize) -> Self {
let (tx, rx) = std::sync::mpsc::sync_channel(count.into());
for _ in 0..count.into() {
tx.send(()).unwrap();
}
Self { tx, rx: std::sync::Mutex::new(rx) }
}
pub fn acquire(&self) -> Guard<'_> {
let _token = self.rx.lock().unwrap().recv().expect("Cannot read token");
Guard { _sem: self, tx: self.tx.clone() }
}
}
pub struct Guard<'a> {
_sem: &'a Semaphore,
tx: std::sync::mpsc::SyncSender<()>,
}
impl Drop for Guard<'_> {
fn drop(&mut self) {
// Return the token back
self.tx.send(()).unwrap();
}
}| # dependencies, only bootstrap itself. | ||
| [profile.dev] | ||
| debug = 0 | ||
| debug-assertions = false |
There was a problem hiding this comment.
Is this really measurable? Debug asserts could in theory help find some overflows or similar things. I don't think that we should trade this off.
There was a problem hiding this comment.
The asserts showed up in profiles but I haven't measured the change in isolation, will do.
The thing is that we run bootstrap in dev as if it were our release profile... would adding a test profile which reenables them be sufficient?
There was a problem hiding this comment.
Well we only do that because of compile times, nothing else, really. I guess that we could only use assertions on CI, but I'd like to see if the assertions really make that much of a difference.
| } | ||
|
|
||
| #[track_caller] | ||
| pub fn start(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> DeferredCommand<'_> { |
There was a problem hiding this comment.
There is already the same function called start_capture. I think that you don't want to capture here, though? 🤔
| if has_missing_submodule(root, submodules, tidy_ctx.is_running_on_ci()) { | ||
| continue; | ||
| } | ||
| thread::scope(|s| { |
There was a problem hiding this comment.
Why does this create a new scope when one scope is already passed in?
There was a problem hiding this comment.
Some leftover from trying different approaches. I'll remove either the local scope or the passed argument.
| { | ||
| let check = ✓ | ||
| let checked_runtime_licenses = &checked_runtime_licenses; | ||
| let guard = if i > 0 { Some(sem.acquire()) } else { None }; |
There was a problem hiding this comment.
Why is the semaphore not acquired for the first workspace?
There was a problem hiding this comment.
If concurrency==1 then that would hang because the deps module itself already takes up one task slot.
There was a problem hiding this comment.
I see, then please add this as a comment on top of this line.
|
Btw, when I run tidy several times in a row, with the disk cache primed, on |
|
@rustbot author |
Tidy has slowed down quite a bit over the years (#81833, #105829), so let's recover some perf
After this about half of the remaining time is burned by bootstrap doing git and cargo stuff.
Fixes: #141074
LLM disclosure: I used copilot's autocomplete. Most suggestions were trivial (or discarded for being incorrect), with the exception of the Semaphore type which it produced almost wholesale. I compared it to implementations in the wild and they look almost identical, so I hope this too falls under "trivial".