amberjs 1.16.1

JavaScript/TypeScript runtime built with Rust and V8
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
// Performance optimization suggestion generator
//
// This module generates actionable optimization suggestions based on
/// performance analysis and bottleneck detection results.
use crate::analysis::bottleneck_detector::{
    Bottleneck, BottleneckType, BottleneckDetector, BottleneckSeverity
};
use crate::performance_analyzer::PerformanceReport;
use serde::{Deserialize, Serialize};
use std::hash::Hash;
/// Optimization priority levels
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum OptimizationPriority {
    /// Critical - fix immediately
    Critical,
    /// High - fix in current sprint
    High,
    /// Medium - fix in next sprint
    Medium,
    /// Low - fix when resources available
    Low,
}
/// Category of optimization
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum OptimizationCategory {
    /// Code-level optimizations
    CodeOptimization,
    /// Memory optimizations
    MemoryOptimization,
    /// Caching strategies
    CachingStrategy,
    /// JIT compilation optimizations
    JITOptimization,
    /// I/O optimizations
    IOOptimization,
    /// Architecture-level changes
    ArchitectureChange,
    /// Configuration tuning
    ConfigurationTuning,
}
/// An optimization suggestion
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationSuggestion {
    pub id: String,
    pub title: String,
    pub description: String,
    pub category: OptimizationCategory,
    pub priority: OptimizationPriority,
    pub estimated_improvement: String,
    pub implementation_effort: String,
    pub steps: Vec<String>,
    pub code_examples: Vec<String>,
    pub related_bottlenecks: Vec<String>,
    pub references: Vec<String>,
}
/// Performance optimizer that generates suggestions
pub struct PerformanceOptimizer {
    bottleneck_detector: BottleneckDetector,
}
impl PerformanceOptimizer {
    /// Create a new performance optimizer
    pub fn new() -> Self {
        Self {
            bottleneck_detector: BottleneckDetector::new(),
        }
    }
    /// Generate optimization suggestions from bottlenecks
    pub fn generate_suggestions(&self, bottlenecks: &[Bottleneck]) -> Vec<OptimizationSuggestion> {
        let mut suggestions = Vec::new();
        for bottleneck in bottlenecks {
            let mut bottleneck_suggestions = self.suggest_for_bottleneck(bottleneck);
            suggestions.append(&mut bottleneck_suggestions);
        }
        // Sort by priority
        suggestions.sort_by(|a, b| {
            let a_val: _ = self.priority_to_value(&a.priority);
            let b_val: _ = self.priority_to_value(&b.priority);
            b_val.cmp(&a_val)
        });
        suggestions
    }
    /// Generate suggestions for a specific bottleneck
    fn suggest_for_bottleneck(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        match &bottleneck.bottleneck_type {
            BottleneckType::SlowExecution => self.suggest_for_slow_execution(bottleneck),
            BottleneckType::LowCacheHitRate => self.suggest_for_low_cache_hit_rate(bottleneck),
            BottleneckType::HighMemoryUsage => self.suggest_for_high_memory_usage(bottleneck),
            BottleneckType::CPUIntensive => self.suggest_for_cpu_intensive(bottleneck),
            BottleneckType::IOBlocking => self.suggest_for_io_blocking(bottleneck),
            BottleneckType::HeapPressure => self.suggest_for_heap_pressure(bottleneck),
            BottleneckType::FrequentGC => self.suggest_for_frequent_gc(bottleneck),
            BottleneckType::EventLoopLag => self.suggest_for_event_loop_lag(bottleneck),
            BottleneckType::Other(_) => self.suggest_for_other(bottleneck),
        }
    }
    /// Suggestions for slow execution
    fn suggest_for_slow_execution(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-001".to_string(),
                title: "Enable V8 JIT Compilation".to_string(),
                description: "Enable V8's Just-In-Time (JIT) compilation to optimize hot code paths".to_string(),
                category: OptimizationCategory::JITOptimization,
                priority: OptimizationPriority::Critical,
                estimated_improvement: "20-50% performance improvement".to_string(),
                implementation_effort: "Low (configuration change)".to_string(),
                steps: vec![
                    "Configure V8 flags: --jit-enable-optimization".to_string(),
                    "Set optimization threshold: --jit-opt-level=3".to_string(),
                    "Enable inline caching: --jit-inline-cache".to_string(),
                ],
                code_examples: vec![
                    "amber --optimize-speed --jit-enable --jit-opt-level 3 script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 JIT Documentation".to_string(),
                    "V8 Optimization Flags Guide".to_string(),
                ],
            },
            OptimizationSuggestion {
                id: "opt-002".to_string(),
                title: "Implement Code Caching".to_string(),
                description: "Cache compiled JavaScript code to avoid re-parsing and re-compilation".to_string(),
                category: OptimizationCategory::CachingStrategy,
                priority: OptimizationPriority::High,
                estimated_improvement: "30-60% startup time improvement".to_string(),
                implementation_effort: "Medium (code changes)".to_string(),
                steps: vec![
                    "Enable persistent code cache".to_string(),
                    "Implement LRU cache for frequently used modules".to_string(),
                    "Add cache invalidation strategy".to_string(),
                ],
                code_examples: vec![
                    "amber --cache --cache-size 100 script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 Code Cache Documentation".to_string(),
                    "JavaScript Module Caching Patterns".to_string(),
                ],
            },
            OptimizationSuggestion {
                id: "opt-003".to_string(),
                title: "Optimize Hot Code Paths".to_string(),
                description: "Refactor frequently executed code for better performance".to_string(),
                category: OptimizationCategory::CodeOptimization,
                priority: OptimizationPriority::High,
                estimated_improvement: "10-40% performance improvement".to_string(),
                implementation_effort: "High (refactoring required)".to_string(),
                steps: vec![
                    "Identify hot code paths using profiling".to_string(),
                    "Minimize function call overhead".to_string(),
                    "Use inline functions where appropriate".to_string(),
                    "Optimize loop structures".to_string(),
                ],
                code_examples: vec![
                    "// Before: Multiple function calls\nfunction calculate(a, b) {\n  return process(a) + process(b);\n}\n\n// After: Inline for better performance\nfunction calculate(a, b) {\n  return a * 2 + b * 2;\n}".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "JavaScript Performance Optimization Guide".to_string(),
                    "V8 Optimization Tips".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for low cache hit rate
    fn suggest_for_low_cache_hit_rate(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-004".to_string(),
                title: "Increase Cache Size".to_string(),
                description: "Increase the code cache size to store more compiled code".to_string(),
                category: OptimizationCategory::CachingStrategy,
                priority: OptimizationPriority::High,
                estimated_improvement: "15-30% cache hit rate improvement".to_string(),
                implementation_effort: "Low (configuration change)".to_string(),
                steps: vec![
                    "Increase cache size limit".to_string(),
                    "Implement cache eviction policy".to_string(),
                    "Monitor cache metrics".to_string(),
                ],
                code_examples: vec![
                    "amber --cache-size 256 script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 Code Cache Configuration".to_string(),
                ],
            },
            OptimizationSuggestion {
                id: "opt-005".to_string(),
                title: "Enable V8 Snapshot".to_string(),
                description: "Use V8 snapshots to pre-compile and cache code at startup".to_string(),
                category: OptimizationCategory::CachingStrategy,
                priority: OptimizationPriority::Medium,
                estimated_improvement: "40-70% startup time improvement".to_string(),
                implementation_effort: "Medium (setup required)".to_string(),
                steps: vec![
                    "Generate V8 snapshot".to_string(),
                    "Enable snapshot loading".to_string(),
                    "Verify snapshot integrity".to_string(),
                ],
                code_examples: vec![
                    "amber --snapshot script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 Snapshot Documentation".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for high memory usage
    fn suggest_for_high_memory_usage(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-006".to_string(),
                title: "Implement Memory Pool".to_string(),
                description: "Use memory pools to reduce allocation overhead and fragmentation".to_string(),
                category: OptimizationCategory::MemoryOptimization,
                priority: OptimizationPriority::High,
                estimated_improvement: "20-40% memory usage reduction".to_string(),
                implementation_effort: "Medium (code changes)".to_string(),
                steps: vec![
                    "Implement object pooling for frequently allocated objects".to_string(),
                    "Use arena allocators for temporary allocations".to_string(),
                    "Monitor memory usage patterns".to_string(),
                ],
                code_examples: vec![
                    "// Enable memory pooling\nbee --memory-pool script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "Rust Memory Pool Patterns".to_string(),
                    "JavaScript Memory Optimization".to_string(),
                ],
            },
            OptimizationSuggestion {
                id: "opt-007".to_string(),
                title: "Optimize Data Structures".to_string(),
                description: "Use more memory-efficient data structures".to_string(),
                category: OptimizationCategory::MemoryOptimization,
                priority: OptimizationPriority::Medium,
                estimated_improvement: "10-30% memory usage reduction".to_string(),
                implementation_effort: "Medium (code refactoring)".to_string(),
                steps: vec![
                    "Replace objects with Maps for better memory efficiency".to_string(),
                    "Use typed arrays for numerical data".to_string(),
                    "Implement lazy loading for large datasets".to_string(),
                ],
                code_examples: vec![
                    "// Use typed arrays instead of regular arrays\nconst arr = new Float32Array(1000);".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "JavaScript Memory Efficiency Guide".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for CPU-intensive operations
    fn suggest_for_cpu_intensive(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-008".to_string(),
                title: "Use Web Workers".to_string(),
                description: "Offload CPU-intensive tasks to Web Workers".to_string(),
                category: OptimizationCategory::ArchitectureChange,
                priority: OptimizationPriority::High,
                estimated_improvement: "50-80% main thread performance improvement".to_string(),
                implementation_effort: "High (architectural changes)".to_string(),
                steps: vec![
                    "Identify CPU-intensive operations".to_string(),
                    "Create Web Worker scripts".to_string(),
                    "Implement message passing".to_string(),
                    "Handle worker lifecycle".to_string(),
                ],
                code_examples: vec![
                    "// main.js\nconst worker = new Worker('worker.js');\nworker.postMessage(data);\n\n// worker.js\nself.onmessage = function(e) {\n  const result = heavyComputation(e.data);\n  self.postMessage(result);\n};".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "Web Workers API Documentation".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for I/O blocking operations
    fn suggest_for_io_blocking(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-009".to_string(),
                title: "Implement Async I/O".to_string(),
                description: "Replace synchronous I/O operations with asynchronous ones".to_string(),
                category: OptimizationCategory::IOOptimization,
                priority: OptimizationPriority::Critical,
                estimated_improvement: "60-90% I/O performance improvement".to_string(),
                implementation_effort: "Medium (code changes)".to_string(),
                steps: vec![
                    "Convert synchronous file operations to async".to_string(),
                    "Use non-blocking network I/O".to_string(),
                    "Implement async/await patterns".to_string(),
                ],
                code_examples: vec![
                    "// Before: Blocking I/O\nconst data = fs.readFileSync('file.txt');\n\n// After: Non-blocking I/O\nconst data = await fs.readFile('file.txt');".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "Async/Await Best Practices".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for heap pressure
    fn suggest_for_heap_pressure(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-010".to_string(),
                title: "Reduce Heap Allocations".to_string(),
                description: "Minimize unnecessary heap allocations".to_string(),
                category: OptimizationCategory::MemoryOptimization,
                priority: OptimizationPriority::High,
                estimated_improvement: "20-50% heap pressure reduction".to_string(),
                implementation_effort: "Medium (code optimization)".to_string(),
                steps: vec![
                    "Identify frequent allocations".to_string(),
                    "Reuse objects where possible".to_string(),
                    "Use stack allocation for small objects".to_string(),
                ],
                code_examples: vec![
                    "// Reuse objects instead of creating new ones\nconst config = { timeout: 5000 };\n// Use config instead of creating new objects".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 Heap Optimization".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for frequent garbage collection
    fn suggest_for_frequent_gc(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-011".to_string(),
                title: "Tune GC Parameters".to_string(),
                description: "Optimize garbage collection parameters for your workload".to_string(),
                category: OptimizationCategory::ConfigurationTuning,
                priority: OptimizationPriority::Medium,
                estimated_improvement: "15-40% GC overhead reduction".to_string(),
                implementation_effort: "Low (configuration)".to_string(),
                steps: vec![
                    "Adjust max heap size".to_string(),
                    "Tune GC thresholds".to_string(),
                    "Enable incremental GC".to_string(),
                ],
                code_examples: vec![
                    "amber --max-heap 512 --gc-incremental script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "V8 GC Tuning Guide".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for event loop lag
    fn suggest_for_event_loop_lag(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-012".to_string(),
                title: "Optimize Event Loop".to_string(),
                description: "Reduce event loop lag by optimizing task scheduling".to_string(),
                category: OptimizationCategory::ConfigurationTuning,
                priority: OptimizationPriority::High,
                estimated_improvement: "30-60% event loop latency reduction".to_string(),
                implementation_effort: "Medium (configuration + code)".to_string(),
                steps: vec![
                    "Use setImmediate instead of setTimeout where appropriate".to_string(),
                    "Break up long-running tasks".to_string(),
                    "Use process.nextTick for immediate callbacks".to_string(),
                ],
                code_examples: vec![
                    "// Use setImmediate for I/O callbacks\nfs.readFile('file.txt', (err, data) => {\n  setImmediate(() => processData(data));\n});".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "Node.js Event Loop Guide".to_string(),
                ],
            },
        ]
    }
    /// Suggestions for other bottlenecks
    fn suggest_for_other(&self, bottleneck: &Bottleneck) -> Vec<OptimizationSuggestion> {
        vec![
            OptimizationSuggestion {
                id: "opt-013".to_string(),
                title: "Profile and Analyze".to_string(),
                description: "Use profiling tools to identify the root cause of the bottleneck".to_string(),
                category: OptimizationCategory::CodeOptimization,
                priority: OptimizationPriority::Medium,
                estimated_improvement: "Varies (diagnostic step)".to_string(),
                implementation_effort: "Low (tool usage)".to_string(),
                steps: vec![
                    "Enable performance profiling".to_string(),
                    "Run performance benchmarks".to_string(),
                    "Analyze profiling results".to_string(),
                    "Implement targeted optimizations".to_string(),
                ],
                code_examples: vec![
                    "amber --profile script.js".to_string(),
                ],
                related_bottlenecks: vec![format!("{:?}", bottleneck.bottleneck_type)],
                references: vec![
                    "JavaScript Profiling Guide".to_string(),
                ],
            },
        ]
    }
    /// Convert priority to numeric value for sorting
    fn priority_to_value(&self, priority: &OptimizationPriority) -> i32 {
        match priority {
            OptimizationPriority::Critical => 5,
            OptimizationPriority::High => 4,
            OptimizationPriority::Medium => 3,
            OptimizationPriority::Low => 2,
        }
    }
    /// Generate a comprehensive optimization report
    pub fn generate_optimization_report(
        &self,
        report: &PerformanceReport,
    ) -> HashMap<String, _> {
        let bottlenecks: _ = self.bottleneck_detector.detect_bottlenecks(report);
        let suggestions: _ = self.generate_suggestions(&bottlenecks);
        let mut categorized_suggestions = HashMap::new();
        for suggestion in suggestions {
            let category: _ = format!("{:?}", suggestion.category);
            categorized_suggestions
                .entry(category)
                .or_insert_with(Vec::new)
                .push(suggestion);
        }
        categorized_suggestions
    }
}
impl Default for PerformanceOptimizer {
    fn default() -> Self {
        Self::new()
    }
}
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_optimizer_creation() {
        let optimizer: _ = PerformanceOptimizer::new();
        // Just ensure it doesn't panic
        let _: _ = optimizer;
    }
    #[test]
    fn test_generate_suggestions_for_slow_execution() {
        let optimizer: _ = PerformanceOptimizer::new();
        let bottleneck: _ = Bottleneck {
            bottleneck_type: BottleneckType::SlowExecution,
            severity: BottleneckSeverity::High,
            description: "Slow execution detected".to_string(),
            affected_metrics: vec!["average_time_ms".to_string()],
            suggestion: "Optimize code".to_string(),
            code_location: None,
        };
        let suggestions: _ = optimizer.generate_suggestions(&[bottleneck]);
        assert!(!suggestions.is_empty());
        assert!(suggestions.iter().any(|s| s.category == OptimizationCategory::JITOptimization));
    }
    #[test]
    fn test_generate_suggestions_for_low_cache_hit_rate() {
        let optimizer: _ = PerformanceOptimizer::new();
        let bottleneck: _ = Bottleneck {
            bottleneck_type: BottleneckType::LowCacheHitRate,
            severity: BottleneckSeverity::Medium,
            description: "Low cache hit rate".to_string(),
            affected_metrics: vec!["cache_hit_rate".to_string()],
            suggestion: "Increase cache size".to_string(),
            code_location: None,
        };
        let suggestions: _ = optimizer.generate_suggestions(&[bottleneck]);
        assert!(!suggestions.is_empty());
        assert!(suggestions.iter().any(|s| s.category == OptimizationCategory::CachingStrategy));
    }
    #[test]
    fn test_generate_optimization_report() {
        let optimizer: _ = PerformanceOptimizer::new();
        let report: _ = PerformanceReport {
            total_executions: 10,
            average_time_ms: 15.0,
            min_time_ms: 5.0,
            max_time_ms: 30.0,
            cache_hit_rate: 30.0,
            total_code_executed: 1000,
        };
        let optimization_report: _ = optimizer.generate_optimization_report(&report);
        assert!(!optimization_report.is_empty());
    }
    #[test]
    fn test_priority_sorting() {
        let optimizer: _ = PerformanceOptimizer::new();
        let suggestions: _ = vec![
            OptimizationSuggestion {
                id: "1".to_string(),
                title: "Low Priority".to_string(),
                description: "Low priority suggestion".to_string(),
                category: OptimizationCategory::CodeOptimization,
                priority: OptimizationPriority::Low,
                estimated_improvement: "5%".to_string(),
                implementation_effort: "Low".to_string(),
                steps: vec![],
                code_examples: vec![],
                related_bottlenecks: vec![],
                references: vec![],
            },
            OptimizationSuggestion {
                id: "2".to_string(),
                title: "Critical Priority".to_string(),
                description: "Critical priority suggestion".to_string(),
                category: OptimizationCategory::CodeOptimization,
                priority: OptimizationPriority::Critical,
                estimated_improvement: "50%".to_string(),
                implementation_effort: "High".to_string(),
                steps: vec![],
                code_examples: vec![],
                related_bottlenecks: vec![],
                references: vec![],
            },
        ];
        // Manually create bottlenecks and suggestions
        let bottlenecks: _ = vec![
            Bottleneck {
                bottleneck_type: BottleneckType::SlowExecution,
                severity: BottleneckSeverity::High,
                description: "Test".to_string(),
                affected_metrics: vec![],
                suggestion: "Test".to_string(),
                code_location: None,
            }
        ];
        let mut suggestions = optimizer.generate_suggestions(&bottlenecks);
        suggestions.sort_by(|a, b| {
            let a_val: _ = optimizer.priority_to_value(&a.priority);
            let b_val: _ = optimizer.priority_to_value(&b.priority);
            b_val.cmp(&a_val)
        });
        assert!(matches!(suggestions[0].priority, OptimizationPriority::Critical));
    }
}
use std::collections::{BTreeMap, HashMap};