Files
2nd/10_Wiki/Topic_Programming/Frontend/Timestamp Queries.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

173 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
id: wiki-2026-0508-timestamp-queries
title: Timestamp Queries
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [GPU Timestamp Queries, WebGPU Timestamp]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [webgpu, profiling, gpu, performance]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: javascript
framework: webgpu
---
# Timestamp Queries
## 매 한 줄
> **"매 nanosecond-precision GPU timing"**. WebGPU `timestamp-query` feature 의 GPU command buffer 안 의 timestamp 의 record 의 pass-level / draw-level latency 의 measure. 매 CPU `performance.now()` 의 GPU work 의 invisible 의 problem 의 solve, 매 2026 production profiling 의 standard.
## 매 핵심
### 매 동작 원리
- `timestamp` query type 의 query set 의 allocate.
- `pass.writeTimestamp(querySet, index)` 의 command buffer 의 inject.
- `commandEncoder.resolveQuerySet()` 의 GPU buffer 의 result 의 write.
- `mapAsync(GPUMapMode.READ)` 의 CPU 의 read — 매 BigInt64Array 의 nanosecond.
### 매 caveat
- 매 feature flag 의 `requiredFeatures: ['timestamp-query']` 의 device 의 request 의 require.
- 매 timestamp resolution 의 driver-dependent — 매 Chrome 의 100ns granularity 의 quantize (privacy).
- 매 GPU clock 의 CPU clock 의 unsynced — 매 absolute time 의 X.
- 매 query result 의 readback 의 1+ frame 의 lag — 매 real-time 의 X 의 best-effort.
### 매 응용
1. Render pass / compute pass 의 cost breakdown.
2. Shader optimization 의 before/after 의 measure.
3. Adaptive quality (timestamp 의 budget exceed 의 case 의 LOD drop).
4. Production telemetry 의 GPU bottleneck 의 detect.
## 💻 패턴
### Request feature
```javascript
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has('timestamp-query')) {
throw new Error('timestamp-query unsupported');
}
const device = await adapter.requestDevice({
requiredFeatures: ['timestamp-query'],
});
```
### Create query set + buffer
```javascript
const querySet = device.createQuerySet({ type: 'timestamp', count: 2 });
const queryBuffer = device.createBuffer({
size: 16, // 2 × u64
usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
});
const readBuffer = device.createBuffer({
size: 16,
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
});
```
### Inject into render pass
```javascript
const pass = encoder.beginRenderPass({
colorAttachments: [...],
timestampWrites: {
querySet,
beginningOfPassWriteIndex: 0,
endOfPassWriteIndex: 1,
},
});
pass.setPipeline(...);
pass.draw(...);
pass.end();
```
### Resolve + readback
```javascript
encoder.resolveQuerySet(querySet, 0, 2, queryBuffer, 0);
encoder.copyBufferToBuffer(queryBuffer, 0, readBuffer, 0, 16);
device.queue.submit([encoder.finish()]);
await readBuffer.mapAsync(GPUMapMode.READ);
const times = new BigInt64Array(readBuffer.getMappedRange());
const deltaNs = Number(times[1] - times[0]);
console.log(`Pass: ${(deltaNs / 1e6).toFixed(2)} ms`);
readBuffer.unmap();
```
### Three.js helper (r170+)
```javascript
const renderer = new THREE.WebGPURenderer({ trackTimestamp: true });
await renderer.init();
await renderer.renderAsync(scene, camera);
const renderTime = await renderer.resolveTimestampsAsync(THREE.TimestampQuery.RENDER);
console.log(`Render GPU: ${renderTime} ms`);
```
### Multiple pass labels
```javascript
const querySet = device.createQuerySet({ type: 'timestamp', count: 6 });
// pass A: index 0, 1
// pass B: index 2, 3
// pass C: index 4, 5
// 매 single resolve 의 batch
```
### Ring buffer 의 frame-over-frame
```javascript
class GpuProfiler {
constructor(device, frames = 4) {
this.queries = Array.from({ length: frames }, () => ({
set: device.createQuerySet({ type: 'timestamp', count: 2 }),
buf: device.createBuffer({ size: 16, usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST }),
pending: false,
}));
this.frame = 0;
}
acquire() {
const slot = this.queries[this.frame % this.queries.length];
this.frame++;
return slot;
}
}
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Coarse CPU+GPU 의 frame time | `performance.now()` + `requestAnimationFrame` |
| Per-pass GPU breakdown | timestamp-query |
| Shader instruction-level | Chrome WebGPU Inspector / RenderDoc |
| Production telemetry | timestamp-query + sampling (1% session) |
| WebGL fallback | EXT_disjoint_timer_query (degraded, deprecated) |
**기본값**: 매 WebGPU app 의 production 의 ring-buffered timestamp-query — 매 1-frame lag 의 accept.
## 🔗 Graph
- 부모: [[WebGPU]]
- Adjacent: [[performance.now]]
## 🤖 LLM 활용
**언제**: 매 GPU bottleneck 의 suspect, 매 pass-level cost 의 attribute 의 want.
**언제 X**: 매 CPU-bound problem (e.g. JS hot loop) — 매 DevTools profiler 의 use.
## ❌ 안티패턴
- **Sync `mapAsync` await 의 매 frame**: 매 pipeline stall — 매 ring buffer 의 use.
- **Single timestamp 의 absolute time 의 interpret**: 매 GPU clock 의 CPU 의 unsync.
- **100ns 의 below 의 reliance**: 매 browser 의 quantize — 매 noise.
- **Feature 의 unrequest 의 use**: 매 `device.createQuerySet` 의 throw.
- **Profiler 의 production 의 always-on**: 매 overhead minor 의 X 의 budget — 매 sample.
## 🧪 검증 / 중복
- Verified (W3C WebGPU spec §22 Queries, Chrome WebGPU release notes).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — query set, ring buffer, Three.js integration |