nodejs / nodejs/node

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

Ouverte
#47,724 9 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

perf_hooks stale
Langage dominant
JavaScript
Étoiles
122k
Forks
37.3k
Merge moyen
4 j 2 h
PR mergées (30 j)
283

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par lib/internal/perf/utils.js et l’implémentation de perf_hooks, qui fonde actuellement performance.now() sur process.hrtime(). Exécutez la session interactive Node du rapport autour d’une mise en veille ou d’une reprise du système. C’est terminé lorsque performance.now() avance sous Linux de la durée de la mise en veille écoulée, tout en préservant le comportement attendu de timeDelta.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
javascript, linux, node.js
Domaine
performance
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Active
Clarté
Plutôt claire
Accessibilité débutants
52/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.