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

[patch] Bad typing performances of big variant type declaration #5944

Closed
vicuna opened this issue Mar 12, 2013 · 3 comments
Closed

[patch] Bad typing performances of big variant type declaration #5944

vicuna opened this issue Mar 12, 2013 · 3 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Mar 12, 2013

Original bug ID: 5944
Reporter: bvaugon
Assigned to: @garrigue
Status: closed (set by @garrigue on 2013-04-23T00:38:42Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.00.1
Fixed in version: 4.00.2+dev
Category: typing

Bug description

The typing complexity of variant type declaration like:

type t = X1 | X2 | X3 | [...] | X32768

is very bad.

This kind of code pattern is somtime usefull, in particular in OCaPIC low level libraries, and it can be fixed by the small and simple attached patch.

Steps to reproduce

Insert this kind of type declaration in a x.mli file and run:

time ocamlopt x.mli

Additional information

The culprit function is check_constraints defined in typing/typedecl.ml.
A small "Map" index resolve the problem, as you can see in the attached patch:
ocaml-4.00.1-fast-typedecl.diff.

With this patch, the time needed to compile a variant definition with 32768 constant constructors go down from 29s to 0.39s (on my computer).

File attachments

@vicuna
Copy link
Author

vicuna commented Mar 12, 2013

Comment author: @garrigue

Well, this is really a huge type...

Your patch is small, so I will probably include it.
My only concern is that you may get into other performance problems using this type.

@vicuna
Copy link
Author

vicuna commented Mar 12, 2013

Comment author: bvaugon

Yes, it's not impossible. But in practice, for now, I uses types like this in multiple programs without other compilation problems.

Thanks for your answer!

@vicuna
Copy link
Author

vicuna commented Apr 23, 2013

Comment author: @garrigue

Patch merge in trunk and 4.00, revision 13588 and 13589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants