leptos-helios 0.8.1

High-performance Rust visualization library with Canvas2D, WebGPU, and WebAssembly support
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
//! Performance Optimizations for leptos-helios
//!
//! This module provides comprehensive performance optimization features including
//! virtual scrolling, data sampling, WebGL/WebGPU acceleration, and memory optimization.

use std::collections::HashMap;
use std::time::{Duration, Instant};

// ============================================================================
// Virtual Scrolling
// ============================================================================

/// Virtual scrolling system for handling large datasets efficiently
#[derive(Debug, Clone)]
pub struct VirtualScroller {
    pub viewport_height: f64,
    pub item_height: f64,
    pub total_items: usize,
    pub visible_start: usize,
    pub visible_end: usize,
    pub scroll_offset: f64,
    pub overscan: usize, // Extra items to render outside viewport
}

impl VirtualScroller {
    /// Create a new virtual scroller
    pub fn new(viewport_height: f64, item_height: f64, total_items: usize) -> Self {
        let visible_count = (viewport_height / item_height).ceil() as usize;
        Self {
            viewport_height,
            item_height,
            total_items,
            visible_start: 0,
            visible_end: visible_count.min(total_items),
            scroll_offset: 0.0,
            overscan: 5, // Render 5 extra items above and below
        }
    }

    /// Scroll to a specific offset
    pub fn scroll_to(&mut self, offset: f64) {
        self.scroll_offset = offset.max(0.0);
        self.update_visible_range();
    }

    /// Update the visible range based on current scroll position
    fn update_visible_range(&mut self) {
        let visible_count = (self.viewport_height / self.item_height).ceil() as usize;
        self.visible_start = (self.scroll_offset / self.item_height).floor() as usize;
        self.visible_end = (self.visible_start + visible_count).min(self.total_items);

        // Apply overscan
        self.visible_start = self.visible_start.saturating_sub(self.overscan);
        self.visible_end = (self.visible_end + self.overscan).min(self.total_items);
    }

    /// Get the currently visible items
    pub fn get_visible_items(&self) -> Vec<VisibleItem> {
        (self.visible_start..self.visible_end)
            .map(|i| VisibleItem {
                index: i,
                y_position: i as f64 * self.item_height - self.scroll_offset,
                height: self.item_height,
            })
            .collect()
    }

    /// Get the total height of all items
    pub fn get_total_height(&self) -> f64 {
        self.total_items as f64 * self.item_height
    }

    /// Check if an item is visible
    pub fn is_item_visible(&self, index: usize) -> bool {
        index >= self.visible_start && index < self.visible_end
    }
}

/// Represents a visible item in the virtual scroller
#[derive(Debug, Clone)]
pub struct VisibleItem {
    pub index: usize,
    pub y_position: f64,
    pub height: f64,
}

// ============================================================================
// Data Sampling
// ============================================================================

/// Strategy for data sampling
#[derive(Debug, Clone, PartialEq)]
pub enum SamplingStrategy {
    /// Uniform sampling - evenly distributed points
    Uniform,
    /// Adaptive sampling - more points in dense regions
    Adaptive,
    /// Statistical sampling - preserves key statistics
    Statistical,
    /// LOD (Level of Detail) sampling - based on zoom level
    LevelOfDetail(f64),
}

/// Data sampler for reducing dataset size while preserving visual fidelity
#[derive(Debug, Clone)]
pub struct DataSampler {
    strategy: SamplingStrategy,
    cache: HashMap<String, Vec<DataPoint>>,
}

impl DataSampler {
    /// Create a new data sampler
    pub fn new(strategy: SamplingStrategy) -> Self {
        Self {
            strategy,
            cache: HashMap::new(),
        }
    }

    /// Sample data according to the strategy
    pub fn sample(&self, data: &[DataPoint], target_size: usize) -> Vec<DataPoint> {
        if data.len() <= target_size {
            return data.to_vec();
        }

        match self.strategy {
            SamplingStrategy::Uniform => self.uniform_sample(data, target_size),
            SamplingStrategy::Adaptive => self.adaptive_sample(data, target_size),
            SamplingStrategy::Statistical => self.statistical_sample(data, target_size),
            SamplingStrategy::LevelOfDetail(zoom) => self.lod_sample(data, target_size, zoom),
        }
    }

    /// Uniform sampling - evenly distributed points
    fn uniform_sample(&self, data: &[DataPoint], target_size: usize) -> Vec<DataPoint> {
        let step = data.len() as f64 / target_size as f64;
        (0..target_size)
            .map(|i| {
                let index = (i as f64 * step).floor() as usize;
                data[index.min(data.len() - 1)].clone()
            })
            .collect()
    }

    /// Adaptive sampling - more points in dense regions
    fn adaptive_sample(&self, data: &[DataPoint], target_size: usize) -> Vec<DataPoint> {
        // Simplified adaptive sampling - in practice would use density analysis
        let mut sampled = Vec::new();
        let chunk_size = data.len() / target_size;

        for i in 0..target_size {
            let start = i * chunk_size;
            let end = ((i + 1) * chunk_size).min(data.len());
            let chunk = &data[start..end];

            // Find the point with maximum value in this chunk
            if let Some(max_point) = chunk
                .iter()
                .max_by(|a, b| a.value.partial_cmp(&b.value).unwrap())
            {
                sampled.push(max_point.clone());
            }
        }

        sampled
    }

    /// Statistical sampling - preserves key statistics
    fn statistical_sample(&self, data: &[DataPoint], target_size: usize) -> Vec<DataPoint> {
        // Simplified statistical sampling - in practice would preserve mean, variance, etc.
        let mut sampled = Vec::new();

        // Always include min and max points
        if let (Some(min_point), Some(max_point)) = (
            data.iter()
                .min_by(|a, b| a.value.partial_cmp(&b.value).unwrap()),
            data.iter()
                .max_by(|a, b| a.value.partial_cmp(&b.value).unwrap()),
        ) {
            sampled.push(min_point.clone());
            sampled.push(max_point.clone());
        }

        // Fill remaining with uniform sampling
        let remaining = target_size.saturating_sub(sampled.len());
        if remaining > 0 {
            let uniform_sample = self.uniform_sample(data, remaining);
            sampled.extend(uniform_sample);
        }

        sampled
    }

    /// Level of detail sampling based on zoom level
    fn lod_sample(&self, data: &[DataPoint], target_size: usize, zoom: f64) -> Vec<DataPoint> {
        // Adjust target size based on zoom level
        let adjusted_size = (target_size as f64 * zoom).ceil() as usize;
        self.uniform_sample(data, adjusted_size.min(target_size))
    }
}

// ============================================================================
// WebGL/WebGPU Acceleration
// ============================================================================

/// WebGL renderer for hardware-accelerated rendering
#[derive(Debug, Clone)]
pub struct WebGLRenderer {
    pub width: u32,
    pub height: u32,
    pub shader_cache: HashMap<String, u32>,
    pub buffer_cache: HashMap<String, u32>,
    pub is_initialized: bool,
}

impl WebGLRenderer {
    /// Create a new WebGL renderer
    pub fn new(width: u32, height: u32) -> Self {
        Self {
            width,
            height,
            shader_cache: HashMap::new(),
            buffer_cache: HashMap::new(),
            is_initialized: false,
        }
    }

    /// Initialize the WebGL context
    pub fn initialize(&mut self) -> Result<(), String> {
        // In practice, this would initialize WebGL context
        self.is_initialized = true;
        Ok(())
    }

    /// Check if the renderer is initialized
    pub fn is_initialized(&self) -> bool {
        self.is_initialized
    }

    /// Compile a shader program
    pub fn compile_shader_program(&mut self, vertex: &str, fragment: &str) -> Option<u32> {
        let key = format!("{}:{}", vertex, fragment);
        if let Some(&program) = self.shader_cache.get(&key) {
            return Some(program);
        }

        // In practice, this would compile WebGL shaders
        let program = self.shader_cache.len() as u32 + 1;
        self.shader_cache.insert(key, program);
        Some(program)
    }

    /// Render a batch of primitives
    pub fn render_batch(&mut self, batch: &RenderBatch) -> Result<(), String> {
        if !self.is_initialized {
            return Err("WebGL renderer not initialized".to_string());
        }

        // In practice, this would use WebGL to render the batch
        let _ = batch.points.len();
        Ok(())
    }

    /// Clear the render target
    pub fn clear(&mut self, _color: Color) -> Result<(), String> {
        if !self.is_initialized {
            return Err("WebGL renderer not initialized".to_string());
        }

        // In practice, this would clear the WebGL framebuffer
        Ok(())
    }
}

/// WebGPU renderer for modern hardware acceleration
#[derive(Debug, Clone)]
pub struct WebGPURenderer {
    pub width: u32,
    pub height: u32,
    pub buffer_pool: Vec<Buffer>,
    pub shader_cache: HashMap<String, u32>,
    pub is_initialized: bool,
}

impl WebGPURenderer {
    /// Create a new WebGPU renderer
    pub fn new(width: u32, height: u32) -> Self {
        Self {
            width,
            height,
            buffer_pool: Vec::new(),
            shader_cache: HashMap::new(),
            is_initialized: false,
        }
    }

    /// Initialize the WebGPU context
    pub fn initialize(&mut self) -> Result<(), String> {
        // In practice, this would initialize WebGPU context
        self.is_initialized = true;
        Ok(())
    }

    /// Check if the renderer is initialized
    pub fn is_initialized(&self) -> bool {
        self.is_initialized
    }

    /// Allocate a buffer from the pool
    pub fn allocate_buffer(&mut self, size: usize) -> Option<Buffer> {
        // Try to reuse a buffer from the pool
        if let Some(index) = self.buffer_pool.iter().position(|b| b.size >= size) {
            return Some(self.buffer_pool.remove(index));
        }

        // Create a new buffer
        Some(Buffer {
            size,
            id: self.buffer_pool.len() as u32 + 1,
        })
    }

    /// Deallocate a buffer back to the pool
    pub fn deallocate_buffer(&mut self, buffer: Buffer) {
        self.buffer_pool.push(buffer);
    }

    /// Render a batch using WebGPU
    pub fn render_batch(&mut self, batch: &RenderBatch) -> Result<(), String> {
        if !self.is_initialized {
            return Err("WebGPU renderer not initialized".to_string());
        }

        // In practice, this would use WebGPU to render the batch
        let _ = batch.points.len();
        Ok(())
    }
}

/// Represents a GPU buffer
#[derive(Debug, Clone)]
pub struct Buffer {
    pub size: usize,
    pub id: u32,
}

/// Batch of rendering primitives
#[derive(Debug, Clone)]
pub struct RenderBatch {
    pub points: Vec<(Point2D, Color)>,
    pub lines: Vec<(Point2D, Point2D, Color)>,
    pub triangles: Vec<(Point2D, Point2D, Point2D, Color)>,
}

impl RenderBatch {
    /// Create a new render batch
    pub fn new() -> Self {
        Self {
            points: Vec::new(),
            lines: Vec::new(),
            triangles: Vec::new(),
        }
    }

    /// Add a point to the batch
    pub fn add_point(&mut self, point: Point2D, color: Color) {
        self.points.push((point, color));
    }

    /// Add a line to the batch
    pub fn add_line(&mut self, start: Point2D, end: Point2D, color: Color) {
        self.lines.push((start, end, color));
    }

    /// Add a triangle to the batch
    pub fn add_triangle(&mut self, a: Point2D, b: Point2D, c: Point2D, color: Color) {
        self.triangles.push((a, b, c, color));
    }

    /// Clear the batch
    pub fn clear(&mut self) {
        self.points.clear();
        self.lines.clear();
        self.triangles.clear();
    }

    /// Get the total number of primitives
    pub fn primitive_count(&self) -> usize {
        self.points.len() + self.lines.len() + self.triangles.len()
    }
}

/// 2D point
#[derive(Debug, Clone, Copy)]
pub struct Point2D {
    pub x: f64,
    pub y: f64,
}

/// Color with RGBA components
#[derive(Debug, Clone, Copy)]
pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
    pub a: f32,
}

impl Color {
    /// Create a new color
    pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
        Self { r, g, b, a }
    }

    /// Create a color from RGB values (0-255)
    pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
        Self {
            r: r as f32 / 255.0,
            g: g as f32 / 255.0,
            b: b as f32 / 255.0,
            a: 1.0,
        }
    }

    /// Create a color from RGBA values (0-255)
    pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
        Self {
            r: r as f32 / 255.0,
            g: g as f32 / 255.0,
            b: b as f32 / 255.0,
            a: a as f32 / 255.0,
        }
    }
}

// ============================================================================
// Memory Optimization
// ============================================================================

/// Memory pool for efficient memory allocation
#[derive(Debug, Clone)]
pub struct MemoryPool {
    pub total_size: usize,
    pub used_size: usize,
    pub available_size: usize,
    pub allocations: Vec<Allocation>,
}

impl MemoryPool {
    /// Create a new memory pool
    pub fn new(size: usize) -> Self {
        Self {
            total_size: size,
            used_size: 0,
            available_size: size,
            allocations: Vec::new(),
        }
    }

    /// Allocate memory from the pool
    pub fn allocate(&mut self, size: usize) -> Option<*mut u8> {
        if self.available_size < size {
            return None;
        }

        // Find a suitable free block
        if let Some(index) = self.find_free_block(size) {
            let allocation = &mut self.allocations[index];
            allocation.size = size;
            allocation.used = true;
            self.used_size += size;
            self.available_size -= size;
            return Some(allocation.ptr);
        }

        // Allocate new block
        let ptr = std::ptr::null_mut(); // Simplified for testing
        self.allocations.push(Allocation {
            ptr,
            size,
            used: true,
        });
        self.used_size += size;
        self.available_size -= size;
        Some(ptr)
    }

    /// Deallocate memory back to the pool
    pub fn deallocate(&mut self, ptr: *mut u8) {
        if let Some(allocation) = self.allocations.iter_mut().find(|a| a.ptr == ptr) {
            self.used_size -= allocation.size;
            self.available_size += allocation.size;
            allocation.used = false;
        }
    }

    /// Find a free block of sufficient size
    fn find_free_block(&self, size: usize) -> Option<usize> {
        self.allocations
            .iter()
            .position(|a| !a.used && a.size >= size)
    }

    /// Defragment the memory pool
    pub fn defragment(&mut self) {
        // Sort allocations by address and merge adjacent free blocks
        self.allocations.sort_by(|a, b| a.ptr.cmp(&b.ptr));

        let mut i = 0;
        while i < self.allocations.len() - 1 {
            if !self.allocations[i].used && !self.allocations[i + 1].used {
                // Merge adjacent free blocks
                self.allocations[i].size += self.allocations[i + 1].size;
                self.allocations.remove(i + 1);
            } else {
                i += 1;
            }
        }
    }
}

/// Memory allocation record
#[derive(Debug, Clone)]
pub struct Allocation {
    pub ptr: *mut u8,
    pub size: usize,
    pub used: bool,
}

/// Garbage collector for managing object lifetimes
#[derive(Debug, Clone)]
pub struct GarbageCollector {
    objects: Vec<Object>,
    next_id: usize,
}

impl GarbageCollector {
    /// Create a new garbage collector
    pub fn new() -> Self {
        Self {
            objects: Vec::new(),
            next_id: 0,
        }
    }

    /// Allocate a new object
    pub fn allocate_object(&mut self, name: &str) -> ObjectId {
        let id = ObjectId(self.next_id);
        self.next_id += 1;

        self.objects.push(Object {
            id,
            name: name.to_string(),
            reachable: false,
            size: 0, // Simplified for testing
        });

        id
    }

    /// Mark an object as reachable
    pub fn mark_reachable(&mut self, id: ObjectId) {
        if let Some(obj) = self.objects.iter_mut().find(|o| o.id == id) {
            obj.reachable = true;
        }
    }

    /// Run garbage collection
    pub fn collect(&mut self) {
        // Remove unreachable objects
        self.objects.retain(|obj| obj.reachable);

        // Reset reachability flags
        for obj in &mut self.objects {
            obj.reachable = false;
        }
    }

    /// Get the number of objects
    pub fn object_count(&self) -> usize {
        self.objects.len()
    }

    /// Check if an object is allocated
    pub fn is_allocated(&self, id: ObjectId) -> bool {
        self.objects.iter().any(|obj| obj.id == id)
    }

    /// Get memory usage statistics
    pub fn get_memory_stats(&self) -> MemoryStats {
        let total_size: usize = self.objects.iter().map(|obj| obj.size).sum();
        MemoryStats {
            object_count: self.objects.len(),
            total_size,
            reachable_count: self.objects.iter().filter(|obj| obj.reachable).count(),
        }
    }
}

/// Object identifier
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ObjectId(usize);

/// Object in the garbage collector
#[derive(Debug, Clone)]
pub struct Object {
    pub id: ObjectId,
    pub name: String,
    pub reachable: bool,
    pub size: usize,
}

/// Memory usage statistics
#[derive(Debug, Clone)]
pub struct MemoryStats {
    pub object_count: usize,
    pub total_size: usize,
    pub reachable_count: usize,
}

// ============================================================================
// Performance Monitoring
// ============================================================================

/// Performance monitor for tracking and optimizing performance
#[derive(Debug, Clone)]
pub struct PerformanceMonitor {
    pub metrics: HashMap<String, PerformanceMetric>,
    pub budgets: HashMap<String, Duration>,
    pub enabled: bool,
}

impl PerformanceMonitor {
    /// Create a new performance monitor
    pub fn new() -> Self {
        Self {
            metrics: HashMap::new(),
            budgets: HashMap::new(),
            enabled: true,
        }
    }

    /// Check if monitoring is enabled
    pub fn is_enabled(&self) -> bool {
        self.enabled
    }

    /// Enable or disable monitoring
    pub fn set_enabled(&mut self, enabled: bool) {
        self.enabled = enabled;
    }

    /// Start timing an operation
    pub fn start_timer(&mut self, name: &str) {
        if !self.enabled {
            return;
        }

        let metric = PerformanceMetric {
            name: name.to_string(),
            start_time: Instant::now(),
            duration: Duration::ZERO,
            call_count: 1,
            min_duration: Duration::MAX,
            max_duration: Duration::ZERO,
            total_duration: Duration::ZERO,
        };
        self.metrics.insert(name.to_string(), metric);
    }

    /// End timing an operation
    pub fn end_timer(&mut self, name: &str) {
        if !self.enabled {
            return;
        }

        if let Some(metric) = self.metrics.get_mut(name) {
            let duration = metric.start_time.elapsed();
            metric.duration = duration;
            metric.total_duration += duration;
            metric.min_duration = metric.min_duration.min(duration);
            metric.max_duration = metric.max_duration.max(duration);
        }
    }

    /// Get all performance metrics
    pub fn get_metrics(&self) -> &HashMap<String, PerformanceMetric> {
        &self.metrics
    }

    /// Set a performance budget for an operation
    pub fn set_budget(&mut self, name: &str, budget: Duration) {
        self.budgets.insert(name.to_string(), budget);
    }

    /// Check if an operation is over budget
    pub fn is_over_budget(&self, name: &str) -> bool {
        if let (Some(metric), Some(budget)) = (self.metrics.get(name), self.budgets.get(name)) {
            metric.duration > *budget
        } else {
            false
        }
    }

    /// Get optimization suggestions
    pub fn get_optimization_suggestions(&self) -> Vec<String> {
        let mut suggestions = Vec::new();

        for (name, metric) in &self.metrics {
            if metric.duration > Duration::from_millis(100) {
                suggestions.push(format!(
                    "Consider optimizing {} (took {:?}, avg: {:?})",
                    name,
                    metric.duration,
                    metric.total_duration / metric.call_count as u32
                ));
            }

            if metric.call_count > 1000 {
                suggestions.push(format!(
                    "Consider batching {} (called {} times)",
                    name, metric.call_count
                ));
            }
        }

        suggestions
    }

    /// Get performance report
    pub fn get_performance_report(&self) -> PerformanceReport {
        let mut slow_operations = Vec::new();
        let mut over_budget = Vec::new();

        for (name, metric) in &self.metrics {
            if metric.duration > Duration::from_millis(50) {
                slow_operations.push((name.clone(), metric.duration));
            }

            if self.is_over_budget(name) {
                over_budget.push(name.clone());
            }
        }

        slow_operations.sort_by(|a, b| b.1.cmp(&a.1));

        PerformanceReport {
            total_operations: self.metrics.len(),
            slow_operations,
            over_budget,
            suggestions: self.get_optimization_suggestions(),
        }
    }
}

/// Performance metric for a single operation
#[derive(Debug, Clone)]
pub struct PerformanceMetric {
    pub name: String,
    pub start_time: Instant,
    pub duration: Duration,
    pub call_count: u32,
    pub min_duration: Duration,
    pub max_duration: Duration,
    pub total_duration: Duration,
}

/// Performance report
#[derive(Debug, Clone)]
pub struct PerformanceReport {
    pub total_operations: usize,
    pub slow_operations: Vec<(String, Duration)>,
    pub over_budget: Vec<String>,
    pub suggestions: Vec<String>,
}

// ============================================================================
// Data Point (from existing code)
// ============================================================================

/// Data point for visualization
#[derive(Debug, Clone)]
pub struct DataPoint {
    pub x: f64,
    pub y: f64,
    pub value: f64,
}