-
Notifications
You must be signed in to change notification settings - Fork 216
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
Make schema?
, into-schema?
open to extensions
#664
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 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
This file contains 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
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.
fast & extendable:
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.
Seems pretty neat! Thanks.
However this only results for what we can call the "green path" e.g.
x
was amalli.core.Schema
.If
x
belonged an unrelated type e.g.42
, then the cost of bothor
branches would be inflicted, for nothing.One possible fix would be to reshuffle the couple
cond
s that useschema?
:malli/src/malli/core.cljc
Lines 1974 to 1976 in 68bb521
By placing the
schema?
check after thevector?
check, one surely most code paths won't ever hit thesatisifes?
.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.
Another option would be to make the extra check dependent on a compile-time condition:
This would work with my use case since I only use protocol extensions within a specific dev-time task - not as a general assumption in my production codebase.
Of course it's not as general of a solution but it might be a worthwhile alternative.
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.
Thanks for the suggestions.
There is
malli.perf.creation-perf-test
which has utilities for testing the perf gains / losses.This code:
currently calls the
schema?
andinto-schema?
with the args that don't match the predicate:perf:
satisfies?
: 90µsvector?
check first: 50µsto make it fast and extendable, we would have implement
Schema
andIntoSchema
for the default case and use some tagging methods to actually tell if it satisfies the protocol or not. Sieppari uses that. Malli had an elegant hack for caching thesatisifies?
call results, hinted by Alex. Could be re-introduced. Or some other way to write extensions for classes.lot of work that could be easily fixed in
clojure.core
, go vote the issue up :)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.
Thumbed!
Hope some sort of fix can make it into Malli in the meantime. Feel free to close this PR if you think the final approach would look too different (I'm not familiar with the tagging technique at all).
For now I'll use some monkey patching but I'd sure love something that felt more dependable.