Skip to content

Conversation

@DZakh
Copy link
Member

@DZakh DZakh commented Aug 29, 2023

No description provided.

%%private(
@val
external propsWithKey: (@as(json`{}`) _, 'props, {"key": string}) => 'props = "Object.assign"
external propsWithKey: ({"key": string}, 'props) => 'props = "Object.assign"
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

  1. Create empty obj
  2. Create obj with key
  3. Mixing props and obj with key to the empty object

After:

  1. Create obj with key
  2. Mixing props to the obj with key

Copy link
Member Author

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 😅

Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.)

Copy link
Member

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.

@mununki
Copy link
Member

mununki commented Sep 1, 2023

Ready to merge?

@DZakh
Copy link
Member Author

DZakh commented Sep 6, 2023

Yes

@mununki
Copy link
Member

mununki commented Sep 12, 2023

Can you update changelog?

@DZakh
Copy link
Member Author

DZakh commented Sep 12, 2023

Yep

@DZakh DZakh force-pushed the react-ppx-optimize-obj-allocation branch from 2c8f479 to d9286f4 Compare September 12, 2023 15:50
@mununki mununki merged commit 0974127 into rescript-lang:master Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants