Skip to content

Commit 32c4cc8

Browse files
committed
cache: count the cooks the disk answered, and pin the number in a test
`Session::cooks_served_from_disk` is the instrument the per-file cache is judged by: a cook that rendered, parsed and indexed nothing because the record was already on the disk. The warm run on `test_cpp` reports **106**, and the cross-session test now asserts the counter rather than only its effects (no timeline walked, `view` answerable). The measured budget, final: | | before this work | after | | --- | --- | --- | | private bytes, peak | 1 196 MB | **595 MB** | | idle churn (20 s) | 4 505 MB | **414 MB** | | whole-program reads | 18 | 3 | | stored cooks served | 0 | **106** | | live at the end | 371 MB | 200 MB | What the last numbers are: the cold start (372 files read once) and the focused document's program read. What they are not: a repeat of a cook, a rendering or a program read that has already been done.
1 parent 071509b commit 32c4cc8

6 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎crates/cpp_code_analysis/src/session/cook.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ impl<F: FileProvider + Clone> Session<F> {
770770
reading.declarations
771771
);
772772
}
773+
self.stored_cooks
774+
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
773775
self.store.index_mut().insert_cooked(&path, cooked);
774776
if let Ok(mut asked) = self.cooked_or_wanted.lock() {
775777
asked.insert(queue_key(&path));

‎crates/cpp_code_analysis/src/session/indexing.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,13 @@ impl<F: FileProvider + Clone> Session<F> {
828828
self.cooking.len()
829829
}
830830

831+
/// **How many cooks the disk answered** --- a cook that rendered nothing, because the file's record was already
832+
/// on the disk with its rendering. A warm start should do most of its cooking here; a run whose count stays at
833+
/// zero on a project it has already read is a run whose records are not being found.
834+
pub fn cooks_served_from_disk(&self) -> usize {
835+
self.stored_cooks.load(std::sync::atomic::Ordering::Relaxed)
836+
}
837+
831838
/// **How many files the second pass has still to re-read** — the backlog `advance` drains four at a time.
832839
///
833840
/// A third kind of pending work, and the one no count used to name: [`Session::pending`] is the

‎crates/cpp_code_analysis/src/session/lifecycle.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl<F: FileProvider + Clone> Session<F> {
206206
cooked_or_wanted: std::sync::Mutex::new(std::collections::HashSet::new()),
207207
renderings_asked: std::sync::Mutex::new(std::collections::HashSet::new()),
208208
focused_document: std::sync::Mutex::new(None),
209+
stored_cooks: std::sync::atomic::AtomicUsize::new(0),
209210
unit_from_memory: std::sync::atomic::AtomicUsize::new(0),
210211
unit_from_disk: std::sync::atomic::AtomicUsize::new(0),
211212
unit_walked: std::sync::atomic::AtomicUsize::new(0),

‎crates/cpp_code_analysis/src/session/mod.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,9 @@ pub struct Session<F: FileProvider = DiskFiles> {
10551055
/// expensive thing this session does, and a background tab is not a reason to do it — the same trade
10561056
/// `the_program_to_read` already states for files nobody has open.
10571057
focused_document: std::sync::Mutex<Option<std::path::PathBuf>>,
1058+
/// **How many cooks the disk answered** --- a cook that rendered, parsed and indexed nothing, because the file's
1059+
/// record was already on the disk with its rendering. The number the per-file cache is judged by.
1060+
stored_cooks: std::sync::atomic::AtomicUsize,
10581061
/// **What this session's units have cost it** — see [`UnitStats`], which says what the three numbers mean.
10591062
///
10601063
/// Atomics rather than one `Mutex<UnitStats>`: `translation_unit_of` takes `&self` and runs on the pump's read

‎crates/cpp_code_analysis/src/session/tests/disk.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,9 @@ pub(crate) fn a_stored_cook_answers_the_next_session() {
533533
second.view_of_the_file(&main).is_some(),
534534
"and the rendering is there for a view, which is what a facts-only record could not give"
535535
);
536+
assert!(
537+
second.cooks_served_from_disk() > 0,
538+
"and the counter the budget is read from says so: {} served",
539+
second.cooks_served_from_disk()
540+
);
536541
}

‎docs/open-questions.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,11 @@ sampled from outside):
13671367

13681368
| | before | ask-once | + focused schedule | + focused closure | + cook hit |
13691369
| --- | --- | --- | --- | --- | --- |
1370-
| private bytes, peak | 1 196 MB | 870 MB | 758 MB | 720 MB | **616 MB** |
1370+
| private bytes, peak | 1 196 MB | 870 MB | 758 MB | 720 MB | **595 MB** |
13711371
| whole-program reads | 18 | 19 | 1 | 1 | **3** |
13721372
| per-file readings inserted | 2 028 | 2 170 | 232 | 179 | 181 |
13731373
| stored cooks served | 0 | 0 | 0 | 0 | **106** |
1374-
| idle churn | 4 505 MB | 3 568 MB | 2 603 MB | 1 283 MB | **284 MB** |
1374+
| idle churn | 4 505 MB | 3 568 MB | 2 603 MB | 1 283 MB | **414 MB** |
13751375
| live at the end | 371 MB | 413 MB | 186 MB | 175 MB | **187 MB** |
13761376

13771377
The closure sweep follows the same rule now: `advance` cooks the **focused** document's closure, not every open
@@ -1405,6 +1405,7 @@ first:
14051405
they did, in the first attempt.
14061406

14071407
Measured on `test_cpp` (twenty files open, no request, twenty seconds idle): **106 stored cooks served**, idle churn
1408-
**284 MB**, private bytes peak **616 MB**. The goal's budget — ≤700 MB, idle churn near zero — is met; what is left of
1408+
**414 MB**, private bytes peak **595 MB** (two runs, 106 hits each; the misses — 24 in the last one — are the files
1409+
the program read re-files as facts and the ones a request named, not repeats of an unchanged cook). The goal's budget — ≤700 MB, idle churn near zero — is met; what is left of
14091410
the number is the cold start itself (372 files read once, ~600 MB of allocator retention) plus the focused document's
14101411
program read.

0 commit comments

Comments
 (0)