nodejs / nodejs/node

performance.now() should jump after sleep/suspend/hibernation

未关闭
#47,724 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

perf_hooks stale
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

Version

v18.14.2

Platform

Linux qubit 5.15.108-0-lts #1-Alpine SMP Fri, 21 Apr 2023 05:55:14 +0000 x86_64 GNU/Linux

Subsystem

perf_hooks

What steps will reproduce the bug?

In an interactive node session run:

function timeDelta() {
    // The delta should be approximately the same on each invocation (assuming the system time is unchanged).
    return Date.now() - performance.now();
};
const ref = timeDelta();
const before = timeDelta();

Now suspend and resume the machine / VM through whatever means. Then continue in the same node session:

const after = timeDelta();
console.log('BEFORE:', ref - before, 'AFTER:', ref - after);

Observe that the after value is incorrectly missing a number of seconds that matches the time the system was suspended. Eg. from my run:

BEFORE: -0.410888671875
AFTER: -7346.271728515625
How often does it reproduce? Is there a required condition?

100% (on Linux)

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

performance.now() is expected to jump with the realtime passed time while suspended according to the spec and https://github.com/w3c/hr-time/issues/115.

The https://github.com/mdn/content/issues/4713 issue also goes into detail on how the "Ticking During Sleep" applies to various platforms.

What do you see instead?

No jump during sleep. Eg. by using more suitable clock reference, as proposed implemented in https://github.com/libuv/libuv/issues/1674.

Additional information

The current performance.now() implementation is based on process.hrtime():

https://github.com/nodejs/node/blob/2ac5e9889aba461f5a54d320973d2574980d206b/lib/internal/perf/utils.js#L13-L16

This issue also seems to contain a lot of relevant context around a concrete problem: https://github.com/open-telemetry/opentelemetry-js/issues/852.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 lib/internal/perf/utils.js 和 perf_hooks 的实现入手,目前该实现以 process.hrtime() 为 performance.now() 的基础。在系统挂起或恢复前后,运行报告中的交互式 Node 会话。完成标准是:在 Linux 上,performance.now() 会加上挂起期间经过的时间,同时保持预期的 timeDelta 行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, linux, node.js
领域
performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。