[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,66 +2,156 @@
|
||||
id: wiki-2026-0508-high-resolution-time
|
||||
title: High Resolution Time
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-05BDE3]
|
||||
aliases: [performance.now, Monotonic Time, HR Time, Hi-Res Timer]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [web-api, performance, timing, security]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - High Re[[Solution|Solution]] Time"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: JavaScript/C
|
||||
framework: W3C-HRTime/POSIX
|
||||
---
|
||||
|
||||
# [[High Resolution Time|High Resolution Time]]
|
||||
# High Resolution Time
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> High Resolution Time(HR-time)은 웹 브라우저 환경에서 고정밀로 시간을 측정하기 위해 사용되는 사양(Spec) 및 메커니즘을 의미한다. 그러나 [[Spectre|Spectre]]나 Meltdown 같은 타이밍 기반의 사이드 채널 공격을 방지하기 위해 이 사양은 `performance.now()`와 같은 측정 도구의 해상도를 의도적으로 제한(Coarsening)하고 있다. 최근 [[WebGPU|WebGPU]]의 타임스탬프 쿼리 기능 역시 이 HR-time 사양의 기준을 참조하여 보안과 성능 측정의 균형을 맞추고 있다.
|
||||
## 매 한 줄
|
||||
> **"매 sub-millisecond 정밀도의 매 monotonic clock"**. W3C High Resolution Time spec — `performance.now()` 가 매 `Date.now()` 의 ms 한계 + wall-clock jitter 를 매 해결. 매 Spectre 후 — 모든 brower 가 매 timer 정밀도를 매 100µs ~ 1ms 로 매 reduce + cross-origin isolation 으로 매 5µs 회복.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
- **보안 취약점에 따른 정밀도 제한 (Coarsening):** Spectre 및 Meltdown과 같은 캐시 사이드 채널 공격은 서브 마이크로초(sub-microsecond) 수준의 미세한 타이밍 차이를 이용해 메모리 접근 패턴을 파악한다 [1]. 이를 막기 위해 브라우저 엔진들은 `performance.now()`와 같은 타이머의 정밀도를 시스템의 격리 상태(isolation status)에 따라 1ms 또는 100 마이크로초(µs) 단위로 낮추었다 [1].
|
||||
- **지터(Jitter)의 도입:** 일부 브라우저 구현에서는 반환되는 시간 값에 작고 무작위적인 변동인 '지터(Jitter)'를 추가하여, 공격자가 통계적 평균을 통해 고정밀 시계를 재구성하는 것을 방지한다 [1].
|
||||
- **컨텍스트에 따른 해상도 차이:** High Resolution Time 사양(HR-time spec)은 크로스 오리진 격리(cross-origin isolated) 컨텍스트에서는 5µs로, 격리되지 않은(non-isolated) 컨텍스트에서는 100µs(또는 구현이 선호하는 더 거친 수준)로 해상도를 제한하도록 권장한다 [2].
|
||||
- **WebGPU 타임스탬프 쿼리([[Timestamp Queries|Timestamp Queries]]) 연동:** WebGPU 환경에서 GPU 연산 소요 시간을 측정하는 타임스탬프 쿼리 기능도 타이밍 공격의 위험이 있어 정밀도 조정이 필요했다 [3-5]. 이에 따라 GPU for the Web 커뮤니티 그룹은 타임스탬프 값을 HR-time 사양을 참조하여 격리 여부와 무관하게 비격리 해상도 기준인 100µs로 제한([[Quantization|Quantization]])하기로 합의하여 일관성 있는 보안 조치를 적용하였다 [6-8].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Graphics & Performance 분야의 자동 자산화 수행.
|
||||
### 매 vs Date.now
|
||||
- `Date.now()`: wall clock, ms 단위, NTP 으로 점프 가능 (음수 delta!).
|
||||
- `performance.now()`: monotonic, fractional ms, navigation start 기준.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[Spectre and Meltdown|Spectre and Meltdown]], WebGPU Timestamp Queries, performance.now()
|
||||
- **Projects/Contexts:** High Resolution Time spec (
|
||||
- **Contradictions/Notes:** 소스 내에 특별한 모순은 없으나, High Resolution Time의 정밀도는 적용되는 보안 격리 환경(Isolated vs Non-isolated) 및 브라우저 엔진의 방어 메커니즘에 따라 5µs, 100µs, 1ms 등 상이하게 적용된다는 점을 유의해야 한다 [1, 2].
|
||||
### 매 timer attack mitigation
|
||||
- Spectre/Meltdown (2018) → 매 brower 가 timer fuzz/round.
|
||||
- Default: 100µs ~ 1ms rounding + jitter.
|
||||
- COOP+COEP (cross-origin isolated) 시 → 5µs 정밀 + `SharedArrayBuffer`.
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
### 매 응용
|
||||
1. Animation frame timing (`rAF` callback).
|
||||
2. Performance profiling (`User Timing API`).
|
||||
3. WebGL/WebGPU frame budget tracking.
|
||||
4. Audio scheduling (`AudioContext.currentTime` 동기).
|
||||
|
||||
---
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Basic timing
|
||||
```javascript
|
||||
const t0 = performance.now();
|
||||
heavyWork();
|
||||
const elapsed = performance.now() - t0;
|
||||
console.log(`took ${elapsed.toFixed(3)} ms`); // 12.345 ms
|
||||
```
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
### User Timing API (DevTools 표시)
|
||||
```javascript
|
||||
performance.mark('render-start');
|
||||
render();
|
||||
performance.mark('render-end');
|
||||
performance.measure('render', 'render-start', 'render-end');
|
||||
const [m] = performance.getEntriesByName('render');
|
||||
console.log(m.duration);
|
||||
// Visible in Chrome DevTools Performance panel.
|
||||
```
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Frame budget tracker
|
||||
```javascript
|
||||
let lastT = performance.now();
|
||||
function frame(now) {
|
||||
const dt = now - lastT;
|
||||
lastT = now;
|
||||
if (dt > 16.7) console.warn(`slow frame: ${dt.toFixed(1)}ms`);
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
requestAnimationFrame(frame);
|
||||
```
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
### Cross-origin isolated (max precision)
|
||||
```http
|
||||
# Server response headers
|
||||
Cross-Origin-Opener-Policy: same-origin
|
||||
Cross-Origin-Embedder-Policy: require-corp
|
||||
```
|
||||
```javascript
|
||||
if (crossOriginIsolated) {
|
||||
// performance.now() granularity ~5µs
|
||||
// SharedArrayBuffer 가능
|
||||
}
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### POSIX equivalent (C)
|
||||
```c
|
||||
#include <time.h>
|
||||
struct timespec t0, t1;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t0);
|
||||
do_work();
|
||||
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||
double elapsed_ns = (t1.tv_sec - t0.tv_sec) * 1e9 + (t1.tv_nsec - t0.tv_nsec);
|
||||
```
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
### Rust std (cross-platform)
|
||||
```rust
|
||||
use std::time::Instant;
|
||||
let t0 = Instant::now();
|
||||
heavy_work();
|
||||
println!("took {:?}", t0.elapsed()); // sub-ns precision on modern HW
|
||||
```
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
### Debounce slow timers
|
||||
```javascript
|
||||
// If you measure dt < 0.1ms repeatedly, you're in fuzzed timer mode.
|
||||
function isolatedPrecisionAvailable() {
|
||||
const samples = Array.from({length: 100}, () => {
|
||||
const a = performance.now(); const b = performance.now();
|
||||
return b - a;
|
||||
});
|
||||
return samples.some(d => d > 0 && d < 0.05); // sub-100µs visible
|
||||
}
|
||||
```
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Wall-clock event log | `Date.now()` / `Date.toISOString()` |
|
||||
| Profile / micro-bench | `performance.now()` + User Timing |
|
||||
| Frame loop | rAF callback timestamp (매 monotonic) |
|
||||
| Audio sync | `AudioContext.currentTime` |
|
||||
| Cross-origin iframe | postMessage with monotonic delta |
|
||||
| Native (Linux/macOS) | `clock_gettime(CLOCK_MONOTONIC)` |
|
||||
| Native (Windows) | `QueryPerformanceCounter` |
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
**기본값**: Duration 측정엔 매 monotonic. 매 Date 는 user-facing timestamp 만.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Web Performance APIs]] · [[Time Measurement]]
|
||||
- 변형: [[Performance Timeline]] · [[Long Tasks API]] · [[Event Timing API]]
|
||||
- 응용: [[Core Web Vitals]] · [[User Timing]] · [[Animation Frame]]
|
||||
- Adjacent: [[Spectre]] · [[Cross-Origin Isolation]] · [[SharedArrayBuffer]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: 성능 측정 코드 작성, profiling, frame budget 분석.
|
||||
**언제 X**: Persistent timestamp / event log 매 wall-clock 필요 시.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **`Date.now()` for delta**: NTP step 시 음수 / 점프 가능.
|
||||
- **`new Date()` 매 hot loop**: allocation cost + ms 한계.
|
||||
- **Assuming sub-ms precision**: COOP/COEP 없으면 매 1ms rounded.
|
||||
- **Cross-origin worker timing**: postMessage 의 매 ms 단위 transmit overhead.
|
||||
- **`setTimeout` 으로 정밀 timing**: 매 4ms+ minimum, jittery.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (W3C HR Time Level 3, MDN performance.now, Chrome timer reduction notes).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — performance.now + Spectre mitigation + COOP/COEP 5µs |
|
||||
|
||||
Reference in New Issue
Block a user