-
Notifications
You must be signed in to change notification settings - Fork 455
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
Jsx ppx optimize object allocation #6376
Jsx ppx optimize object allocation #6376
Conversation
@@ -26,12 +26,12 @@ module Jsx = JsxC | |||
|
|||
%%private( | |||
@val | |||
external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign" | |||
external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign" |
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.
This was intentional to avoid mutating the object.
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.
Am I remembering correctly? @cknitt
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.
Oh, I missed that switching arguments position between key and props. It makes sense.
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.
It doesn't mutate the props
object. It'll create the new object with key
field and then mutate it.
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.
Before:
- Create
empty obj
- Create
obj with key
- Mixing
props
andobj with key
to theempty object
After:
- Create
obj with key
- Mixing
props
to theobj with key
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.
I don't understand what you want to say 😅
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.
Sorry for the lack of explanation.
I meant I think that the existing implementation is more appropriate.
What do you think? @cknitt
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.
This should work like the previous implementation (no mutation), but with one less object allocation. Looks good to me.
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.
(Provided that the caller passes a different {"key": key} object every time, but that seems to be the case and this is an internal function anyway.)
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.
Okay. It seems unlikely that Object.assign({"key": key}, props)
would change the value of key at runtime, since props would not be able to contain key when the JSX ppx transforms the component application.
LGTM.
Ready to merge? |
Yes |
Can you update changelog? |
Yep |
2c8f479
to
d9286f4
Compare
No description provided.