Improve compile time of opens, esp. for local opens #6826
Original bug ID: 6826
Every time an "open" is type-checked, all items from the opened signature are added to the environment. This can become problematic esp. with local opens. Consider for instance:
module A = struct
Type-checking this with ocamlc.opt shows a clear quadratic behavior:
N = 1000: 1.04s
I don't know how bad this is in practice, since people don't often have modules with so many elements, but this show that perhaps something could be improved.
This is not related to sub-modules, so I don't think that #5916 is relevant here. I checked manually, and all the time in Env.open_signature is spent in computing newenv, not on computing the substituted signature sg. And even more specifically, most of the time is spent in Ident.add (and a non-negligible part of it in the string comparison between id.name and k.ident.name).
This could be improved in several ways:
The text was updated successfully, but these errors were encountered:
Comment author: @alainfrisch
I've attached a quick POC to evaluate the idea of keeping a symbolic representation merged Env.t to type-check "open" constructs. This is mostly encapsulated in the EnvTbl module, which now has an optional "previous" field.
Results are as follow:
N = 1000: 0.07s
This is very lightly tested, and doesn't support warnings on open statements (unused opens, shadowing) for now. Also, one should probably use this new representation only for local opens, not global ones (EDIT: done in the second version of the uploaded patch).