performance.now() should jump after sleep/suspend/hibernation
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
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():
This issue also seems to contain a lot of relevant context around a concrete problem: https://github.com/open-telemetry/opentelemetry-js/issues/852.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/internal/perf/utils.js と perf_hooks の実装から始めます。現在は performance.now() の基準を process.hrtime() にしています。システムのサスペンドまたはレジュームを挟んで、レポートにあるインタラクティブな Node セッションを実行します。Linux 上で、サスペンド中に経過した時間の分だけ performance.now() が進み、期待される timeDelta の挙動も維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, linux, node.js
- 領域
- performance
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100