Sitelet https://github.com/nodejs/node/issues/40623
Skip to content

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

Description

@acchou

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

Activity

  1. added
    performanceIssues and PRs related to the performance of Node.js.
    confirmed-bugIssues and PRs for confirmed bugs.
    on Oct 27, 2021
  2. targos commented on Oct 27, 2021

    @targos
    Member

    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.

  3. targos commented on Oct 27, 2021

    @targos
    Member
  4. added
    perf_hooksIssues and PRs related to the perf_hooks module and performance measurement APIs.
    and removed
    performanceIssues and PRs related to the performance of Node.js.
    on Oct 27, 2021
  5. hax commented on Apr 12, 2022

    @hax
    Contributor

    Caught by this bug today!

    Workaround: using arrow function.

  6. hax commented on Apr 18, 2022

    @hax
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.perf_hooksIssues and PRs related to the perf_hooks module and performance measurement APIs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions