Skip to content

Commit 96717a9

Browse files
brittanyreymeta-codesync[bot]
authored andcommitted
Fix remaining O(n*m) in cross-library resolution promotion path
Summary: D106415307 fixed the O(n*m) unqualified-name scan in `resolve_cross_library_errors`'s error-*clearing* loop by adding the `globally_safe_funcs` index plus `is_call_verified_safe_indexed`. But the sibling call site — the function-*promotion* fixpoint (`promote_resolved_module_functions` -> `can_promote_missing_dep_function`) — was left calling the non-indexed `is_call_verified_safe` with `module_names` (every module). For each `UnsafeMissingDep` callee that does not resolve to a qualified module, that fallback scans all modules, so the promotion fixpoint stayed O(n*m). This call site does not show up on the medium target but dominates on XL: on `confucius/server/ads_abtest:ads_abtest_server` (250,811 modules) `analyze-binary` was pinned single-threaded for 15+ minutes, with perf attributing ~95% of `resolve_cross_library_errors` to `is_call_verified_safe`. Fix: route `can_promote_missing_dep_function` through the same `is_call_verified_safe_indexed` helper and `globally_safe_funcs` index that D106415307 already added. Because `module_names` covers every module and the index is kept in sync with promotions, the result is identical to the old unqualified scan but O(1) per callee instead of O(modules). Result on XL (`ads_abtest_server`, 250,811 modules): `resolve_cross_library_errors` 15+ min -> 8.2s; `analyze-binary` total -> 14.3s. Reviewed By: martindemello Differential Revision: D107395893 fbshipit-source-id: 9761569f26f385c3ace7c68d1c4ea6ef679aa876
1 parent 0c50ece commit 96717a9

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/cache.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ impl LibraryCache {
294294
continue;
295295
};
296296
for (func_name, info) in fs {
297-
if can_promote_missing_dep_function(info, module_names, func_safety_by_module) {
297+
if can_promote_missing_dep_function(
298+
info,
299+
module_names,
300+
func_safety_by_module,
301+
globally_safe_funcs,
302+
) {
298303
to_promote.push((module.name, func_name.clone()));
299304
}
300305
}
@@ -552,14 +557,20 @@ fn can_promote_missing_dep_function(
552557
info: &FunctionSafetyInfo,
553558
module_names: &AHashSet<ModuleName>,
554559
func_safety_by_module: &HashMap<ModuleName, HashMap<String, FunctionSafetyInfo>>,
560+
globally_safe_funcs: &AHashSet<String>,
555561
) -> bool {
556562
info.verdict == FunctionSafety::UnsafeMissingDep
557563
// Promote only with positive evidence: a non-empty callee set,
558564
// all now verified safe. No record (e.g. a re-export-propagated
559565
// verdict) stays conservatively unsafe.
560566
&& !info.missing_dep_callees.is_empty()
561567
&& info.missing_dep_callees.iter().all(|callee| {
562-
is_call_verified_safe(callee.as_str(), module_names, func_safety_by_module)
568+
is_call_verified_safe_indexed(
569+
callee.as_str(),
570+
module_names,
571+
func_safety_by_module,
572+
globally_safe_funcs,
573+
)
563574
})
564575
}
565576

0 commit comments

Comments
 (0)