Skip to content

Commit 9cb0525

Browse files
yangdanny97meta-codesync[bot]
authored andcommitted
optimize lookup_special_export
Summary: Profiling the indexing of langchain/dify I found >25% of the time was spent waiting on locks in lookup_special_export There's lots of contention for calculating exports here since we check lookup_special_export so much in bindings Longer AI explanation: P2152790830 Adding a fast return path that avoids pulling exports before entering the loop reduces the contention. Reviewed By: rchen152 Differential Revision: D91753332 fbshipit-source-id: f89ef539fa5c9ca8fcc495806969d27b137062b6
1 parent 93fd467 commit 9cb0525

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pyrefly/lib/binding/scope.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@ impl Scopes {
17611761
mut module: ModuleName,
17621762
lookup: &dyn LookupExport,
17631763
) -> Option<SpecialExport> {
1764+
// Fast check to avoid calculating exports, reducing contention
1765+
if let Some(special) = SpecialExport::new(&name)
1766+
&& special.defined_in(module)
1767+
{
1768+
return Some(special);
1769+
}
17641770
let mut seen = HashSet::new();
17651771
let mut exports = lookup.get(module).finding()?.exports(lookup);
17661772
loop {

0 commit comments

Comments
 (0)