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

Simplify/optimize map-reduce in useLoadData #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

baker-ling
Copy link

@baker-ling baker-ling commented Jan 10, 2025

Proposed changes

I saw the usage of map-reduce in useLoadData, and I think that those can be simplified by using Array.prototype.every and Array.prototype.some instead.

In addition to the simplification, this should provide some time and space optimization.

  • Time: .some() and .every() will terminate early (still O(n) though)
  • Space: should also be reduced from O(n) to O(1) because they do not build a new array like .map() does

Fixes #41

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@CLAassistant
Copy link

CLAassistant commented Jan 10, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@nthurow nthurow left a comment

Choose a reason for hiding this comment

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

It looks good to me! Do the tests work locally? Looks like we don't have those running as a PR check yet...

@baker-ling
Copy link
Author

All the tests in useLoadDatat.test.ts pass. Here's the report from running yarn jest useLoadData:
image

I haven't tried testing it in an application or in a performance test bed.

@NielsJPeschel
Copy link
Contributor

@baker-ling great contribution! Looks like there is a pending contributor license agreement that needs to be signed. Feel free to reach out if you have any questions!

@baker-ling
Copy link
Author

@baker-ling great contribution! Looks like there is a pending contributor license agreement that needs to be signed. Feel free to reach out if you have any questions!

@NielsJPeschel I think there's an issue with my GH account. I used my Optum email in git when I created the commit, but GH won't let me add my Optum email to my GH account.

I've completed the license agreement several times, so I think this email issue is preventing the PR condition from passing.

@baker-ling baker-ling marked this pull request as ready for review January 16, 2025 19:54
@baker-ling
Copy link
Author

@NielsJPeschel @nthurow I got the email and CLA issues sorted, so I think it's ready to go.

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.

Simplification and optimization opportunity in useLoadData
4 participants