Skip to content

Commit

Permalink
Add comment regarding performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Dec 21, 2024
1 parent 9d57adf commit b455093
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl SymbolDeclarations {
.push(ScopedVisibilityConstraintId::ALWAYS_TRUE);
}

/// Add given visibility constraint to all live bindings.
/// Add given visibility constraint to all live declarations.
pub(super) fn record_visibility_constraint(
&mut self,
visibility_constraints: &mut VisibilityConstraints,
Expand Down
6 changes: 6 additions & 0 deletions crates/red_knot_python_semantic/src/visibility_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ use crate::semantic_index::{
use crate::types::{infer_expression_types, Truthiness};
use crate::Db;

/// The maximum depth of recursion when evaluating visibility constraints.
///
/// This is a performance optimization that prevents us from descending deeply in case of
/// pathological cases. The actual limit here has been derived from performance testing on
/// the `black` codebase. When increasing the limit beyond 32, we see a 5x runtime increase
/// resulting from a few files with a lot of boolean expressions and `if`-statements.
const MAX_RECURSION_DEPTH: usize = 24;

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit b455093

Please sign in to comment.