performance.timerify(fn) behave inconsistently for sync/async functions
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 perf_hooks performance.timerify 入口开始,使用直方图复现所提供的 sync 和 async 示例。检查如何处理返回的 promises 和抛出的错误;完成标准是:timerified sync 函数和返回 promises 的函数具有一致的直方图记录行为,包括 thenables。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- performance
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100