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.timerify doesn't return wrapped function's return value #40623

Closed
acchou opened this issue Oct 27, 2021 · 4 comments · Fixed by #43330
Closed

performance.timerify doesn't return wrapped function's return value #40623

acchou opened this issue Oct 27, 2021 · 4 comments · Fixed by #43330
Labels
confirmed-bug Issues with confirmed bugs. perf_hooks Issues and PRs related to the implementation of the Performance Timing API.

Comments

@acchou
Copy link

acchou commented Oct 27, 2021

Version

v16.13.0

Platform

Darwin AC-MacBook-Pro.hsd1.ca.comcast.net 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin

Subsystem

performance

What steps will reproduce the bug?

const perf = performance.timerify(function foo() {
    let sum = 0;
    for (let i = 0; i < 1000000; i++) {
        sum += i;
    }
    return sum;
});

const result = perf();
console.log(result);

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

This reproduces deterministically.

What is the expected behavior?

A number should be printed

What do you see instead?

foo {}

Additional information

No response

@targos targos added performance Issues and PRs related to the performance of Node.js. confirmed-bug Issues with confirmed bugs. labels Oct 27, 2021
@targos
Copy link
Member

targos commented Oct 27, 2021

Seems like a bug to me indeed. The function is called as a constructor and it returns an instance of it instead of the true return value.

@targos
Copy link
Member

targos commented Oct 27, 2021

/cc @jasnell

@Mesteery Mesteery added perf_hooks Issues and PRs related to the implementation of the Performance Timing API. and removed performance Issues and PRs related to the performance of Node.js. labels Oct 27, 2021
@hax
Copy link
Contributor

hax commented Apr 12, 2022

Caught by this bug today!

Workaround: using arrow function.

@hax
Copy link
Contributor

hax commented Apr 18, 2022

Note, node 14 do not have this bug. So it's the bug of rewriting it from C++ to JS :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. perf_hooks Issues and PRs related to the implementation of the Performance Timing API.
Projects
None yet
4 participants