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

refactor(NODE-6616): short circuit EJSON stringifying #4360

Closed
wants to merge 10 commits into from

Conversation

nbbeeken
Copy link
Contributor

Description

What is changing?

Is there new documentation needed for these changes?

What is the motivation for this change?

Release Highlight

Fill in title or leave empty for no highlight

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

@nbbeeken nbbeeken changed the title NODE-6616-ejson-max-len refactor(NODE-6616): short circuit EJSON stringifying Dec 20, 2024
@nbbeeken nbbeeken force-pushed the NODE-6616-ejson-max-len branch from 4bc5283 to 9e2721f Compare December 20, 2024 22:48
@nbbeeken nbbeeken force-pushed the NODE-6616-ejson-max-len branch from 9e2721f to 0e83e17 Compare January 2, 2025 15:33
if (typeof value === 'string') {
currentLength += value.length;
} else if (typeof value === 'number' || typeof value === 'bigint') {
currentLength += 20;
Copy link
Contributor

@baileympearson baileympearson Jan 3, 2025

Choose a reason for hiding this comment

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

where is this lengths coming from? wouldn't the length of numbers be dependent on the actual number being stringified (ex: 0 would be 1, but 1.1234 would be 6?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes correct they would depend on the value. I can improve this to calculate the number of digits from the value.

Generally, the lengths here are approximations when we can't determine the length without actually stringifying the value in an attempt to avoid paying that potentially expensive cost. With a better implementation, we should always get a bit over maxLen returned to us and then slicing ensures we actually hit the target.

@nbbeeken nbbeeken force-pushed the NODE-6616-ejson-max-len branch from 0e83e17 to d588ada Compare January 15, 2025 22:41
@W-A-James W-A-James force-pushed the NODE-6616-ejson-max-len branch from 27d615f to 31f941e Compare January 22, 2025 21:03
if (v.scope == null) {
currentLength += v.code.length + 10 + 2;
} else {
// Ignoring actual scope object
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to account for the scope?

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