performance.timerify(fn) behave inconsistently for sync/async functions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
master branch
Platform
All
Subsystem
perf_hooks
What steps will reproduce the bug?
function f1() { throw new Error() }
async function f2() { throw new Error() }
let h1 = perf_hooks.createHistogram()
let h2 = perf_hooks.createHistogram()
let g1 = perf_hooks.performance.timerify(f1, {histogram: h1})
let g2 = perf_hooks.performance.timerify(f2, {histogram: h2})
g1()
await g2()
h1.count === h2.count // expect true, actual false
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
Timerified functions should behave consistently for whether trigger histogram.record.
What do you see instead?
Currently, normal function would not trigger histogram.record if throw; but async function (or any function which return promise) would.
Additional information
Currently, the code is like if (typeof result?.finally === 'function') return result.finally(...). It should use result.then instead, so the behavior will consistent with non-thenable result. Even we want to always trigger histogram.record, we should not use finally because thenable is only require to have then method, not finally method.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the perf_hooks performance.timerify entry point and reproduce the supplied sync and async examples with histograms. Inspect how returned promises and thrown errors are handled; done means timerified sync and promise-returning functions have consistent histogram-recording behavior, including thenables.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100