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

[HOLD for payment 2024-06-13] [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method #42414

Closed
mountiny opened this issue May 21, 2024 · 14 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Daily KSv2 External Added to denote the issue can be worked on by a contributor NewFeature Something to build that is a new item.

Comments

@mountiny
Copy link
Contributor

mountiny commented May 21, 2024

Problem

When you use the spread operator in an array reduce, it often leads to a partial object being copied over and over again in a loop.

// BAD
const reducedObject = myArray.reduce(
    (acc, key) => ({
        ...acc,
        [key]: someOtherObject[key],
    }),
    {},
);

Especially with large objects, this is very inefficient because ...acc will unnecessarily copy the full object on each iteration, rather than just adding the single key we want to add.

Solution

Prohibit this pattern with a new ESLint rule - no-spread-in-reduce. The above example would result in a lint error, and you might fix it with something more simple and efficient, like this:

GOOD
const reducedObject = myArray.reduce(
    (acc, key) => {
        acc[key] = someOtherObject[key];
        return acc;
    },
    {},
)

@kacper-mikolajczak

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~011102640f041d624c
  • Upwork Job ID: 1792878366584131584
  • Last Price Increase: 2024-05-21
  • Automatic offers:
    • DylanDylann | Reviewer | 0
Issue OwnerCurrent Issue Owner: @garrettmknight
@mountiny mountiny added Daily KSv2 NewFeature Something to build that is a new item. labels May 21, 2024
@mountiny mountiny self-assigned this May 21, 2024
@mountiny mountiny added the External Added to denote the issue can be worked on by a contributor label May 21, 2024
Copy link

melvin-bot bot commented May 21, 2024

Triggered auto assignment to @garrettmknight (NewFeature), see https://stackoverflowteams.com/c/expensify/questions/14418#:~:text=BugZero%20process%20steps%20for%20feature%20requests for more details. Please add this Feature request to a GH project, as outlined in the SO.

Copy link

melvin-bot bot commented May 21, 2024

Job added to Upwork: https://www.upwork.com/jobs/~011102640f041d624c

@melvin-bot melvin-bot bot changed the title [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method [$250] [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method May 21, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Help Wanted Apply this label when an issue is open to proposals by contributors and removed Daily KSv2 labels May 21, 2024
Copy link

melvin-bot bot commented May 21, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @DylanDylann (External)

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels May 21, 2024
@mountiny mountiny removed the Help Wanted Apply this label when an issue is open to proposals by contributors label May 21, 2024
@kacper-mikolajczak
Copy link
Contributor

kacper-mikolajczak commented May 21, 2024

Hi @mountiny 👋

@mountiny mountiny changed the title [$250] [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method May 21, 2024
Copy link

melvin-bot bot commented May 21, 2024

📣 @DylanDylann 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@lirbank
Copy link

lirbank commented May 21, 2024

Just to double check, is task to create a ESLint rule to catch spread in reducers?

Copy link

melvin-bot bot commented May 21, 2024

📣 @lirbank! 📣
Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
    Screen Shot 2022-11-16 at 4 42 54 PM
    Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

@mountiny
Copy link
Contributor Author

@lirbank Hello! The task will be handled by @kacper-mikolajczak (no Help Wanted label on the issue)

However, the scope is to add the lint rule and fix all the places where its currently broken

Copy link

melvin-bot bot commented May 24, 2024

@garrettmknight, @mountiny, @kacper-mikolajczak, @DylanDylann Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@DylanDylann
Copy link
Contributor

Not overdue, we are waiting for PR to be ready for review

@melvin-bot melvin-bot bot removed the Overdue label May 27, 2024
@melvin-bot melvin-bot bot added the Reviewing Has a PR in review label May 29, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels May 29, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Jun 6, 2024
@melvin-bot melvin-bot bot changed the title [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method [HOLD for payment 2024-06-13] [LOW] [Performance] Add no-spread-in-reduce to avoid recreating array in reduce method Jun 6, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jun 6, 2024
Copy link

melvin-bot bot commented Jun 6, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Jun 6, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.79-11 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-06-13. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Jun 6, 2024

BugZero Checklist: The PR adding this new feature has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@DylanDylann] Please propose regression test steps to ensure the new feature will work correctly on production in further releases.
  • [@garrettmknight] Link the GH issue for creating/updating the regression test once above steps have been agreed upon.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jun 12, 2024
@garrettmknight
Copy link
Contributor

@DylanDylann you've been paid out - no regression test for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Daily KSv2 External Added to denote the issue can be worked on by a contributor NewFeature Something to build that is a new item.
Projects
Development

No branches or pull requests

5 participants