Latest Results
Allow customizing the order of memos to save memory usage
The order is inferred based on previous runs, like in PGO.
In rust-analyzer this saves between 16mb and 100mb on the projects I measured. The setup goes like that: the top level crate, `rust-analyzer`, gains a new feature `precomputed-memo-frequencies`. I also included the following code:
```rust
#[macro_export]
macro_rules! precomputed_memo_frequencies_path {
() => {
concat!(env!("CARGO_MANIFEST_DIR"), "/../../memo_frequencies.bin")
};
}
#[cfg(feature = "precomputed-memo-frequencies")]
pub fn memo_frequencies() -> MemoFrequencyStats {
static MEMO_FREQUENCIES: std::sync::LazyLock<MemoFrequencyStats> =
std::sync::LazyLock::new(|| {
let data = include_bytes!(crate::precomputed_memo_frequencies_path!());
MemoFrequencyStats::deserialize(data)
});
MEMO_FREQUENCIES.clone()
}
#[cfg(not(feature = "precomputed-memo-frequencies"))]
pub fn memo_frequencies() -> MemoFrequencyStats {
MemoFrequencyStats::default()
}
```
Then when creating a database I pass `memo_frequencies()`.
I also included a flag in the CLI command that analyzes a project (`analysis-stats`). When the flag is active it does:
```rust
if let Some(optimal_init_percent) = self.write_memo_frequencies {
let memo_freq = MemoFrequencyStats::determine_from_db(db, optimal_init_percent / 100.);
let memo_freq = memo_freq.serialize();
let path = crate::precomputed_memo_frequencies_path!();
std::fs::write(path, memo_freq).context("failed to write memo frequency data")?;
eprintln!(
"Wrote memo frequencies into `{}`.",
std::fs::canonicalize(path).unwrap_or_else(|_| PathBuf::from(path)).display(),
);
}
```
Then, I first compile without the feature, and run `analysis-stats -- write-memo-frequencies <fraction>` on some project. `<fraction>` is determined experimentally, as a compromise between speed (avoiding excess reallocations) and memory usage; I found 90% (0.9) to be a good balance.
After the run finishes, I re-compile with `--features rust-analyzer/precomputed-memo-frequencies`, and now I have an optimized binary. Allow customizing the order of memos to save memory usage
The order is inferred based on previous runs, like in PGO.
In rust-analyzer this saves between 16mb and 100mb on the projects I measured. The setup goes like that: the top level crate, `rust-analyzer`, gains a new feature `precomputed-memo-frequencies`. I also included the following code:
```rust
#[macro_export]
macro_rules! precomputed_memo_frequencies_path {
() => {
concat!(env!("CARGO_MANIFEST_DIR"), "/../../memo_frequencies.bin")
};
}
#[cfg(feature = "precomputed-memo-frequencies")]
pub fn memo_frequencies() -> MemoFrequencyStats {
static MEMO_FREQUENCIES: std::sync::LazyLock<MemoFrequencyStats> =
std::sync::LazyLock::new(|| {
let data = include_bytes!(crate::precomputed_memo_frequencies_path!());
MemoFrequencyStats::deserialize(data)
});
MEMO_FREQUENCIES.clone()
}
#[cfg(not(feature = "precomputed-memo-frequencies"))]
pub fn memo_frequencies() -> MemoFrequencyStats {
MemoFrequencyStats::default()
}
```
Then when creating a database I pass `memo_frequencies()`.
I also included a flag in the CLI command that analyzes a project (`analysis-stats`). When the flag is active it does:
```rust
if let Some(optimal_init_percent) = self.write_memo_frequencies {
let memo_freq = MemoFrequencyStats::determine_from_db(db, optimal_init_percent / 100.);
let memo_freq = memo_freq.serialize();
let path = crate::precomputed_memo_frequencies_path!();
std::fs::write(path, memo_freq).context("failed to write memo frequency data")?;
eprintln!(
"Wrote memo frequencies into `{}`.",
std::fs::canonicalize(path).unwrap_or_else(|_| PathBuf::from(path)).display(),
);
}
```
Then, I first compile without the feature, and run `analysis-stats -- write-memo-frequencies <fraction>` on some project. `<fraction>` is determined experimentally, as a compromise between speed (avoiding excess reallocations) and memory usage; I found 90% (0.9) to be a good balance.
After the run finishes, I re-compile with `--features rust-analyzer/precomputed-memo-frequencies`, and now I have an optimized binary. Latest Branches
-3%
ChayimFriedman2:no-typeid-memo +4%
0%
renovate/taiki-e-install-action-2.x © 2026 CodSpeed Technology