-
Notifications
You must be signed in to change notification settings - Fork 38
Use sets rather than lists in compiler types #247
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
Conversation
We still have to keep the order for some reason, but at least the filtering process checks for membership in O(log n) rather than O(n). Not sure this matters in practice but at least we are not calling the generic structural equality on potentially arbitrary data.
@gares the merge_type function is a hotspot of HB for some reason. This PR doesn't solve the underlying efficiency problem, but 1. it makes it algorithmically more reasonable 2. it abstracts aways the implementation and 3. it doesn't rely anymore on structural equality. |
(Full disclaimer: I have no idea what purpose this list of types is supposed to have, I am just messing with the code and hinting at a suspect point.) |
if set' == t.set && lst' == t.lst && def' == t.def then t | ||
else { set = set'; lst = lst'; def = def' } | ||
|
||
let append x t = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this cons
?
I'd like to understand why you need |
Thanks your change makes a lot of sense. At the same time, I don't get why it should be a bottleneck. In which file? TBH, the compilation chain will require some serious scrutiny and speedup, scheduled this fall. |
The first HB calls in e.g. |
I'm looking into this, it is very weird this is expensive since most of these maps should be empty |
I did push a commit. I guess you have a setup where you can bench this. If not I will do it myself. In my local tests the list/sets of types are of size 1 or 2, so anything would do. |
New
old
|
No, I'm confident this is the precise stack call I mentioned before. In any case, your last commit has indeed solved the issue on mathcomp-analysis. |
let fold t accu = | ||
let t' = f t in | ||
if t' == t then accu | ||
else Set.add t' (Set.remove t accu) | ||
in | ||
let set' = Set.fold fold t.set t.set in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ocaml sets have https://github.com/ocaml/ocaml/blob/cea4b6d84161e3d35eb6966bdbfaa225de44832c/stdlib/set.mli#L209-L219 since 4.04
We still have to keep the order for some reason, but at least the filtering process checks for membership in O(log n) rather than O(n). Not sure this matters in practice but at least we are not calling the generic structural equality on potentially arbitrary data.