Skip to content
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

Flatten children array as it is diffed #1716

Merged
merged 3 commits into from
Sep 9, 2019
Merged

Conversation

andrewiggins
Copy link
Member

@andrewiggins andrewiggins commented Jun 18, 2019

Instead of passing over the newVNode's children array twice (once in toChildArray to flatten it, and once again in diffChildren to diff the children), we now pass over the children once, diffing the children and flattening the list as we go.

Total change:
+6 B (22e0fba)
-4 B (ffc1713)

@andrewiggins
Copy link
Member Author

If anyone has the time and setup, would love to know if this PR moves the perf at all

@coveralls
Copy link

coveralls commented Jun 18, 2019

Coverage Status

Coverage increased (+0.0003%) to 99.882% when pulling b7ca4fa on forEachChild into 1d2882e on master.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

This looks good, in my mind this feels slower because of the function allocation but I think that’s because I think about the classic engines. Should be tested, I’ll see if I can find the big jsperf benchmark on my laptop.

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

So good 👍 💯 Skipping a whole iteration should be faster in theory but I haven't made any tests to get some numbers. @developit maybe you got some benches ready when you suggested the change on slack? 🙂

@cristianbote
Copy link
Member

Hey @andrewiggins took a stab at it and tried to resolve the conflicts 🕺 If something it's not right, please let me know.

*/
export function toChildArray(children, flattened, map, keepHoles) {
export function toChildArray(children, callback, flattened) {
Copy link
Member

Choose a reason for hiding this comment

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

IIRC the first two args here are used externally. Maybe worth changing to toChildArray(children, flattened, callback)?

Copy link
Member

Choose a reason for hiding this comment

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

I think that change was made for golfing purposes in children.js. There it's used without the flattened argument. Either way we've only advertised the first arg so far in our types and elsewhere. So I think it's fine to swap them like it's done here.

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.

6 participants