mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-06 00:20:37 +00:00
[ty] Add environment variable to dump Salsa memory usage stats (#18928)
## Summary Setting `TY_MEMORY_REPORT=full` will generate and print a memory usage report to the CLI after a `ty check` run: ``` =======SALSA STRUCTS======= `Definition` metadata=7.24MB fields=17.38MB count=181062 `Expression` metadata=4.45MB fields=5.94MB count=92804 `member_lookup_with_policy_::interned_arguments` metadata=1.97MB fields=2.25MB count=35176 ... =======SALSA QUERIES======= `File -> ty_python_semantic::semantic_index::SemanticIndex` metadata=11.46MB fields=88.86MB count=1638 `Definition -> ty_python_semantic::types::infer::TypeInference` metadata=24.52MB fields=86.68MB count=146018 `File -> ruff_db::parsed::ParsedModule` metadata=0.12MB fields=69.06MB count=1642 ... =======SALSA SUMMARY======= TOTAL MEMORY USAGE: 577.61MB struct metadata = 29.00MB struct fields = 35.68MB memo metadata = 103.87MB memo fields = 409.06MB ``` Eventually, we should integrate these numbers into CI in some form. The one limitation currently is that heap allocations in salsa structs (e.g. interned values) are not tracked, but memoized values should have full coverage. We may also want a peak memory usage counter (that accounts for non-salsa memory), but that is relatively simple to profile manually (e.g. `time -v ty check`) and would require a compile-time option to avoid runtime overhead.
This commit is contained in:
parent
a1579d82d0
commit
6f7b1c9bb3
79 changed files with 905 additions and 207 deletions
|
@ -86,7 +86,7 @@ declare_lint! {
|
|||
}
|
||||
}
|
||||
|
||||
#[salsa::tracked(returns(ref))]
|
||||
#[salsa::tracked(returns(ref), heap_size=get_size2::GetSize::get_heap_size)]
|
||||
pub(crate) fn suppressions(db: &dyn Db, file: File) -> Suppressions {
|
||||
let parsed = parsed_module(db.upcast(), file).load(db.upcast());
|
||||
let source = source_text(db.upcast(), file);
|
||||
|
@ -331,7 +331,7 @@ impl<'a> CheckSuppressionsContext<'a> {
|
|||
}
|
||||
|
||||
/// The suppressions of a single file.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[derive(Debug, Eq, PartialEq, get_size2::GetSize)]
|
||||
pub(crate) struct Suppressions {
|
||||
/// Suppressions that apply to the entire file.
|
||||
///
|
||||
|
@ -424,7 +424,7 @@ impl<'a> IntoIterator for &'a Suppressions {
|
|||
/// Suppression comments that suppress multiple codes
|
||||
/// create multiple suppressions: one for every code.
|
||||
/// They all share the same `comment_range`.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, get_size2::GetSize)]
|
||||
pub(crate) struct Suppression {
|
||||
target: SuppressionTarget,
|
||||
kind: SuppressionKind,
|
||||
|
@ -466,10 +466,10 @@ impl Suppression {
|
|||
/// The wrapped `TextRange` is the suppression's range.
|
||||
/// This is unique enough because it is its exact
|
||||
/// location in the source.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, get_size2::GetSize)]
|
||||
pub(crate) struct FileSuppressionId(TextRange);
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, get_size2::GetSize)]
|
||||
enum SuppressionTarget {
|
||||
/// Suppress all lints
|
||||
All,
|
||||
|
@ -628,7 +628,7 @@ impl<'a> SuppressionsBuilder<'a> {
|
|||
}
|
||||
|
||||
/// Suppression for an unknown lint rule.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, get_size2::GetSize)]
|
||||
struct UnknownSuppression {
|
||||
/// The range of the code.
|
||||
range: TextRange,
|
||||
|
@ -639,7 +639,7 @@ struct UnknownSuppression {
|
|||
reason: GetLintError,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, get_size2::GetSize)]
|
||||
struct InvalidSuppression {
|
||||
kind: SuppressionKind,
|
||||
error: ParseError,
|
||||
|
@ -843,7 +843,7 @@ struct SuppressionComment {
|
|||
codes: Option<SmallVec<[TextRange; 2]>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, get_size2::GetSize)]
|
||||
enum SuppressionKind {
|
||||
TypeIgnore,
|
||||
Ty,
|
||||
|
@ -871,7 +871,7 @@ impl fmt::Display for SuppressionKind {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, get_size2::GetSize)]
|
||||
struct ParseError {
|
||||
kind: ParseErrorKind,
|
||||
|
||||
|
@ -893,7 +893,7 @@ impl fmt::Display for ParseError {
|
|||
|
||||
impl Error for ParseError {}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Error)]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Error, get_size2::GetSize)]
|
||||
enum ParseErrorKind {
|
||||
/// The comment isn't a suppression comment.
|
||||
#[error("not a suppression comment")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue