Skip to content

Optimize variable flattening

Valentin David requested to merge valentindavid/optimize-variables into master

Verifying for variables (all used variables defined and no cycle) is much faster than flattening them. It also uses much less memory. Only bst show -f "%{vars}" requires to flatten all variables. For other cases we can improve performance by only checking rather than flattening.

Also flattening very nested variables could lead to very long lists of empty strings. The memory usage for flattening could be a lot bigger than the resulting value. Force flattening and caching every variable definitions can improve intermediate memory consumption and only consume memory of the size of the result.

Finally, an optimization allowed inifinite cycles leading to segmentation fault. This was solved by simplifying the code.

This change will be useful to allow on-demand variable flattening for junctions which potentially have partial environment. However, this MR does not yet change the behavior.

Edited by Valentin David

Merge request reports