Optimize TD3 to not unnecessarily store bottom for just eval-ed variables#349
Optimize TD3 to not unnecessarily store bottom for just eval-ed variables#349
Conversation
…bles This was revealed by #345. Simply get-ing/eval-ing global constraint variables added bottom to rho. This unnecessarily increases rho with default values. An an unintended consequence, the bottom values for all dead local variables also never get stored.
This is the best of both worlds: 1. no stored bot for just read globals, 2. stored bot for dead code (to avoid recomputation).
| (* if HM.mem called y then (init y; let y' = HM.find_default l y (S.Dom.bot ()) in HM.replace rho y y'; HM.remove l y; y') else *) | ||
| if S.system y = None then (init y; add_infl y x; try HM.find rho y with Not_found -> S.Dom.bot ()) else | ||
| if not space || HM.mem wpoint y then (solve y Widen; add_infl y x; try HM.find rho y with Not_found -> S.Dom.bot ()) else | ||
| if HM.mem called y then (init y; HM.remove l y; add_infl y x; try HM.find rho y with Not_found -> S.Dom.bot ()) else |
There was a problem hiding this comment.
This HM.mem called y case doesn't exist in the TD3 paper. Is it some optimization? If so, then maybe there should be an explanatory comment.
| HM.replace rho x (S.Dom.bot ()) | ||
| if init_bot_all || (init_bot_rhs && S.system x <> None) then | ||
| HM.replace rho x (S.Dom.bot ()) | ||
| (* TODO: fix new_var_event repeatedly triggering when init-ing multiple times without value *) |
There was a problem hiding this comment.
it looks like the solver variable counting happens very primitively by incrementing a counter:
analyzer/src/solvers/generic.ml
Lines 207 to 209 in 5a434cd
Seems to me like this could just be
HM.length rho, which would fix the new issue.
|
To recap from Gobcon yesterday: The bottoms that are inserted are meaningful in that the hashtable for a partial (post-)solution should be closed, i.e. not depend on any implicit bottoms for any unknown. From a purely practical standpoint, I guess the question is whether one wants to introduce an option that still makes this optimization, in case one is not interested in the domain. I think this something we should then only consider if it leads to improved performance of the solver, quicker marshaling, or some other measurable improvement. |
In the space variant, the solution hashtable isn't closed anyway and missing keys might even correspond to non-bottom values. And the paper goes through all the trouble to define the closure of such solution to make it meaningful. Surely the reasoning for closing only bottoms is much simpler since it requires no transfer function evaluations (and resolving between wpoint). Moreover, we already make this assumption of implicit bottoms in the partial solution all over the place: EDIT 1: Even TD3 itself, before these changes, follows this convention in some places: Lines 334 to 338 in 139734d Lines 390 to 391 in 139734d Lines 473 to 475 in 139734d So it's not even consistent within TD3 itself and that's why it seems like this was intended, but left uncompleted at some point. EDIT 2: To drive this even further, the TD3 article doesn't even have |
|
Do we want to do something with this or close it? I would vote for only merging this if we can show it to have significant performance impact. |
|
@stilscher @jerhard @sim642 Opinions on whether we should mege (with a special option) or close this? |
|
I think it's not worth complicating things by having another option for this feature, which probably made no performance difference. But I'll have a closer look before closing. |
|
I cherry-picked 1f4bd6e onto master because it's orthogonal cleanup, but let's leave the rest for now. |
This was revealed by #345.
Simply
get-ing/eval-ing global constraint variables added bottom torho.This unnecessarily increases rho with default values.
This PR changes TD3 such that it doesn't store those bottoms eagerly when a constraint variable is just read and never receives a real value. Thus most
HM.find rhoare wrapped with catchingNot_foundto return bottom. Is there maybe some reason I'm not aware of why TD3 doesn't use implicit bottom values already?There were a few places where
HM.mem rhowas used, for which it matters whether the bottom value has been added or not. From what I can tell, these are just for the space variant and actually correspond toHM.mem wpoint, which is how those checks are presented in the TD3 paper.I added two static variables to tune the bottom insertion behavior of
initsuch that the old behavior can easily be toggled as well.