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

optimize getFetchedAt.ts #3275

Merged
merged 4 commits into from
May 24, 2019

Conversation

slecoustre
Copy link

When you have a call with many identifiers then the getFetchedAt took a lot of time.

@Kmaschta
Copy link
Contributor

How many identifiers did you have that this reduce becomes a performance issue ? :o

@slecoustre
Copy link
Author

@Kmaschta I had 1200 id and it was between 1 to 2s just for getFetchedAt. with this optimization this is almost instantaneous

@fzaninotto fzaninotto merged commit 71de47a into marmelab:master May 24, 2019
@fzaninotto
Copy link
Member

I made some perf tests and the difference is indeed abysmal. I'm surprised that array reduce is so slow. Anyway, thanks a lot for the patch!

@fzaninotto fzaninotto added this to the 2.9.2 milestone May 24, 2019
@NikitaVlaznev
Copy link
Contributor

May be it's not reduce's fault.
Accumulator was recreated on each iteration by {...acc}:

const newRecordsById = newRecords.reduce(
    (acc, record) => ({
        ...acc,
        [record.id]: record,
    }),
    {}
);

May be this could solve the problem (comma operator just returns the last value):

const newRecordsById = newRecords.reduce(
    (acc, record) => (
        acc[record.id] = record,
        acc
    ),
    {}
);

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.

5 participants