performance.now() should jump after sleep/suspend/hibernation
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.3k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với lib/internal/perf/utils.js và phần triển khai perf_hooks, hiện đang lấy process.hrtime() làm cơ sở cho performance.now(). Chạy phiên Node tương tác trong báo cáo quanh thời điểm hệ thống tạm ngưng hoặc tiếp tục. Được xem là hoàn tất khi performance.now() tăng trên Linux theo khoảng thời gian đã trôi qua trong lúc tạm ngưng, đồng thời vẫn giữ nguyên hành vi timeDelta như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, linux, node.js
- Lĩnh vực
- performance
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100