Skip to content

Conversation

@poke1024
Copy link
Contributor

This PR introduces a special case for flattening sequences as it's an operation/border case deeply embedded into the rules and evaluation engine and executed nearly each time a rule is resolved.

The main advantage of the new approach is that symbols are now tracked during Expression construction, such that all paths leading to a symbol can be efficiently identified in any part of an Expression tree without having to revert to full tree traversals. In that way, all sub trees of an Expression not containing sequences don't have to be checked.

The original optimization targeted with this PR was faster handling of huge lists. E.g., using list = Nest[Partition[#, 2]&, Range[2 ^ 14], 14]:

Without this PR:

In[2]:= Timing[Length[list]]
Out[2]= {0.330744, 1}

With this PR:

In[2]:= Timing[Length[list]]
Out[2]= {0.165357, 1}

In addition to this targeted case, this PR yields notable performance improvements across the board (see attached files, esp. Random).

opt4-before.txt

opt4-after.txt

@sn6uv sn6uv merged commit 27a1bba into mathics:master Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants