From beaed4d820e3afdf9914f56eb578f165d6bc0878 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 23 Mar 2020 03:11:21 -0700 Subject: [PATCH] [racerd] optimise add_callee_accesses Summary: This function is used to adapt the callee summary at a call site. It did two things for every domain element in the callee summary: - A linear search through the list of actuals. - For each such actual, it would (repeatedly) compute its ownership (!). For large summaries this can be substantial. The right way is to precompute the ownership for all actuals once and then simply retrieve it (via an array). Reviewed By: jberdine Differential Revision: D20564447 fbshipit-source-id: 1ca3121c2 --- infer/src/concurrency/RacerD.ml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/infer/src/concurrency/RacerD.ml b/infer/src/concurrency/RacerD.ml index 0a8972f62..505c0d289 100644 --- a/infer/src/concurrency/RacerD.ml +++ b/infer/src/concurrency/RacerD.ml @@ -118,19 +118,16 @@ module TransferFunctions (CFG : ProcCfg.S) = struct let add_callee_accesses formals (caller_astate : Domain.t) callee_accesses locks threads actuals callee_pname loc = let open Domain in + let actuals_ownership = + (* precompute array holding ownership of each actual for fast random access *) + Array.of_list_map actuals ~f:(fun actual_exp -> + OwnershipDomain.ownership_of_expr actual_exp caller_astate.ownership ) + in let update_ownership_precondition actual_index (acc : OwnershipAbstractValue.t) = - match acc with - | Unowned -> - (* optimisation -- already unowned, don't compute ownership of remaining actuals *) - acc - | actuals_ownership -> ( - match List.nth actuals actual_index with - | None -> - (* vararg methods can result into missing actuals so simply ignore *) - acc - | Some actual_exp -> - OwnershipDomain.ownership_of_expr actual_exp caller_astate.ownership - |> OwnershipAbstractValue.join actuals_ownership ) + if actual_index >= Array.length actuals_ownership then + (* vararg methods can result into missing actuals so simply ignore *) + acc + else OwnershipAbstractValue.join acc actuals_ownership.(actual_index) in let update_callee_access (snapshot : AccessSnapshot.t) acc = let access = TraceElem.with_callsite snapshot.access (CallSite.make callee_pname loc) in