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

perf(NODE-6126): improve Long.fromBigInt performance #681

Merged
merged 9 commits into from
May 7, 2024

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented May 2, 2024

Description

Refactor Long.fromBigInt to only use bit math, and refactor the Long constructor to have cleaner logic + remove Object.assign calls

What is changing?

Improve performance of Long.fromBigInt

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Use a more efficient algorithm for Long.fromBigInt

Release Highlight

Optimize performance of Long.fromBigInt

Internally fromBigInt was originally implemented using toString of the bigint value. Now, Long.fromBigInt has been refactored to use bitwise operations greatly improving performance.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@aditi-khare-mongoDB
Copy link
Contributor Author

aditi-khare-mongoDB commented May 2, 2024

Link to perf sheet

Chose BigInt Constructor because it is 7.2% better than the 10,000 iterations case for FromString/ToString, and 1.4% improvement from the BigInt Literal case

@aditi-khare-mongoDB aditi-khare-mongoDB marked this pull request as ready for review May 3, 2024 19:39
src/long.ts Outdated Show resolved Hide resolved
src/long.ts Outdated Show resolved Hide resolved
src/long.ts Outdated Show resolved Hide resolved
test/node/long.test.ts Outdated Show resolved Hide resolved
@nbbeeken nbbeeken self-assigned this May 6, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label May 6, 2024
Copy link
Contributor

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

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

comment about !, req changes for viz

@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels May 7, 2024
@nbbeeken nbbeeken merged commit 63eafcb into main May 7, 2024
5 checks passed
@nbbeeken nbbeeken deleted the NODE-6126/long-fromBigInt-perf branch May 7, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants