Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
768 changes: 607 additions & 161 deletions crates/codegraph-core/src/complexity.rs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions crates/codegraph-core/src/extractors/csharp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, CSHARP_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -103,7 +104,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(&child),
end_line: Some(end_line(&child)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(&child, &CSHARP_RULES)),
});
}
}
Expand Down Expand Up @@ -140,7 +141,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &CSHARP_RULES)),
});
}
}
Expand All @@ -159,7 +160,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &CSHARP_RULES)),
});
}
}
Expand All @@ -178,7 +179,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &CSHARP_RULES)),
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/codegraph-core/src/extractors/go.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, GO_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand All @@ -23,7 +24,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &GO_RULES)),
});
}
}
Expand Down Expand Up @@ -59,7 +60,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &GO_RULES)),
});
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/codegraph-core/src/extractors/java.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, JAVA_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -109,7 +110,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(&child),
end_line: Some(end_line(&child)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(&child, &JAVA_RULES)),
});
}
}
Expand Down Expand Up @@ -146,7 +147,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &JAVA_RULES)),
});
}
}
Expand All @@ -165,7 +166,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &JAVA_RULES)),
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/codegraph-core/src/extractors/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::compute_function_complexity;
use crate::complexity::{compute_function_complexity, JS_TS_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand All @@ -24,7 +24,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: Some(compute_function_complexity(node)),
complexity: Some(compute_function_complexity(node, &JS_TS_RULES)),
});
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: Some(compute_function_complexity(node)),
complexity: Some(compute_function_complexity(node, &JS_TS_RULES)),
});
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(&value_n)),
decorators: None,
complexity: Some(compute_function_complexity(&value_n)),
complexity: Some(compute_function_complexity(&value_n, &JS_TS_RULES)),
});
}
}
Expand Down Expand Up @@ -562,7 +562,7 @@ fn extract_callback_definition(call_node: &Node, source: &[u8]) -> Option<Defini
line: start_line(&cb),
end_line: Some(end_line(&cb)),
decorators: None,
complexity: Some(compute_function_complexity(&cb)),
complexity: Some(compute_function_complexity(&cb, &JS_TS_RULES)),
});
}

Expand All @@ -579,7 +579,7 @@ fn extract_callback_definition(call_node: &Node, source: &[u8]) -> Option<Defini
line: start_line(&cb),
end_line: Some(end_line(&cb)),
decorators: None,
complexity: Some(compute_function_complexity(&cb)),
complexity: Some(compute_function_complexity(&cb, &JS_TS_RULES)),
});
}

Expand All @@ -593,7 +593,7 @@ fn extract_callback_definition(call_node: &Node, source: &[u8]) -> Option<Defini
line: start_line(&cb),
end_line: Some(end_line(&cb)),
decorators: None,
complexity: Some(compute_function_complexity(&cb)),
complexity: Some(compute_function_complexity(&cb, &JS_TS_RULES)),
});
}

Expand Down
7 changes: 4 additions & 3 deletions crates/codegraph-core/src/extractors/php.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, PHP_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -39,7 +40,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &PHP_RULES)),
});
}
}
Expand Down Expand Up @@ -121,7 +122,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(&child),
end_line: Some(end_line(&child)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(&child, &PHP_RULES)),
});
}
}
Expand Down Expand Up @@ -171,7 +172,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &PHP_RULES)),
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/codegraph-core/src/extractors/python.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, PYTHON_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -39,7 +40,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
} else {
Some(decorators)
},
complexity: None,
complexity: Some(compute_function_complexity(node, &PYTHON_RULES)),
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/codegraph-core/src/extractors/ruby.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, RUBY_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -76,7 +77,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &RUBY_RULES)),
});
}
}
Expand All @@ -95,7 +96,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &RUBY_RULES)),
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/codegraph-core/src/extractors/rust_lang.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use tree_sitter::{Node, Tree};
use crate::complexity::{compute_function_complexity, RUST_LANG_RULES};
use crate::types::*;
use super::helpers::*;
use super::SymbolExtractor;
Expand Down Expand Up @@ -42,7 +43,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(node),
end_line: Some(end_line(node)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(node, &RUST_LANG_RULES)),
});
}
}
Expand Down Expand Up @@ -101,7 +102,7 @@ fn walk_node(node: &Node, source: &[u8], symbols: &mut FileSymbols) {
line: start_line(&child),
end_line: Some(end_line(&child)),
decorators: None,
complexity: None,
complexity: Some(compute_function_complexity(&child, &RUST_LANG_RULES)),
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion scripts/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function benchmarkEngine(engine) {
if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath);

const buildStart = performance.now();
await buildGraph(root, { engine, incremental: false });
const buildResult = await buildGraph(root, { engine, incremental: false });
const buildTimeMs = performance.now() - buildStart;

const queryStart = performance.now();
Expand Down Expand Up @@ -155,6 +155,7 @@ async function benchmarkEngine(engine) {
noopRebuildMs,
oneFileRebuildMs,
queries,
phases: buildResult?.phases || null,
};
}

Expand Down Expand Up @@ -185,6 +186,7 @@ const result = {
noopRebuildMs: wasm.noopRebuildMs,
oneFileRebuildMs: wasm.oneFileRebuildMs,
queries: wasm.queries,
phases: wasm.phases,
},
native: native
? {
Expand All @@ -197,6 +199,7 @@ const result = {
noopRebuildMs: native.noopRebuildMs,
oneFileRebuildMs: native.oneFileRebuildMs,
queries: native.queries,
phases: native.phases,
}
: null,
};
Expand Down
25 changes: 25 additions & 0 deletions scripts/update-benchmark-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@ for (const engineKey of ['native', 'wasm']) {
md += `| Files | ${latest.files} |\n\n`;
}

// ── Build Phase Breakdown (latest) ────────────────────────────────────
const hasPhases = latest.native?.phases || latest.wasm?.phases;
if (hasPhases) {
md += '### Build Phase Breakdown (latest)\n\n';
const phaseKeys = ['parseMs', 'insertMs', 'resolveMs', 'edgesMs', 'structureMs', 'rolesMs', 'complexityMs'];
const phaseLabels = {
parseMs: 'Parse',
insertMs: 'Insert nodes',
resolveMs: 'Resolve imports',
edgesMs: 'Build edges',
structureMs: 'Structure',
rolesMs: 'Roles',
complexityMs: 'Complexity',
};

md += '| Phase | Native | WASM |\n';
md += '|-------|-------:|-----:|\n';
for (const key of phaseKeys) {
const nVal = latest.native?.phases?.[key];
const wVal = latest.wasm?.phases?.[key];
md += `| ${phaseLabels[key]} | ${nVal != null ? nVal + ' ms' : 'n/a'} | ${wVal != null ? wVal + ' ms' : 'n/a'} |\n`;
}
md += '\n';
}

// ── Extrapolated estimate for large repos ────────────────────────────────
const ESTIMATE_FILES = 50_000;
md += `### Estimated performance at ${(ESTIMATE_FILES).toLocaleString()} files\n\n`;
Expand Down
Loading