Skip to content

Commit 5f3b095

Browse files
committed
CBOM generation optimization
1 parent 0c46a6f commit 5f3b095

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

crates/cbom-generator/src/algorithm_detector.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ impl AlgorithmDetector {
7171
}
7272
}
7373

74-
// Perform additional static analysis for parameter extraction
75-
let additional_algorithms =
76-
self.perform_deep_static_analysis_with_registry(scan_path, registry)?;
77-
for asset in additional_algorithms {
78-
let key = self.create_deduplication_key(&asset);
79-
if seen_algorithms.insert(key) {
80-
algorithms.push(asset);
74+
// Only perform deep static analysis if we have a reasonable number of findings
75+
// Skip for large codebases to avoid performance issues
76+
if findings.len() < 1000 {
77+
let additional_algorithms =
78+
self.perform_deep_static_analysis_with_registry(scan_path, registry)?;
79+
for asset in additional_algorithms {
80+
let key = self.create_deduplication_key(&asset);
81+
if seen_algorithms.insert(key) {
82+
algorithms.push(asset);
83+
}
8184
}
8285
}
8386
} else {
@@ -257,12 +260,21 @@ impl AlgorithmDetector {
257260
) -> Result<Vec<CryptoAsset>> {
258261
let mut algorithms = Vec::new();
259262

263+
// Only analyze a limited number of files to avoid performance issues
264+
const MAX_FILES_TO_ANALYZE: usize = 100;
265+
let mut files_analyzed = 0;
266+
260267
// Walk through source files for parameter extraction
261268
for entry in WalkDir::new(scan_path)
269+
.max_depth(5) // Limit depth to avoid deep recursion
262270
.into_iter()
263271
.filter_map(|e| e.ok())
264272
.filter(|e| e.file_type().is_file())
265273
{
274+
if files_analyzed >= MAX_FILES_TO_ANALYZE {
275+
break; // Stop after analyzing enough files
276+
}
277+
266278
let path = entry.path();
267279

268280
if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
@@ -275,6 +287,7 @@ impl AlgorithmDetector {
275287
) {
276288
if let Ok(mut extracted) = self.analyze_file_with_registry(path, registry) {
277289
algorithms.append(&mut extracted);
290+
files_analyzed += 1;
278291
}
279292
}
280293
}

0 commit comments

Comments
 (0)