-
Notifications
You must be signed in to change notification settings - Fork 217
perf: class_ and classes -> dont use unwrap because it generates inefficient code, use unsafeCoerce #693
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
base: master
Are you sure you want to change the base?
Conversation
I think it would be better to wait for 0.14, which implements safe coercions so that we get this for free without using unsafeCoerce (we can use the ‘coerce’ function instead). |
@thomashoneyman will it? I thought it needs something like purescript/purescript#3890 to work |
Hmm — I didn’t know about #3890. I would hope that if coerce is meant to be the way to do safe coercions that it would generate the same code as unsafeCoerce. This change is probably not very risky, and it generates better code, but if possible I would rather rely on a safe operation and I’d like to check whether coerce will provide that. Halogen 6 will be released with 0.14. Even if it doesn’t generate the nicer code it at least still has some savings. I would also hope that the newtype library uses coerce for unwrap going forward, because afaik that’s the primary thing to replace with it. In that case we wouldn’t need to change any uses of unwrap. Have you checked for other places where we should plan to switch to coerce? |
no 👀 ) |
Why don't you just pattern match the newtype? |
Good point. Though that wouldn't help in the case of |
Yeah, that's right |
After looking further through the plans for safe coercion and #3890 I would rather not introduce the Instead, I suggest we pattern-match on the newtype instead of calling I don't think the small additional overhead of using |
|
||
classes :: forall r i. Array ClassName -> IProp (class :: String | r) i | ||
classes = prop (PropName "className") <<< joinWith " " <<< map unwrap |
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.
As of Halogen 6 this can now be replaced with coerce
@@ -148,10 +148,10 @@ charset :: forall r i. String -> IProp (charset :: String | r) i | |||
charset = prop (PropName "charset") | |||
|
|||
class_ :: forall r i. ClassName -> IProp (class :: String | r) i | |||
class_ = prop (PropName "className") <<< unwrap |
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 can use pattern-matching here to avoid the call to unwrap
, rather than unsafeCoerce
…ficient code, use coerce
with coerce the generated core is
why it doesnt optimize? |
before purs 0.13.8 generated
now