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
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
]

[workspace.package]
version = "2.2.7"
version = "2.2.8"
edition = "2021"
rust-version = "1.80"
license = "MIT"
Expand Down
35 changes: 10 additions & 25 deletions crates/codegraph-bench/src/bin/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use camino::Utf8Path;
use clap::Parser;
use codegraph_bench::{BenchOptions, Repo, extract, index_at, orchestrator, run_queries};
use codegraph_core::{
Annotation, CallRecord, EdgeMeta, EffectType, ScopeLevel, Symbol, SymbolKind,
};
use codegraph_core::{Annotation, CallRecord, EffectType, ScopeLevel, Symbol, SymbolKind};
use codegraph_graph::meminfo::{MemTracker, fmt_bytes, rss_bytes};
use codegraph_graph::memtrack::MemBreakdown;
use std::sync::OnceLock;
Expand Down Expand Up @@ -127,7 +125,7 @@ struct Cli {

/// Dựng index synthetic với N function thay vì đọc repo thật — deterministic,
/// không phụ thuộc network. Mỗi function gọi `--fanout` function khác nên
/// `edges` + `call_names` (hai cấu trúc đang tối ưu) có quy mô đáng kể.
/// `call_names` (cấu trúc đang tối ưu) có quy mô đáng kể.
#[arg(long, value_name = "N")]
synthetic: Option<usize>,

Expand All @@ -141,7 +139,7 @@ struct Cli {
///
/// - `symbols` — chỉ symbol → `symbols` + `name_index` + **name engine**
/// - `chains` — symbol + chain, không call record → thêm **chain engine**
/// - `full` — kèm call record → thêm `call_names` + `edges`
/// - `full` — kèm call record → thêm `call_names` (+ đếm `edge_count`)
#[arg(long, value_enum, default_value_t = Shape::Full)]
shape: Shape,

Expand Down Expand Up @@ -212,8 +210,6 @@ struct RepoMem {
rss_index_delta: u64,
/// `symbols.len() × size_of::<Symbol>()` — phần trong HashMap `symbols`.
predicted_symbols: u64,
/// `edges.len() × size_of::<EdgeMeta>()` — phần trong HashMap `edges`.
predicted_edges: u64,
/// Deep size từng cấu trúc, sort giảm dần.
breakdown: Vec<BreakdownRow>,
/// Tổng bytes đã quy được về cấu trúc (chưa gồm allocator + radix engine).
Expand Down Expand Up @@ -301,7 +297,6 @@ fn measure(repo: &Repo, opts: &BenchOptions) -> anyhow::Result<RepoMem> {
rss_peak: tracker.peak(),
rss_index_delta: after_index.saturating_sub(after_extract),
predicted_symbols: st.symbols * size_of::<Symbol>() as u64,
predicted_edges: st.edges * size_of::<EdgeMeta>() as u64,
accounted_total: breakdown.accounted_total(),
caches: breakdown.caches.clone(),
breakdown: breakdown_rows(&breakdown),
Expand All @@ -311,10 +306,10 @@ fn measure(repo: &Repo, opts: &BenchOptions) -> anyhow::Result<RepoMem> {
/// Dựng `ParseResult` synthetic: `n` function, mỗi function gọi `fanout`
/// function khác (id local tính từ `SYMBOL_BASE`).
///
/// Mục tiêu là **làm đầy `edges` + `call_names`** — hai `HashMap` đang tốn
/// nhiều RAM nhất trong `GraphIndex`. Call name cố tình trùng lặp (chỉ vài
/// tên lib giả) để `call_names` có nhiều key chứa nhiều site, đúng hình dạng
/// repo thật.
/// Mục tiêu là **làm đầy `call_names`** — `HashMap` đang tốn nhiều RAM nhất
/// trong `GraphIndex` (edge metadata không còn materialize thành map riêng).
/// Call name cố tình trùng lặp (chỉ vài tên lib giả) để `call_names` có nhiều
/// key chứa nhiều site, đúng hình dạng repo thật.
fn synthetic_parse_result(n: usize, fanout: usize, shape: Shape) -> codegraph_graph::ParseResult {
// `n = 0` sẽ làm `% n` panic ở vòng sinh chain — chặn sớm, báo rõ.
assert!(n > 0, "--synthetic cần N > 0");
Expand Down Expand Up @@ -423,7 +418,6 @@ fn measure_synthetic(n: usize, fanout: usize, shape: Shape) -> anyhow::Result<Re
rss_peak: tracker.peak(),
rss_index_delta: after_index.saturating_sub(after_extract),
predicted_symbols: st.symbols * size_of::<Symbol>() as u64,
predicted_edges: st.edges * size_of::<EdgeMeta>() as u64,
accounted_total: breakdown.accounted_total(),
caches: breakdown.caches.clone(),
breakdown: breakdown_rows(&breakdown),
Expand Down Expand Up @@ -488,7 +482,6 @@ fn measure_reopen(n: usize, fanout: usize, shape: Shape) -> anyhow::Result<RepoM
rss_peak: tracker.peak(),
rss_index_delta: after_open.saturating_sub(before_open),
predicted_symbols: st.symbols * size_of::<Symbol>() as u64,
predicted_edges: st.edges * size_of::<EdgeMeta>() as u64,
accounted_total: breakdown.accounted_total(),
caches: breakdown.caches.clone(),
breakdown: breakdown_rows(&breakdown),
Expand Down Expand Up @@ -534,27 +527,19 @@ fn main() -> anyhow::Result<()> {
}

println!(
"{:<14} {:>8} {:>8} {:>10} {:>10} {:>10} {:>12} {:>12}",
"repo",
"symbols",
"edges",
"rss extract",
"rss index",
"Δ index",
"pred symbols",
"pred edges"
"{:<14} {:>8} {:>8} {:>10} {:>10} {:>10} {:>12}",
"repo", "symbols", "edges", "rss extract", "rss index", "Δ index", "pred symbols",
);
for r in &results {
println!(
"{:<14} {:>8} {:>8} {:>10} {:>10} {:>10} {:>12} {:>12}",
"{:<14} {:>8} {:>8} {:>10} {:>10} {:>10} {:>12}",
r.repo,
r.symbols,
r.edges,
fmt_bytes(r.rss_after_extract),
fmt_bytes(r.rss_after_index),
fmt_bytes(r.rss_index_delta),
fmt_bytes(r.predicted_symbols),
fmt_bytes(r.predicted_edges),
);
}
for r in &results {
Expand Down
2 changes: 1 addition & 1 deletion crates/codegraph-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use error::{Error, Result};
pub use route::StorageRoute;
pub use semgraph::{
is_marker, marker_id, marker_name, Annotation, BranchLabel, CallRecord, CallSite,
CallSiteResult, ClassInfo, DbStats as SemgraphStats, DependenciesReport, Dependency, EdgeMeta,
CallSiteResult, ClassInfo, DbStats as SemgraphStats, DependenciesReport, Dependency,
EffectCallPattern, EffectRule, EffectType, FileInfo, FlowCall, FlowResult, FunctionScope,
MemberInfo, ResolveResult, ScopeLevel, SearchFlowResult, Symbol, SymbolId, SymbolKind,
SymbolMatch, MARKER_BRANCH_END, MARKER_BREAK, MARKER_CONTINUE, MARKER_IF_FALSE, MARKER_IF_TRUE,
Expand Down
20 changes: 0 additions & 20 deletions crates/codegraph-core/src/semgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,26 +316,6 @@ pub struct Annotation {
pub line: u32,
}

/// Metadata của 1 call edge — serialized thành edge data (edge stream).
///
/// `(caller_id, callee_id)` là chiều chuẩn; `position` = index của callee trong
/// chain của caller (để nối với CallRecord khi render flow).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EdgeMeta {
pub caller_id: SymbolId,
pub callee_id: SymbolId,
/// Index trong chain của caller mà callee xuất hiện.
pub position: usize,
/// Guard text của if bao quanh (nếu có).
pub condition: Option<String>,
pub effect: EffectType,
pub effect_desc: Option<String>,
#[serde(default)]
pub arg_ids: Vec<SymbolId>,
pub is_loop_body: bool,
pub is_recursive: bool,
}

/// Call record thô — persist để render flow khi call không resolve được.
///
/// Vị trí `0` trong chain là placeholder, được thay bằng id thật khi resolve.
Expand Down
Loading
Loading