-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Optimization attempt for union of maps and tuples #14205
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We are still going to change the implementation of maps considerably, so I would suggest keeping those separate.
Something else you can do, which is what we do once we normalize, is to compute the union of two fields, if there is only field that is different. And in this case, we check for structural equality.
So this could be a more general algorithm:
This should require one pass to find fields and another to solve subtyping.
WDYT?
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.
The
fusible_maps?
function gives you a general idea of the algorithm today, although it returns a boolean, and you want something more complex. We could later on adapt the function to be shared by both union and normalize.Uh oh!
There was an error while loading. Please reload this page.
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.
Makes sense 👍
Interesting one, I think I see what you're saying. Only if the tags are equal though, correct?
%{a: integer(), b: type_of_b()} or %{a: float(), b: type_of_b()}
is%{a: integer() or float(), b: type_of_b()}
%{..., a: integer(), b: type_of_b()} or %{..., a: float(), b: type_of_b()}
is%{..., a: integer() or float(), b: type_of_b()}
%{..., a: integer(), b: type_of_b()} or %{a: float(), b: type_of_b()}
=> any other field is illegal ifa
is a float?It would be nice to have a bench for this case, do you have an example in mind where we could measure its impact?
Uh oh!
There was an error while loading. Please reload this page.
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.
Yes, only if the tags are equal. In my mind, the most expensive parts are computing the subtyping and traversing the keys. So in my mind, the suggestions above are an improvement to this pull request because:
In pseudo code:
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.
The important point I didn't highlight in the PR description is that I'm not using
subtype?
(which I understand is quite expensive), but a very lightweightsimple_subtype?
(trivial_subtype?
) which only handles trivial cases likeinteger() subtype_of term()
or{integer(), string()} subtype_of {term(), term()}
(which are the kind of cases I saw in practices in the slow examples).I don't expect it to be costly, because it only does mostly shallow pattern/guard-based comparisons and bails as soon as something is off (different # of keys, one key missing, one key not being a trivial subtype).
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.
Yes, I got it, but it will be slower than the equality check and, given we are traversing keys anyway, providing a more general solution than simple subtyping will yield other benefits. Basically, if we are already traversing the keys to optimize, let's optimize as much as we can?
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.
Strongly agreed 👍
Will try to prepare some benchee bench as well.
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.
Done in a new PR #14215