1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Size proxies for the coalescer's batch packing.
//!
//! Plays no role in correctness — rustfmt produces the same output
//! regardless of which strategy we pick. Only the *relative* magnitudes
//! between crates matter, since the coalescer uses size_bytes to balance
//! batches. Strategies trade discovery cost for accuracy.
use Path;
/// Cap above which a crate is unambiguously a "giant" for solo
/// dispatch. We only need a binary classifier here — the priority queue
/// orders giants relative to each other by their (clamped) size, and
/// since they all clamp to the same value the dispatch order between
/// giants is unspecified, which is fine: any giant landing in an empty
/// queue takes off first regardless.
pub const HUGE_CUTOFF_BYTES: u64 = 1_000_000;
/// Active size proxy. Walks the crate's `*.rs` files but stops as soon
/// as accumulated bytes hit `HUGE_CUTOFF_BYTES`, returning the cutoff
/// verbatim. So tiny crates pay full walk cost (which is tiny because
/// they have few files), and giants pay only as much as it takes to
/// classify them — typically tens of files instead of thousands. Files
/// stat'd here end up in the page cache for rustfmt's own reads, so
/// the I/O is recouped downstream.
pub
/// Sum of bytes of every `*.rs` file under `manifest_dir`, skipping
/// `target/`. Closer to what rustfmt actually parses (it walks `mod`
/// declarations from entry points and reads the same files we'd
/// enumerate here, modulo `#[path]` and excluded modules). Costs one
/// walkdir per crate during discovery — for 580 crates with ~10 files
/// each, on the order of 50ms total.
pub
/// Sum of `*.rs` bytes under `manifest_dir`, returning early once the
/// running total reaches `cap` (returning `cap`). Skips `target/` and
/// non-files. Lets us stop walking after a crate is classified as
/// giant, instead of fully enumerating multi-MB trees we'll only use
/// for one bit of "is this huge?" information.
pub