Opened 10 years ago
Closed 4 years ago
#2800 closed defect (fixed)
Improve Expression traversal
Reported by: | Martin Sjölund | Owned by: | Martin Sjölund |
---|---|---|---|
Priority: | high | Milestone: | 1.16.0 |
Component: | Frontend | Version: | trunk |
Keywords: | Cc: | Adrian Pop, leonardo, Per Östlund |
Description
We need to improve expression traversal performance in a few steps.
Do not pass everything as a tuple. This causes stress on the GC. The functions should instead have the prototype:
partial function FuncExpType input DAE.Exp inExp; input Type_a inTypeA; output DAE.Exp outExp; output Type_a outA; end FuncExpType;
We need to remove some duplicate code like traverseExpWithoutRelations. If traverseExp needs more functionality, pass it as an extra argument (keep traverseExp as it is; use intermediate functions instead).
If possible, add support for functions that do not modify the expressions or extra arguments, like:
partial function FuncExpType2 input DAE.Exp inExp; input Type_a inTypeA; output DAE.Exp outExp; end FuncExpType2;
or
partial function FuncExpType3 input DAE.Exp inExp; input Type_a inTypeA; output DAE.Exp outExp; end FuncExpType3;
or
partial function FuncExpType4 input DAE.Exp inExp; output DAE.Exp outExp; end FuncExpType4;
This can be done by passing additional arguments to the worker function.
Change History (4)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:3 by , 10 years ago
I am thinking of maybe having something like:
traverseExp(e, TOPDOWN(topDownFunc), extraArg); function traverseExp ... algorithm (e,continue,extraArg) := evalTraversalFunctionTopDown(e, funcUnion, extraArg); (e,extraArg) := match (...) ... case BINARY(e1,op,e2) equation (e1_1,extraArg) = traverseExp(e1,funcUnion,extraArg); (e2_2,extraArg) = traverseExp(e1,funcUnion,extraArg); e = if referenceEq(e1,e1_1) and referenceEq(e2,e2_1) then e else BINARY(e1,op,e2); then (e,extraArg) ... end match; (e,extraArg) := evalTraversalFunctionBottomUp(e, funcUnion, extraArg); end traverseExp;
This is (much) simpler to maintain (you can create many of the weird special traversal routines we have right now), but I am afraid it might slow down execution. Any thoughts?
comment:4 by , 4 years ago
Milestone: | Future → 1.16.0 |
---|---|
Resolution: | → fixed |
Status: | accepted → closed |
The traversal functions in the old frontend are still a bit of a mess, but for the new frontend we have e.g. Expression.map/fold where extra arguments can be given using function partial application. There's also e.g. Expression.mapShallow that only traverses one level down for when more control is needed. So lets consider this fixed.
Does anyone have more suggestions? I am working on the first (and second) ones.