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_hooks: fix rangeerror #54772

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

benjamingr
Copy link
Member

@benjamingr benjamingr commented Sep 4, 2024

Fixes: #54768

A proposed ad-hoc fix for that issue.

As mentioned there I'm not sure how to test since it's implementation detail #54768 (comment)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/tsc

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Sep 4, 2024
@@ -106,6 +106,7 @@ performance of code in Node.js.

* Methods that mutate the internal state of arrays:
* `ArrayPrototypePush`
* `ArrayPrototypePushApply`: also fails with a RangeError on large arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

That’s not the correct place to document, as this is not a performance issue IIUC

@aduh95
Copy link
Contributor

aduh95 commented Sep 4, 2024

As a test, I think it makes sense to use the code from the issue.

@@ -6,7 +6,6 @@ const {
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
ArrayPrototypePush,
ArrayPrototypePushApply,
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR: Can we eventually add an eslint rule to avoid using this?

Copy link
Contributor

Choose a reason for hiding this comment

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

What would be the rational for such a rule?

Copy link
Member

Choose a reason for hiding this comment

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

V8 has a hard limit on function argument count and without explicitly checking the number, it is easy to make a mistake?

Copy link
Member

Choose a reason for hiding this comment

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

Depending on use it can also be significantly faster. In undici we batch the .apply calls in our data url parser for performance: https://github.com/nodejs/undici/blob/89a46dd54f7d7db7513c435fac8042769ee9e9b5/lib/web/fetch/data-url.js#L657-L674

ArrayPrototypePushApply(this.#buffer, entries);
for (let i = 0; i < entries.length; i++) {
ArrayPrototypePush(this.#buffer, entries[i]);
}
Copy link
Member

Choose a reason for hiding this comment

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

I understand the necessary fix but we should benchmark this to make sure it's not too much of a regression. Might make sense to split entries up and still use ...PushApply with smaller, safer chunks

@RedYetiDev RedYetiDev added the perf_hooks Issues and PRs related to the implementation of the Performance Timing API. label Oct 15, 2024
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 15, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 15, 2024
@nodejs-github-bot
Copy link
Collaborator

@marco-ippolito marco-ippolito added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 2, 2024
@marco-ippolito
Copy link
Member

Actually this is technically landable but there are some unresolved conversation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. perf_hooks Issues and PRs related to the implementation of the Performance Timing API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

performance.getEntries and performance.getEntriesByName cause call stack size to be exceeded
9 participants