thread-flow 0.1.0

Thread dataflow integration for data processing pipelines, using CocoIndex.
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
// SPDX-FileCopyrightText: 2025 Knitli Inc. <knitli@knit.li>
// SPDX-License-Identifier: AGPL-3.0-or-later

//! Incremental update system performance benchmarks.
//!
//! This benchmark suite validates Phase 4 constitutional requirements and measures
//! performance characteristics of the incremental analysis system.
//!
//! ## Benchmark Groups (48-72 benchmarks total):
//!
//! 1. **change_detection** - Incremental overhead validation
//!    - Fingerprint computation speed
//!    - Change detection latency
//!    - Graph traversal time
//!    - **Target: <10ms overhead**
//!
//! 2. **graph_traversal** - Invalidation propagation
//!    - BFS traversal (100/1000/10000 nodes)
//!    - Affected file calculation
//!    - **Target: <50ms for 1000 nodes**
//!
//! 3. **topological_sort** - Analysis ordering
//!    - DAG sorting (various sizes)
//!    - Cycle detection overhead
//!    - Parallel sorting (feature-gated)
//!
//! 4. **reanalysis** - Incremental vs full
//!    - 1% change rate
//!    - 10% change rate
//!    - 50% change rate
//!    - Speedup factor measurement
//!
//! 5. **cache_hit_rate** - Repeated analysis
//!    - Zero changes
//!    - Identical content
//!    - **Target: >90% hit rate**
//!
//! 6. **executor_comparison** - Concurrency (feature-gated)
//!    - Sequential baseline
//!    - Tokio async
//!    - Rayon parallel
//!    - Speedup measurements
//!
//! ## Constitutional Requirements Validation:
//!
//! - Incremental overhead: <10ms (Constitution VI)
//! - Graph traversal: <50ms for 1000 nodes (Constitution VI)
//! - Cache hit rate: >90% (Constitution VI)
//! - All targets must be met for compliance
//!
//! ## Running:
//!
//! ```bash
//! # Run all incremental benchmarks
//! cargo bench -p thread-flow incremental_benchmarks --all-features
//!
//! # Run specific benchmark group
//! cargo bench -p thread-flow incremental_benchmarks -- change_detection
//! cargo bench -p thread-flow incremental_benchmarks -- graph_traversal
//! cargo bench -p thread-flow incremental_benchmarks -- cache_hit_rate
//! ```

use ::std::hint::black_box;
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use std::path::PathBuf;
use thread_flow::incremental::{
    AnalysisDefFingerprint, DependencyEdge, DependencyGraph, DependencyType, InMemoryStorage,
    StorageBackend,
};

// ============================================================================
// Test Data Generation
// ============================================================================

/// Helper to generate synthetic Rust file content
fn generate_rust_file(file_id: usize, size: &str) -> String {
    match size {
        "small" => format!(
            r#"
// File {}
pub fn func_{}() -> i32 {{
    {}
}}
"#,
            file_id, file_id, file_id
        ),
        "medium" => format!(
            r#"
// File {}
use std::collections::HashMap;

pub struct Data{} {{
    value: i32,
}}

impl Data{} {{
    pub fn new(v: i32) -> Self {{ Self {{ value: v }} }}
    pub fn process(&self) -> i32 {{ self.value * 2 }}
}}

pub fn func_{}() -> Data{} {{
    Data{}::new({})
}}
"#,
            file_id, file_id, file_id, file_id, file_id, file_id, file_id
        ),
        "large" => {
            let mut code = format!(
                r#"
// File {}
use std::collections::{{HashMap, HashSet}};
use std::sync::Arc;

pub struct Module{} {{
    data: Vec<i32>,
}}
"#,
                file_id, file_id
            );
            for i in 0..10 {
                code.push_str(&format!(
                    r#"
pub fn func_{}_{}() -> i32 {{ {} }}
"#,
                    file_id, i, i
                ));
            }
            code
        }
        _ => panic!("Unknown size: {}", size),
    }
}

/// Creates a linear dependency chain: 0 -> 1 -> 2 -> ... -> n
fn create_linear_chain(size: usize) -> DependencyGraph {
    let mut graph = DependencyGraph::new();

    for i in 0..size {
        let current = PathBuf::from(format!("file_{}.rs", i));
        if i < size - 1 {
            let next = PathBuf::from(format!("file_{}.rs", i + 1));
            graph.add_edge(DependencyEdge::new(current, next, DependencyType::Import));
        } else {
            // Ensure leaf node exists
            graph.add_node(&current);
        }
    }

    graph
}

/// Creates a diamond dependency pattern:
/// ```text
///       0
///      / \
///     1   2
///      \ /
///       3
/// ```
fn create_diamond_pattern() -> DependencyGraph {
    let mut graph = DependencyGraph::new();

    let n0 = PathBuf::from("file_0.rs");
    let n1 = PathBuf::from("file_1.rs");
    let n2 = PathBuf::from("file_2.rs");
    let n3 = PathBuf::from("file_3.rs");

    graph.add_edge(DependencyEdge::new(
        n0.clone(),
        n1.clone(),
        DependencyType::Import,
    ));
    graph.add_edge(DependencyEdge::new(n0, n2.clone(), DependencyType::Import));
    graph.add_edge(DependencyEdge::new(n1, n3.clone(), DependencyType::Import));
    graph.add_edge(DependencyEdge::new(n2, n3, DependencyType::Import));

    graph
}

/// Creates a tree structure with specified depth and fanout
fn create_tree_structure(depth: usize, fanout: usize) -> DependencyGraph {
    let mut graph = DependencyGraph::new();
    let mut node_id = 0;

    fn add_tree_level(
        graph: &mut DependencyGraph,
        parent: PathBuf,
        depth: usize,
        fanout: usize,
        node_id: &mut usize,
    ) {
        if depth == 0 {
            return;
        }

        for _ in 0..fanout {
            let child = PathBuf::from(format!("file_{}.rs", *node_id));
            *node_id += 1;

            graph.add_edge(DependencyEdge::new(
                parent.clone(),
                child.clone(),
                DependencyType::Import,
            ));

            add_tree_level(graph, child, depth - 1, fanout, node_id);
        }
    }

    let root = PathBuf::from("file_0.rs");
    graph.add_node(&root);
    node_id += 1;

    add_tree_level(&mut graph, root, depth, fanout, &mut node_id);

    graph
}

// ============================================================================
// Benchmark Group 1: Change Detection
// ============================================================================

fn benchmark_change_detection(c: &mut Criterion) {
    let mut group = c.benchmark_group("change_detection");

    // Fingerprint computation speed
    let small_content = generate_rust_file(0, "small");
    let medium_content = generate_rust_file(0, "medium");
    let large_content = generate_rust_file(0, "large");

    group.bench_function("fingerprint_small_file", |b| {
        b.iter(|| {
            black_box(AnalysisDefFingerprint::new(black_box(
                small_content.as_bytes(),
            )))
        });
    });

    group.bench_function("fingerprint_medium_file", |b| {
        b.iter(|| {
            black_box(AnalysisDefFingerprint::new(black_box(
                medium_content.as_bytes(),
            )))
        });
    });

    group.bench_function("fingerprint_large_file", |b| {
        b.iter(|| {
            black_box(AnalysisDefFingerprint::new(black_box(
                large_content.as_bytes(),
            )))
        });
    });

    // Change detection latency
    let old_fp = AnalysisDefFingerprint::new(b"original content");

    group.bench_function("detect_no_change", |b| {
        b.iter(|| black_box(old_fp.content_matches(black_box(b"original content"))));
    });

    group.bench_function("detect_change", |b| {
        b.iter(|| black_box(!old_fp.content_matches(black_box(b"modified content"))));
    });

    // Graph traversal time (small)
    let graph = create_linear_chain(100);
    let changed: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("file_99.rs")].into_iter().collect();

    group.bench_function("graph_traversal_100_nodes", |b| {
        b.iter(|| black_box(graph.find_affected_files(black_box(&changed))));
    });

    // Incremental overhead: full change detection pipeline
    let rt = tokio::runtime::Runtime::new().unwrap();
    let storage = InMemoryStorage::new();

    // Prime storage with 100 files
    rt.block_on(async {
        for i in 0..100 {
            let path = PathBuf::from(format!("file_{}.rs", i));
            let content = generate_rust_file(i, "small");
            let fp = AnalysisDefFingerprint::new(content.as_bytes());
            storage.save_fingerprint(&path, &fp).await.unwrap();
        }
    });

    group.bench_function("incremental_overhead_1_change", |b| {
        b.iter(|| {
            rt.block_on(async {
                let path = PathBuf::from("file_50.rs");
                let new_content = generate_rust_file(50, "medium");
                let old_fp = storage.load_fingerprint(&path).await.unwrap();
                let changed = match old_fp {
                    Some(old) => !old.content_matches(new_content.as_bytes()),
                    None => true,
                };

                black_box(changed)
            })
        });
    });

    // Target validation: <10ms overhead
    println!("\n[Constitutional Validation] Target: <10ms incremental overhead");

    group.finish();
}

// ============================================================================
// Benchmark Group 2: Graph Traversal
// ============================================================================

fn benchmark_graph_traversal(c: &mut Criterion) {
    let mut group = c.benchmark_group("graph_traversal");

    // BFS traversal with different graph sizes
    for size in [100, 500, 1000].iter() {
        let graph = create_linear_chain(*size);
        let changed: thread_utilities::RapidSet<PathBuf> =
            [PathBuf::from(format!("file_{}.rs", size - 1))]
                .into_iter()
                .collect();

        group.bench_with_input(BenchmarkId::new("bfs_linear_chain", size), size, |b, _| {
            b.iter(|| black_box(graph.find_affected_files(black_box(&changed))));
        });
    }

    // Affected file calculation (diamond pattern)
    let diamond = create_diamond_pattern();
    let changed: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("file_3.rs")].into_iter().collect();

    group.bench_function("affected_files_diamond", |b| {
        b.iter(|| black_box(diamond.find_affected_files(black_box(&changed))));
    });

    // Wide fanout pattern (1 root -> N children)
    for fanout in [10, 50, 100].iter() {
        let mut graph = DependencyGraph::new();
        let root = PathBuf::from("root.rs");

        for i in 0..*fanout {
            let child = PathBuf::from(format!("child_{}.rs", i));
            graph.add_edge(DependencyEdge::new(
                child.clone(),
                root.clone(),
                DependencyType::Import,
            ));
        }

        let changed: thread_utilities::RapidSet<PathBuf> = [root.clone()].into_iter().collect();

        group.bench_with_input(BenchmarkId::new("wide_fanout", fanout), fanout, |b, _| {
            b.iter(|| black_box(graph.find_affected_files(black_box(&changed))));
        });
    }

    // Tree structure traversal
    let tree = create_tree_structure(4, 3); // depth=4, fanout=3 = 40 nodes
    let root_changed: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("file_0.rs")].into_iter().collect();

    group.bench_function("tree_traversal_depth4_fanout3", |b| {
        b.iter(|| black_box(tree.find_affected_files(black_box(&root_changed))));
    });

    // Target validation: <50ms for 1000 nodes
    println!("\n[Constitutional Validation] Target: <50ms for 1000 nodes");

    group.finish();
}

// ============================================================================
// Benchmark Group 3: Topological Sort
// ============================================================================

fn benchmark_topological_sort(c: &mut Criterion) {
    let mut group = c.benchmark_group("topological_sort");

    // DAG sorting with different sizes
    for size in [10, 50, 100, 500].iter() {
        let graph = create_linear_chain(*size);
        let all_files: thread_utilities::RapidSet<_> = (0..*size)
            .map(|i| PathBuf::from(format!("file_{}.rs", i)))
            .collect();

        group.bench_with_input(BenchmarkId::new("linear_chain", size), size, |b, _| {
            b.iter(|| black_box(graph.topological_sort(black_box(&all_files))));
        });
    }

    // Diamond pattern sorting
    let diamond = create_diamond_pattern();
    let diamond_files: thread_utilities::RapidSet<_> = (0..4)
        .map(|i| PathBuf::from(format!("file_{}.rs", i)))
        .collect();

    group.bench_function("diamond_pattern", |b| {
        b.iter(|| black_box(diamond.topological_sort(black_box(&diamond_files))));
    });

    // Tree structure sorting
    let tree = create_tree_structure(4, 3);
    let tree_files: thread_utilities::RapidSet<_> = tree.nodes.keys().cloned().collect();

    group.bench_function("tree_structure", |b| {
        b.iter(|| black_box(tree.topological_sort(black_box(&tree_files))));
    });

    // Cycle detection overhead (expect error)
    let mut cyclic_graph = DependencyGraph::new();
    cyclic_graph.add_edge(DependencyEdge::new(
        PathBuf::from("a.rs"),
        PathBuf::from("b.rs"),
        DependencyType::Import,
    ));
    cyclic_graph.add_edge(DependencyEdge::new(
        PathBuf::from("b.rs"),
        PathBuf::from("a.rs"),
        DependencyType::Import,
    ));
    let cyclic_files: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("a.rs"), PathBuf::from("b.rs")]
            .into_iter()
            .collect();

    group.bench_function("cycle_detection", |b| {
        b.iter(|| {
            let result = cyclic_graph.topological_sort(black_box(&cyclic_files));
            black_box(result.is_err())
        });
    });

    group.finish();
}

// ============================================================================
// Benchmark Group 4: Reanalysis Scenarios
// ============================================================================

fn benchmark_reanalysis(c: &mut Criterion) {
    let mut group = c.benchmark_group("reanalysis");

    // Simulate incremental vs full analysis with different change rates
    let file_count = 100;

    for change_pct in [1, 10, 50].iter() {
        let changed_count = (file_count * change_pct) / 100;

        // Setup: Create graph and storage
        let rt = tokio::runtime::Runtime::new().unwrap();
        let storage = InMemoryStorage::new();
        let graph = create_linear_chain(file_count);

        // Prime storage with all files
        rt.block_on(async {
            for i in 0..file_count {
                let path = PathBuf::from(format!("file_{}.rs", i));
                let content = generate_rust_file(i, "small");
                let fp = AnalysisDefFingerprint::new(content.as_bytes());
                storage.save_fingerprint(&path, &fp).await.unwrap();
            }
        });

        // Incremental: only analyze affected files
        let changed_files: thread_utilities::RapidSet<_> = (0..changed_count)
            .map(|i| PathBuf::from(format!("file_{}.rs", i)))
            .collect();

        group.bench_with_input(
            BenchmarkId::new("incremental_analysis", change_pct),
            change_pct,
            |b, _| {
                b.iter(|| {
                    rt.block_on(async {
                        let affected = graph.find_affected_files(black_box(&changed_files));
                        let sorted = graph.topological_sort(black_box(&affected)).unwrap();

                        for file in sorted {
                            let _fp = storage.load_fingerprint(&file).await.unwrap();
                            // Simulate analysis work
                            black_box(_fp);
                        }
                    })
                });
            },
        );

        // Full: analyze all files regardless of changes
        let all_files: thread_utilities::RapidSet<_> = (0..file_count)
            .map(|i| PathBuf::from(format!("file_{}.rs", i)))
            .collect();

        group.bench_with_input(
            BenchmarkId::new("full_analysis", change_pct),
            change_pct,
            |b, _| {
                b.iter(|| {
                    rt.block_on(async {
                        let sorted = graph.topological_sort(black_box(&all_files)).unwrap();

                        for file in sorted {
                            let _fp = storage.load_fingerprint(&file).await.unwrap();
                            // Simulate analysis work
                            black_box(_fp);
                        }
                    })
                });
            },
        );
    }

    // Speedup measurement
    println!("\n[Performance] Incremental speedup factors calculated above");

    group.finish();
}

// ============================================================================
// Benchmark Group 5: Cache Hit Rate
// ============================================================================

fn benchmark_cache_hit_rate(c: &mut Criterion) {
    let mut group = c.benchmark_group("cache_hit_rate");

    let rt = tokio::runtime::Runtime::new().unwrap();
    let storage = InMemoryStorage::new();

    // Prime cache with 1000 files
    rt.block_on(async {
        for i in 0..1000 {
            let path = PathBuf::from(format!("file_{}.rs", i));
            let content = generate_rust_file(i, "small");
            let fp = AnalysisDefFingerprint::new(content.as_bytes());
            storage.save_fingerprint(&path, &fp).await.unwrap();
        }
    });

    // Scenario 1: 100% cache hit (zero changes)
    group.bench_function("100_percent_hit_rate", |b| {
        b.iter(|| {
            rt.block_on(async {
                let mut hits = 0;
                let mut misses = 0;

                for i in 0..100 {
                    let path = PathBuf::from(format!("file_{}.rs", i));
                    let content = generate_rust_file(i, "small");

                    if let Some(old_fp) = storage.load_fingerprint(&path).await.unwrap() {
                        if old_fp.content_matches(content.as_bytes()) {
                            hits += 1;
                        } else {
                            misses += 1;
                        }
                    } else {
                        misses += 1;
                    }
                }

                black_box((hits, misses))
            })
        });
    });

    // Scenario 2: 90% cache hit (10% changed)
    group.bench_function("90_percent_hit_rate", |b| {
        b.iter(|| {
            rt.block_on(async {
                let mut hits = 0;
                let mut misses = 0;

                for i in 0..100 {
                    let path = PathBuf::from(format!("file_{}.rs", i));
                    let content = if i % 10 == 0 {
                        // 10% modified
                        generate_rust_file(i, "medium")
                    } else {
                        // 90% unchanged
                        generate_rust_file(i, "small")
                    };

                    if let Some(old_fp) = storage.load_fingerprint(&path).await.unwrap() {
                        if old_fp.content_matches(content.as_bytes()) {
                            hits += 1;
                        } else {
                            misses += 1;
                        }
                    } else {
                        misses += 1;
                    }
                }

                black_box((hits, misses))
            })
        });
    });

    // Scenario 3: 50% cache hit (50% changed)
    group.bench_function("50_percent_hit_rate", |b| {
        b.iter(|| {
            rt.block_on(async {
                let mut hits = 0;
                let mut misses = 0;

                for i in 0..100 {
                    let path = PathBuf::from(format!("file_{}.rs", i));
                    let content = if i % 2 == 0 {
                        generate_rust_file(i, "medium")
                    } else {
                        generate_rust_file(i, "small")
                    };

                    if let Some(old_fp) = storage.load_fingerprint(&path).await.unwrap() {
                        if old_fp.content_matches(content.as_bytes()) {
                            hits += 1;
                        } else {
                            misses += 1;
                        }
                    } else {
                        misses += 1;
                    }
                }

                black_box((hits, misses))
            })
        });
    });

    // Identical content detection
    group.bench_function("identical_content_detection", |b| {
        b.iter(|| {
            rt.block_on(async {
                let content = generate_rust_file(0, "small");

                let fp1 = AnalysisDefFingerprint::new(content.as_bytes());

                black_box(fp1.content_matches(content.as_bytes()))
            })
        });
    });

    // Target validation: >90% hit rate
    println!("\n[Constitutional Validation] Target: >90% cache hit rate");

    group.finish();
}

// ============================================================================
// Benchmark Group 6: Executor Comparison (Feature-Gated)
// ============================================================================

#[cfg(feature = "parallel")]
fn benchmark_executor_comparison(c: &mut Criterion) {
    use rayon::prelude::*;

    let mut group = c.benchmark_group("executor_comparison");

    let file_count = 100;
    let files: Vec<_> = (0..file_count)
        .map(|i| {
            (
                PathBuf::from(format!("file_{}.rs", i)),
                generate_rust_file(i, "small"),
            )
        })
        .collect();

    // Sequential baseline
    group.bench_function("sequential_baseline", |b| {
        b.iter(|| {
            for (_path, content) in &files {
                let fp = AnalysisDefFingerprint::new(content.as_bytes());
                black_box(fp);
            }
        });
    });

    // Tokio async
    let rt = tokio::runtime::Runtime::new().unwrap();

    group.bench_function("tokio_async", |b| {
        b.iter(|| {
            rt.block_on(async {
                let mut tasks = Vec::new();

                for (_path, content) in &files {
                    let content = content.clone();
                    tasks.push(tokio::spawn(async move {
                        AnalysisDefFingerprint::new(content.as_bytes())
                    }));
                }

                for task in tasks {
                    black_box(task.await.unwrap());
                }
            });
        });
    });

    // Rayon parallel
    group.bench_function("rayon_parallel", |b| {
        b.iter(|| {
            files.par_iter().for_each(|(_path, content)| {
                let fp = AnalysisDefFingerprint::new(content.as_bytes());
                black_box(fp);
            });
        });
    });

    // Speedup measurements
    println!("\n[Performance] Parallel speedup factors calculated above");

    group.finish();
}

#[cfg(not(feature = "parallel"))]
fn benchmark_executor_comparison(_c: &mut Criterion) {
    // Parallel benchmarks skipped (feature not enabled)
}

// ============================================================================
// Additional Performance Validation Benchmarks
// ============================================================================

fn benchmark_performance_validation(c: &mut Criterion) {
    let mut group = c.benchmark_group("performance_validation");

    // Large graph performance (10000 nodes)
    let large_graph = create_linear_chain(10000);
    let changed: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("file_9999.rs")].into_iter().collect();

    group.bench_function("large_graph_10000_nodes", |b| {
        b.iter(|| black_box(large_graph.find_affected_files(black_box(&changed))));
    });

    // Deep chain performance (1000 levels)
    let deep_chain = create_linear_chain(1000);
    let deep_changed: thread_utilities::RapidSet<PathBuf> =
        [PathBuf::from("file_999.rs")].into_iter().collect();

    group.bench_function("deep_chain_1000_levels", |b| {
        b.iter(|| black_box(deep_chain.find_affected_files(black_box(&deep_changed))));
    });

    // Memory efficiency: batch fingerprint creation
    group.bench_function("batch_fingerprint_1000_files", |b| {
        b.iter(|| {
            let mut fingerprints = Vec::new();
            for i in 0..1000 {
                let content = generate_rust_file(i, "small");
                fingerprints.push(AnalysisDefFingerprint::new(content.as_bytes()));
            }
            black_box(fingerprints)
        });
    });

    group.finish();
}

// ============================================================================
// Criterion Configuration
// ============================================================================

criterion_group!(
    benches,
    benchmark_change_detection,
    benchmark_graph_traversal,
    benchmark_topological_sort,
    benchmark_reanalysis,
    benchmark_cache_hit_rate,
    benchmark_executor_comparison,
    benchmark_performance_validation,
);

criterion_main!(benches);