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

dramatically improve performance of UnaryType and BinaryType #244

Merged
merged 1 commit into from
Mar 29, 2019

Conversation

davidchambers
Copy link
Member

Commit message:

The predicate and extractor functions provided to the UnaryType and BinaryType type constructors play an important role in type checking. Each predicate function may be applied hundreds of times when a small program is run. This is not a problem, in and of itself.

If these oft-applied functions are themselves type-checked, though, run-time type checking is significantly more expensive as a result.

This commit disables type checking of predicate and extractor functions.

On my computer, the following program takes about half a second to run on this branch compared with about five seconds on master:

const $ = require ('.');

const a = $.TypeVariable ('a');

const xs = []; for (let x = 0; x < 1000; x += 1) xs.push ([[[[[[[[[x]]]]]]]]]);

$.create
  ({checkTypes: true, env: [$.Array ($.Unknown), $.Number]})
  ('I')
  ({})
  ([a, a])
  (x => x)
  (xs);

Note that providing $.env as the environment does not demonstrate the problem because the version of $.Array included in $.env is not defined via def.

Copy link
Member

@Avaq Avaq left a comment

Choose a reason for hiding this comment

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

Fantastic!

The predicate and extractor functions provided to the UnaryType and
BinaryType type constructors play an important role in type checking.
Each predicate function may be applied hundreds of times when a small
program is run. This is not a problem, in and of itself.

If these oft-applied functions are themselves type-checked, though,
run-time type checking is significantly more expensive as a result.

This commit disables type checking of predicate and extractor functions.
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.

None yet

2 participants