Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance of _determineActualTypes #78

Merged
merged 1 commit into from
Jul 4, 2016
Merged

Conversation

davidchambers
Copy link
Member

Commit message:

The current algorithm is inefficient for unary and binary types. Given an array containing 1000 elements, for example, we first determine the types of each element, resulting in an array of 1000 arrays of types. We then find the intersection of these "sets". This commit introduces a different approach: for each element, we refine the set of types of which all previous elements are members rather than filtering the whole environment each time. This is significantly more efficient for large arrays.

I ran the following command to observe the performance improvement:

$ time node --eval 'const R = require("ramda"), $ = require("."), a = $.TypeVariable("a"), def = $.create({checkTypes: true, env: $.env}), id = def("id", {}, [a, a], x => x); id(R.range(0, 100 * 1000))'

On my computer this takes about 1.5 seconds on dc-perf compared with about 5 seconds on master.

100,000 elements was about as large as I could make the array without blowing the stack on master.

'\n' +
'2) Left(/XXX/) :: Either RegExp ???\n' +
'\n' +
'Since there is no type of which all the above values are members, the type-variable constraint has been violated.\n'));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. We should underline the first and third arguments in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in #79. Rather than spend time backporting the fix to this branch, I updated the expected output then commented out the failing assertion.

The current algorithm is inefficient for unary and binary types. Given
an array containing 1000 elements, for example, we first determine the
types of each element, resulting in an array of 1000 arrays of types.
We then find the intersection of these "sets". This commit introduces
a different approach: for each element, we refine the set of types of
which all previous elements are members rather than filtering the whole
environment each time. This is significantly more efficient for large
arrays.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant