@umituz/react-native-ai-gemini-provider 1.14.28 → 1.14.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/package.json +41 -3
  2. package/src/domain/README.md +232 -0
  3. package/src/domain/constants/README.md +191 -0
  4. package/src/domain/entities/README.md +238 -0
  5. package/src/infrastructure/README.md +252 -0
  6. package/src/infrastructure/cache/CACHE_SYSTEM.md +213 -0
  7. package/src/infrastructure/cache/README.md +213 -0
  8. package/src/infrastructure/content/CONTENT_BUILDER.md +175 -0
  9. package/src/infrastructure/content/README.md +175 -0
  10. package/src/infrastructure/interceptors/README.md +226 -0
  11. package/src/infrastructure/interceptors/REQUEST_INTERCEPTORS.md +171 -0
  12. package/src/infrastructure/job/JOB_MANAGER.md +174 -0
  13. package/src/infrastructure/job/README.md +194 -0
  14. package/src/infrastructure/response/README.md +187 -0
  15. package/src/infrastructure/response/RESPONSE_FORMATTER.md +185 -0
  16. package/src/infrastructure/services/CORE_CLIENT_SERVICE.md +202 -0
  17. package/src/infrastructure/services/FEATURE_MODEL_SELECTOR_SERVICE.md +206 -0
  18. package/src/infrastructure/services/GENERATION_EXECUTOR_SERVICE.md +176 -0
  19. package/src/infrastructure/services/IMAGE_EDIT_SERVICE.md +169 -0
  20. package/src/infrastructure/services/IMAGE_GENERATION_SERVICE.md +166 -0
  21. package/src/infrastructure/services/JOB_PROCESSOR_SERVICE.md +174 -0
  22. package/src/infrastructure/services/PROVIDER_INITIALIZER_SERVICE.md +176 -0
  23. package/src/infrastructure/services/README.md +233 -0
  24. package/src/infrastructure/services/RETRY_SERVICE.md +178 -0
  25. package/src/infrastructure/services/STREAMING_SERVICE.md +166 -0
  26. package/src/infrastructure/services/STRUCTURED_TEXT_SERVICE.md +175 -0
  27. package/src/infrastructure/services/TEXT_GENERATION_SERVICE.md +160 -0
  28. package/src/infrastructure/services/VEO_HTTP_CLIENT_SERVICE.md +179 -0
  29. package/src/infrastructure/services/VEO_POLLING_SERVICE.md +173 -0
  30. package/src/infrastructure/services/VIDEO_DOWNLOADER_SERVICE.md +166 -0
  31. package/src/infrastructure/services/VIDEO_ERROR_HANDLER_SERVICE.md +185 -0
  32. package/src/infrastructure/services/VIDEO_GENERATION_SERVICE.md +176 -0
  33. package/src/infrastructure/services/VIDEO_URL_EXTRACTOR_SERVICE.md +186 -0
  34. package/src/infrastructure/services/gemini-provider.ts +9 -2
  35. package/src/infrastructure/telemetry/README.md +203 -0
  36. package/src/infrastructure/telemetry/TELEMETRY_SYSTEM.md +200 -0
  37. package/src/infrastructure/utils/DATA_TRANSFORMER_UTILS.md +175 -0
  38. package/src/infrastructure/utils/ERROR_MAPPER.md +170 -0
  39. package/src/infrastructure/utils/ERROR_UTILITIES.md +208 -0
  40. package/src/infrastructure/utils/IMAGE_PREPARER_UTILS.md +185 -0
  41. package/src/infrastructure/utils/INPUT_BUILDERS.md +214 -0
  42. package/src/infrastructure/utils/MODEL_VALIDATION_UTILS.md +189 -0
  43. package/src/infrastructure/utils/PERFORMANCE_UTILITIES.md +477 -0
  44. package/src/infrastructure/utils/PERFORMANCE_UTILS.md +219 -0
  45. package/src/infrastructure/utils/README.md +289 -0
  46. package/src/presentation/README.md +187 -0
  47. package/src/presentation/hooks/README.md +188 -0
  48. package/src/presentation/hooks/USE_GEMINI_HOOK.md +226 -0
  49. package/src/providers/README.md +247 -0
@@ -0,0 +1,477 @@
1
+ # Performance Utilities
2
+
3
+ Performans izleme ve optimizasyon araçları. Operasyon sürelerini ölçmek, debouncing ve throttling yapmak için kullanılır.
4
+
5
+ ## Dosya
6
+
7
+ [`performance.util.ts`](./performance.util.ts)
8
+
9
+ ## Fonksiyonlar
10
+
11
+ ### `measureAsync(operation, metadata?)`
12
+
13
+ Asenkron operasyonun süresini ölçer.
14
+
15
+ **Parametreler:**
16
+ - `operation`: `() => Promise<T>` - Ölçülecek operasyon
17
+ - `metadata?`: `Record<string, unknown>` - Ek metadata (opsiyonel)
18
+
19
+ **Dönen değer:** `Promise<{ result: T; duration: number }>`
20
+
21
+ **Örnek:**
22
+
23
+ ```typescript
24
+ import { measureAsync } from '@umituz/react-native-ai-gemini-provider';
25
+
26
+ const { result, duration } = await measureAsync(
27
+ async () => {
28
+ return await fetch('https://api.example.com/data');
29
+ },
30
+ { operation: 'fetch-data' }
31
+ );
32
+
33
+ console.log(`Sonuç:`, result);
34
+ console.log(`Süre: ${duration}ms`);
35
+ ```
36
+
37
+ ### `measureSync(operation, metadata?)`
38
+
39
+ Senkron operasyonun süresini ölçer.
40
+
41
+ **Parametreler:**
42
+ - `operation`: `() => T` - Ölçülecek operasyon
43
+ - `metadata?`: `Record<string, unknown>` - Ek metadata (opsiyonel)
44
+
45
+ **Dönen değer:** `{ result: T; duration: number }`
46
+
47
+ **Örnek:**
48
+
49
+ ```typescript
50
+ import { measureSync } from '@umituz/react-native-ai-gemini-provider';
51
+
52
+ const { result, duration } = measureSync(
53
+ () => {
54
+ return expensiveCalculation();
55
+ },
56
+ { operation: 'calculation' }
57
+ );
58
+
59
+ console.log(`Sonuç: ${result}, Süre: ${duration}ms`);
60
+ ```
61
+
62
+ ### `debounce(func, wait)`
63
+
64
+ Debounce fonksiyonu oluşturur. Fonksiyon çağrıları arasındaki bekleme süresini kontrol eder.
65
+
66
+ **Parametreler:**
67
+ - `func`: `T` - Debounce edilecek fonksiyon
68
+ - `wait`: `number` - Bekleme süresi (ms)
69
+
70
+ **Dönen değer:** Debounce edilmiş fonksiyon
71
+
72
+ **Örnek:**
73
+
74
+ ```typescript
75
+ import { debounce } from '@umituz/react-native-ai-gemini-provider';
76
+
77
+ const debouncedSearch = debounce((query: string) => {
78
+ console.log('Aranıyor:', query);
79
+ }, 300);
80
+
81
+ debouncedSearch('test'); // 300ms bekler
82
+ debouncedSearch('test2'); // Önceki iptal olur, 300ms bekler
83
+ // 300ms sonra: 'Aranıyor: test2'
84
+ ```
85
+
86
+ ### `throttle(func, limit)`
87
+
88
+ Throttle fonksiyonu oluşturur. Fonksiyonun maksimum çağrılma sıklığını sınırlar.
89
+
90
+ **Parametreler:**
91
+ - `func`: `T` - Throttle edilecek fonksiyon
92
+ - `limit`: `number` - Minimum çağrılma aralığı (ms)
93
+
94
+ **Dönen değer:** Throttle edilmiş fonksiyon
95
+
96
+ **Örnek:**
97
+
98
+ ```typescript
99
+ import { throttle } from '@umituz/react-native-ai-gemini-provider';
100
+
101
+ const throttledScroll = throttle(() => {
102
+ console.log('Scroll olayı');
103
+ }, 100);
104
+
105
+ // Her 100ms'de en fazla bir kez çalışır
106
+ window.addEventListener('scroll', throttledScroll);
107
+ ```
108
+
109
+ ## Sınıflar
110
+
111
+ ### PerformanceTimer
112
+
113
+ Performans zamanlayıcısı.
114
+
115
+ ```typescript
116
+ class PerformanceTimer {
117
+ constructor(metadata?: Record<string, unknown>)
118
+
119
+ stop(): number
120
+ get duration: number
121
+ getMetrics(): PerformanceMetrics
122
+ get isRunning(): boolean
123
+ }
124
+ ```
125
+
126
+ #### Kullanım
127
+
128
+ ```typescript
129
+ import { PerformanceTimer } from '@umituz/react-native-ai-gemini-provider';
130
+
131
+ const timer = new PerformanceTimer({ operation: 'data-processing' });
132
+
133
+ // İşlem yap
134
+ processData();
135
+
136
+ const duration = timer.stop();
137
+ console.log(`Süre: ${duration}ms`);
138
+ console.log(`Çalışıyor mu? ${timer.isRunning}`); // false
139
+ ```
140
+
141
+ ### PerformanceTracker
142
+
143
+ Performans takipçisi. Birden fazla operasyonun istatistiklerini tutar.
144
+
145
+ ```typescript
146
+ class PerformanceTracker {
147
+ record(operation: string, duration: number): void
148
+ getStats(operation: string): Stats | null
149
+ getAllStats(): Record<string, Stats>
150
+ clear(): void
151
+ }
152
+
153
+ interface Stats {
154
+ count: number;
155
+ avg: number;
156
+ min: number;
157
+ max: number;
158
+ }
159
+ ```
160
+
161
+ #### Kullanım
162
+
163
+ ```typescript
164
+ import { performanceTracker } from '@umituz/react-native-ai-gemini-provider';
165
+
166
+ // Operasyon sürelerini kaydet
167
+ performanceTracker.record('api-call', 150);
168
+ performanceTracker.record('api-call', 200);
169
+ performanceTracker.record('api-call', 175);
170
+
171
+ // İstatistikleri al
172
+ const stats = performanceTracker.getStats('api-call');
173
+ console.log(stats);
174
+ // { count: 3, avg: 175, min: 150, max: 200 }
175
+
176
+ // Tüm istatistikleri al
177
+ const allStats = performanceTracker.getAllStats();
178
+ console.log(allStats);
179
+ // { 'api-call': { count: 3, avg: 175, min: 150, max: 200 } }
180
+
181
+ // Temizle
182
+ performanceTracker.clear();
183
+ ```
184
+
185
+ ## Global Instance
186
+
187
+ ```typescript
188
+ export const performanceTracker = new PerformanceTracker();
189
+ ```
190
+
191
+ ## Kullanım Örnekleri
192
+
193
+ ### API Çağrısı Ölçümü
194
+
195
+ ```typescript
196
+ import { measureAsync, performanceTracker } from '@umituz/react-native-ai-gemini-provider';
197
+
198
+ async function fetchUserData(userId: string) {
199
+ const { result, duration } = await measureAsync(
200
+ () => fetch(`/api/users/${userId}`).then(r => r.json()),
201
+ { operation: 'fetch-user', userId }
202
+ );
203
+
204
+ // Performans tracker'a kaydet
205
+ performanceTracker.record('fetch-user', duration);
206
+
207
+ return result;
208
+ }
209
+ ```
210
+
211
+ ### Batch İşlem Performansı
212
+
213
+ ```typescript
214
+ import { measureSync } from '@umituz/react-native-ai-gemini-provider';
215
+
216
+ function processBatch(items: any[]) {
217
+ const { result, duration } = measureSync(
218
+ () => items.map(item => processItem(item)),
219
+ { operation: 'batch-process', itemCount: items.length }
220
+ );
221
+
222
+ console.log(`${items.length} öğe ${duration}ms'de işlendi`);
223
+ console.log(`Ortalama: ${(duration / items.length).toFixed(2)}ms per item`);
224
+
225
+ return result;
226
+ }
227
+ ```
228
+
229
+ ### Arama Input'u Debounce
230
+
231
+ ```typescript
232
+ import { debounce } from '@umituz/react-native-ai-gemini-provider';
233
+
234
+ function SearchInput() {
235
+ const [query, setQuery] = useState('');
236
+
237
+ // Debounce ile arama
238
+ const debouncedSearch = debounce(async (searchQuery: string) => {
239
+ const results = await searchAPI(searchQuery);
240
+ setResults(results);
241
+ }, 500);
242
+
243
+ const handleChange = (text: string) => {
244
+ setQuery(text);
245
+ debouncedSearch(text);
246
+ };
247
+
248
+ return (
249
+ <TextInput
250
+ value={query}
251
+ onChangeText={handleChange}
252
+ placeholder="Ara..."
253
+ />
254
+ );
255
+ }
256
+ ```
257
+
258
+ ### Scroll Olayı Throttle
259
+
260
+ ```typescript
261
+ import { throttle } from '@umituz/react-native-ai-gemini-provider';
262
+
263
+ function InfiniteScrollList() {
264
+ const handleScroll = throttle(() => {
265
+ // Scroll sonuna yaklaştıkça daha fazla veri yükle
266
+ loadMoreData();
267
+ }, 500);
268
+
269
+ return (
270
+ <ScrollView onScroll={handleScroll}>
271
+ {/* İçerik */}
272
+ </ScrollView>
273
+ );
274
+ }
275
+ ```
276
+
277
+ ### Kompleks Operasyon Takibi
278
+
279
+ ```typescript
280
+ import { PerformanceTimer } from '@umituz/react-native-ai-gemini-provider';
281
+
282
+ async function complexOperation() {
283
+ const timers = {
284
+ step1: new PerformanceTimer({ step: 'step1' }),
285
+ step2: new PerformanceTimer({ step: 'step2' }),
286
+ step3: new PerformanceTimer({ step: 'step3' }),
287
+ };
288
+
289
+ // Adım 1
290
+ const result1 = await step1();
291
+ timers.step1.stop();
292
+ console.log(`Adım 1: ${timers.step1.duration}ms`);
293
+
294
+ // Adım 2
295
+ const result2 = await step2();
296
+ timers.step2.stop();
297
+ console.log(`Adım 2: ${timers.step2.duration}ms`);
298
+
299
+ // Adım 3
300
+ const result3 = await step3();
301
+ timers.step3.stop();
302
+ console.log(`Adım 3: ${timers.step3.duration}ms`);
303
+
304
+ const totalDuration = timers.step1.duration + timers.step2.duration + timers.step3.duration;
305
+ console.log(`Toplam: ${totalDuration}ms`);
306
+ }
307
+ ```
308
+
309
+ ### Performance Dashboard
310
+
311
+ ```typescript
312
+ import { performanceTracker } from '@umituz/react-native-ai-gemini-provider';
313
+
314
+ function PerformanceDashboard() {
315
+ const stats = performanceTracker.getAllStats();
316
+
317
+ return (
318
+ <View>
319
+ <Text>Performans İstatistikleri</Text>
320
+ {Object.entries(stats).map(([operation, stat]) => (
321
+ <View key={operation}>
322
+ <Text>{operation}</Text>
323
+ <Text>Count: {stat.count}</Text>
324
+ <Text>Average: {stat.avg.toFixed(0)}ms</Text>
325
+ <Text>Min: {stat.min}ms</Text>
326
+ <Text>Max: {stat.max}ms</Text>
327
+ </View>
328
+ ))}
329
+ </View>
330
+ );
331
+ }
332
+ ```
333
+
334
+ ### Conditional Measurement
335
+
336
+ ```typescript
337
+ import { measureAsync } from '@umituz/react-native-ai-gemini-provider';
338
+
339
+ async function conditionalFetch(shouldMeasure: boolean) {
340
+ if (shouldMeasure) {
341
+ // Development modunda ölç
342
+ const { result, duration } = await measureAsync(
343
+ () => fetch('https://api.example.com/data'),
344
+ { operation: 'fetch-data' }
345
+ );
346
+
347
+ if (__DEV__) {
348
+ console.log(`API call took ${duration}ms`);
349
+ }
350
+
351
+ return result;
352
+ } else {
353
+ // Production'da direkt çağır
354
+ return await fetch('https://api.example.com/data');
355
+ }
356
+ }
357
+ ```
358
+
359
+ ### Memory Monitoring
360
+
361
+ ```typescript
362
+ import { measureAsync } from '@umituz/react-native-ai-gemini-provider';
363
+
364
+ async function monitoredOperation() {
365
+ const startMemory = performance.memory?.usedJSHeapSize;
366
+
367
+ const { result, duration } = await measureAsync(async () => {
368
+ return await heavyOperation();
369
+ });
370
+
371
+ const endMemory = performance.memory?.usedJSHeapSize;
372
+ const memoryUsed = endMemory && startMemory
373
+ ? endMemory - startMemory
374
+ : 0;
375
+
376
+ console.log(`Süre: ${duration}ms`);
377
+ console.log(`Memory: ${(memoryUsed / 1024 / 1024).toFixed(2)}MB`);
378
+
379
+ return result;
380
+ }
381
+ ```
382
+
383
+ ### Performance Alerts
384
+
385
+ ```typescript
386
+ import { performanceTracker } from '@umituz/react-native-ai-gemini-provider';
387
+
388
+ // Performance monitoring
389
+ setInterval(() => {
390
+ const stats = performanceTracker.getAllStats();
391
+
392
+ Object.entries(stats).forEach(([operation, stat]) => {
393
+ // Yavaş operasyon kontrolü
394
+ if (stat.avg > 5000) {
395
+ console.warn(`⚠️ Yavaş operasyon: ${operation} (avg: ${stat.avg.toFixed(0)}ms)`);
396
+ // Alert gönder
397
+ sendAlert({
398
+ type: 'slow-operation',
399
+ operation,
400
+ avgTime: stat.avg,
401
+ });
402
+ }
403
+
404
+ // Çok değişken (min-max farkı büyük)
405
+ const variance = stat.max - stat.min;
406
+ if (variance > 3000) {
407
+ console.warn(`⚠️ Dengesiz operasyon: ${operation} (min: ${stat.min}ms, max: ${stat.max}ms)`);
408
+ }
409
+ });
410
+ }, 60000); // Her dakika
411
+ ```
412
+
413
+ ## PerformanceMetrics
414
+
415
+ ```typescript
416
+ interface PerformanceMetrics {
417
+ duration: number;
418
+ timestamp: number;
419
+ metadata?: Record<string, unknown>;
420
+ }
421
+ ```
422
+
423
+ ## Best Practices
424
+
425
+ ### 1. Measure kullanın
426
+
427
+ ```typescript
428
+ // ✅ İyi - measureAsync kullan
429
+ const { result, duration } = await measureAsync(() => apiCall());
430
+
431
+ // ❌ Kötü - Manuel ölçüm
432
+ const start = Date.now();
433
+ const result = await apiCall();
434
+ const duration = Date.now() - start;
435
+ ```
436
+
437
+ ### 2. Metadata ekleyin
438
+
439
+ ```typescript
440
+ // ✅ İyi - Metadata ile
441
+ measureAsync(() => apiCall(), {
442
+ operation: 'fetch-user',
443
+ userId: '123',
444
+ endpoint: '/api/users/123'
445
+ });
446
+
447
+ // ❌ Kötü - Metadata olmadan
448
+ measureAsync(() => apiCall());
449
+ ```
450
+
451
+ ### 3. Debounce/throttle kullanın
452
+
453
+ ```typescript
454
+ // ✅ İyi - Debounce ile
455
+ const debouncedSearch = debounce(search, 300);
456
+
457
+ // ❌ Kötü - Her tuşta arama
458
+ onChange={(e) => search(e.target.value)}
459
+ ```
460
+
461
+ ### 4. Development'da ölçün
462
+
463
+ ```typescript
464
+ // ✅ İyi - Sadece development'ta
465
+ if (__DEV__) {
466
+ const { duration } = await measureAsync(() => apiCall());
467
+ console.log(`API call: ${duration}ms`);
468
+ }
469
+
470
+ // ❌ Kötü - Her zaman ölçüm
471
+ const { duration } = await measureAsync(() => apiCall());
472
+ ```
473
+
474
+ ## İlgili Dosyalar
475
+
476
+ - [`performance.util.ts`](./performance.util.ts) - Implementasyon
477
+ - [`../telemetry/README.md`](../telemetry/README.md) - Telemetry modülü
@@ -0,0 +1,219 @@
1
+ # Performance Utilities
2
+
3
+ Tools for measuring, tracking, and optimizing AI operation performance.
4
+
5
+ ## 📍 Import Path
6
+
7
+ ```
8
+ import {
9
+ measureAsync,
10
+ measureSync,
11
+ debounce,
12
+ throttle,
13
+ PerformanceTimer,
14
+ performanceTracker
15
+ } from '@umituz/react-native-ai-gemini-provider';
16
+ ```
17
+
18
+ ## 🎯 Purpose
19
+
20
+ Use these utilities to monitor and optimize AI operation performance. Provides timing, debouncing, throttling, and performance tracking.
21
+
22
+ **When to use:**
23
+ - Measure API call duration
24
+ - Track performance metrics over time
25
+ - Implement debouncing for user input
26
+ - Throttle expensive operations
27
+ - Monitor slow operations
28
+ - Optimize application performance
29
+
30
+ ## 📌 Strategy
31
+
32
+ Performance monitoring is crucial for UX. These utilities:
33
+ - Measure operation duration accurately
34
+ - Track metrics over time
35
+ - Provide performance statistics
36
+ - Enable optimization through debouncing/throttling
37
+ - Support performance debugging
38
+
39
+ **Key Decision**: Use `measureAsync()` for all critical AI operations to identify performance bottlenecks early.
40
+
41
+ ## ⚠️ Rules
42
+
43
+ ### Usage Rules
44
+ - **MUST** always stop PerformanceTimers
45
+ - **SHOULD** include metadata for context
46
+ - **MUST** track slow operations (>5s)
47
+ - **SHOULD** clear statistics periodically
48
+ - **MUST NOT** leak timers (always cleanup)
49
+
50
+ ### Measurement Rules
51
+ - **SHOULD** measure async operations
52
+ - **MUST** use descriptive operation names
53
+ - **SHOULD** include relevant metadata
54
+ - **MUST** handle errors in measured operations
55
+ - **SHOULD NOT** measure trivial operations
56
+
57
+ ### Debounce/Throttle Rules
58
+ - **SHOULD** debounce user input
59
+ - **MUST** throttle expensive operations
60
+ - **SHOULD** set appropriate time intervals
61
+ - **MUST NOT** debounce/throttle everything
62
+ - **SHOULD** consider UX impact
63
+
64
+ ## 🤖 AI Agent Guidelines
65
+
66
+ ### When Modifying These Utilities
67
+ 1. **READ** the implementation file first
68
+ 2. **UNDERSTAND** performance implications
69
+ 3. **MAINTAIN** backward compatibility
70
+ 4. **ADD** tests for new functionality
71
+ 5. **UPDATE** type definitions
72
+
73
+ ### When Adding New Features
74
+ 1. **CHECK** if similar utility exists
75
+ 2. **FOLLOW** existing patterns
76
+ 3. **USE** established error handling
77
+ 4. **DOCUMENT** in type definitions
78
+ 5. **ADD** examples to tests (not docs)
79
+
80
+ ### When Fixing Bugs
81
+ 1. **REPRODUCE** bug locally first
82
+ 2. **IDENTIFY** root cause
83
+ 3. **FIX** with minimal changes
84
+ 4. **ADD** regression test
85
+ 5. **VERIFY** all tests pass
86
+
87
+ ### Code Style Rules
88
+ - **USE** precise timing measurements
89
+ - **VALIDATE** inputs
90
+ - **HANDLE** errors gracefully
91
+ - **LOG** performance in development
92
+ - **COMMENT** complex logic only
93
+
94
+ ## 📦 Available Utilities
95
+
96
+ ### `measureAsync(operation, metadata?)`
97
+
98
+ Measure async operation duration.
99
+
100
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
101
+
102
+ ### `measureSync(operation, metadata?)`
103
+
104
+ Measure sync operation duration.
105
+
106
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
107
+
108
+ ### `debounce(func, wait)`
109
+
110
+ Debounce function calls.
111
+
112
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
113
+
114
+ ### `throttle(func, limit)`
115
+
116
+ Throttle function calls.
117
+
118
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
119
+
120
+ ### `PerformanceTimer`
121
+
122
+ Timer class for measuring operations.
123
+
124
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
125
+
126
+ ### `performanceTracker`
127
+
128
+ Global performance statistics tracker.
129
+
130
+ **Refer to**: [`performance.util.ts`](./performance.util.ts)
131
+
132
+ ## 🔗 Related Modules
133
+
134
+ - **Telemetry Service**: [`../services/TELEMETRY_SERVICE.md`](../services/TELEMETRY_SERVICE.md)
135
+ - **Retry Service**: [`../services/RETRY_SERVICE.md`](../services/RETRY_SERVICE.md)
136
+ - **Domain Types**: [`../../domain/entities/README.md`](../../domain/entities/README.md)
137
+
138
+ ## 📋 Configuration Reference
139
+
140
+ ### Performance Metrics
141
+
142
+ Tracked metrics include:
143
+ - `count`: Number of operations
144
+ - `avg`: Average duration (ms)
145
+ - `min`: Minimum duration (ms)
146
+ - `max`: Maximum duration (ms)
147
+
148
+ ### Debounce/Throttle Timing
149
+
150
+ **Typical values:**
151
+ - User input debounce: 300-500ms
152
+ - API call throttle: 1000-2000ms
153
+ - Expensive operations: 2000-5000ms
154
+
155
+ ## 🎓 Usage Patterns
156
+
157
+ ### Measuring API Calls
158
+ 1. Import `measureAsync`
159
+ 2. Wrap API call in measurement
160
+ 3. Include descriptive metadata
161
+ 4. Check duration for slow operations
162
+ 5. Log or report performance issues
163
+
164
+ ### Performance Monitoring
165
+ 1. Create `PerformanceTimer` instance
166
+ 2. Start timer before operation
167
+ 3. Stop timer after operation (in finally block)
168
+ 4. Extract metrics from timer
169
+ 5. Handle results appropriately
170
+
171
+ ### Performance Statistics
172
+ 1. Record operation with `performanceTracker.record()`
173
+ 2. Get statistics with `getStats()`
174
+ 3. Analyze average/min/max durations
175
+ 4. Identify slow operations
176
+ 5. Clear stats periodically
177
+
178
+ ### Debouncing User Input
179
+ 1. Import `debounce` utility
180
+ 2. Wrap user input handler
181
+ 3. Set appropriate delay (300-500ms)
182
+ 4. Handle debounced calls
183
+ 5. Update UI appropriately
184
+
185
+ ### Throttling API Calls
186
+ 1. Import `throttle` utility
187
+ 2. Wrap expensive operation
188
+ 3. Set minimum time between calls
189
+ 4. Handle throttled execution
190
+ 5. Provide user feedback
191
+
192
+ ### Performance Comparison
193
+ 1. Use `measureAsync` for each operation
194
+ 2. Compare durations
195
+ 3. Identify faster/slower methods
196
+ 4. Optimize based on results
197
+ 5. Document findings
198
+
199
+ ## 🚨 Common Pitfalls
200
+
201
+ ### Don't
202
+ - Forget to stop timers (memory leaks)
203
+ - Skip metadata (hard to analyze)
204
+ - Ignore slow operations
205
+ - Debounce/throttle everything
206
+ - Clear statistics too frequently
207
+
208
+ ### Do
209
+ - Always stop timers in finally blocks
210
+ - Include descriptive metadata
211
+ - Monitor for slow operations (>5s)
212
+ - Set appropriate debounce/throttle intervals
213
+ - Clear stats periodically (daily)
214
+ - Consider UX when timing operations
215
+
216
+ ---
217
+
218
+ **Last Updated**: 2025-01-08
219
+ **See Also**: [AI_GUIDELINES.md](../../../AI_GUIDELINES.md)