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

Performance issue with Date.toLocaleString in Node.js #48288

Closed
OguzhanUmutlu opened this issue Jun 1, 2023 · 3 comments
Closed

Performance issue with Date.toLocaleString in Node.js #48288

OguzhanUmutlu opened this issue Jun 1, 2023 · 3 comments

Comments

@OguzhanUmutlu
Copy link

Version

v19.8.1

Platform

Microsoft Windows NT 10.0.22621.0 x64

Subsystem

No response

What steps will reproduce the bug?

Run the following code in Node.js:

const date = new Date;

console.time();
const str = date.toLocaleString("en", {month: "short", day: "numeric"});
console.timeEnd();

console.log(str);

How often does it reproduce? Is there a required condition?

The issue reproduces consistently every time the code is executed.

What is the expected behavior? Why is that the expected behavior?

The expected behavior is that the execution time of date.toLocaleString should be reasonably fast, comparable to the performance observed in web browsers. It should be able to perform this relatively simple task efficiently.

What do you see instead?

When running the code in Node.js, the execution time of date.toLocaleString is observed to be significantly slower compared to running it in a web browser. The reported execution time is around 20-30 milliseconds, which is much longer than expected for such a straightforward operation. In contrast, when executed in a browser environment, the same code completes in approximately 0.3-0.4 milliseconds.

Additional information

No response

@OguzhanUmutlu
Copy link
Author

Note: It's the same no matter what are the options.(Tried with no options and got the same 20-30 milliseconds result)

@anonrig
Copy link
Member

anonrig commented Jun 1, 2023

Hi @OguzhanUmutlu, we are tracking a similar issue on nodejs/performance repository: nodejs/performance#47

@bnoordhuis
Copy link
Member

The test case is defective. V8 does some one-time setup the first time you call toLocaleString(). All subsequent calls take <1ms. Closing.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2023
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

No branches or pull requests

3 participants