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

Use a queue instead of array reduce for performance #142

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

nettyso
Copy link
Contributor

@nettyso nettyso commented Oct 18, 2020

I was suspicious of the number of function calls in gathering children so I made a performance test: perf.link

Firefox is 19% the speed.
image

Opera/Blink is 1% (!!!) the speed.
image

@luwes
Copy link
Owner

luwes commented Oct 19, 2020

Wow this is impressive! I'll have a look at this soon. Great find!

@luwes
Copy link
Owner

luwes commented Oct 20, 2020

checking to make sure we don't re-introduce this bug. I don't think it's covered in the tests
#20 (comment)

there is a test, cool

test('parent cleans up inner subscriptions', function(t) {

Copy link
Owner

@luwes luwes left a comment

Choose a reason for hiding this comment

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

LGTM 👍 awesome work! thank you

@luwes luwes merged commit 80b08b1 into luwes:master Oct 20, 2020
@nettyso
Copy link
Contributor Author

nettyso commented Oct 20, 2020

That's good to check and have tests for it. I tried to make other optimizations elsewhere and was surprised, but happy, that tests failed - helped me a lot in understanding how the code works.

@luwes
Copy link
Owner

luwes commented Oct 20, 2020

still checking the tests a little, I hit a case where the tests still pass when commenting out this whole block:

I feel like there should be a test failing when we do this.

    // prevChildren.forEach(u => {
    //   if (update._children.indexOf(u) === -1) {
    //     u._fresh = true;
    //   }
    // });

    // // If any children were marked as fresh remove them from the run lists.
    // let curr;
    // const queue = [].concat(update.children);
    // while (curr = queue.pop()) {
    //   if (curr._fresh) {
    //     curr._observables.forEach(o => {
    //       if (o._runObservers) o._runObservers.delete(curr);
    //     });
    //   }
    //   curr.children.forEach(u => queue.push(u));
    // }

@nettyso
Copy link
Contributor Author

nettyso commented Oct 20, 2020

Hmm yeah. That does seem strange. As for the actual PR changes though, it doesn't look like any observables could run or cause changes (to the run list or other observables for example) - I imagine deleting all children from run lists is safe regardless of the order of operations?

@luwes
Copy link
Owner

luwes commented Oct 20, 2020

you're right, just noticed those are deleted anyway
700bf4c#diff-557ac877462f43d8cd15cc29b87f96bf489abfc5ebc44fadbc958a5d10cda04e

I'm wondering if that whole block might be unneeded then because that case Ryan explained is passing its tests.

allChildren.forEach(removeFreshChildren);

let curr;
const queue = [].concat(update.children);
Copy link
Owner

Choose a reason for hiding this comment

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

just noticed, missing the underscore here. update._children

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WHOA. Huh sorry I missed that converting from a TS codebase back to JS... I'm too used to the editor catching that :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants