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

Comments

Projects
None yet
2 participants
@vicuna
Copy link
Collaborator

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

This comment has been minimized.

Copy link
Collaborator Author

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

This comment has been minimized.

Copy link
Collaborator Author

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

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 23, 2013

Comment author: @garrigue

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

@vicuna vicuna closed this Apr 23, 2013

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.