Skip to main content
CodeGraph can handle large codebases, but very large graphs (10,000+ nodes) require some optimization. This guide covers best practices.

Analysis Optimization

Exclude Unnecessary Projects

# Exclude test projects
codegraph analyze ./Solution.sln --exclude "*Tests*" --exclude "*Test*"

# Only include core projects
codegraph analyze ./Solution.sln --include "*.Core" --include "*.Domain"

Use Class-Level Analysis

Method-level analysis dramatically increases graph size:
LevelTypical Node Count
Namespace10-50
Class100-1,000
Method1,000-50,000
# Class-level (default, recommended for large codebases)
codegraph analyze ./Solution.sln --depth class

# Method-level (use only when needed)
codegraph analyze ./Solution.sln --depth method

Incremental Analysis

After initial analysis, use incremental mode for updates:
# First time: full analysis
codegraph analyze ./Solution.sln

# Later: only changed files
codegraph analyze ./Solution.sln --incremental

Layout Optimization

Use GPU Layout

GPU layout is essential for large graphs:
NodesCPU TimeGPU Time
1,0008s1.2s
5,000120s4s
10,000600s+12s
# Ensure GPU server is running
codegraph gpu start

# Trigger GPU layout
codegraph layout compute --gpu --iterations 2000

Optimize Layout Parameters

For very large graphs:
{
  "iterations": 2000,
  "barnesHutTheta": 1.5,
  "gravity": 2.0,
  "scalingRatio": 5.0
}
ParameterLarge Graph SettingEffect
barnesHutTheta1.5-2.0Faster but less accurate
gravity2.0-5.0Keeps graph compact
scalingRatio5.0-10.0Spreads out dense areas

Visualization Optimization

Filter in the UI

Use filters to reduce visible nodes:
  1. Hide namespaces: Focus on classes only
  2. Hide methods: If using method-level analysis
  3. Filter by namespace: Show one module at a time
  4. Isolation mode: Focus on a specific node and its connections

Use Isolation Mode

  1. Select a node of interest
  2. Press I to isolate
  3. Only connected nodes remain visible
  4. Press I again to exit

Adjust Render Settings

// In frontend config
{
  "rendering": {
    "maxVisibleNodes": 5000,
    "lodEnabled": true,
    "lodDistance": 100,
    "labelMinZoom": 2.0
  }
}

Neo4j Optimization

Memory Settings

For large graphs, increase Neo4j memory:
# neo4j.conf
dbms.memory.heap.initial_size=1G
dbms.memory.heap.max_size=4G
dbms.memory.pagecache.size=2G

Add Indexes

Ensure indexes exist (CodeGraph creates these automatically):
CREATE INDEX node_id FOR (n:CodeNode) ON (n.id);
CREATE INDEX node_name FOR (n:CodeNode) ON (n.name);
CREATE INDEX node_type FOR (n:CodeNode) ON (n.type);
CREATE INDEX node_namespace FOR (n:CodeNode) ON (n.namespace);

Use Database Projections

For very large graphs, consider analyzing subsets:
# Analyze into separate databases
Neo4j__Database=core codegraph analyze ./src/Core --clear
Neo4j__Database=web codegraph analyze ./src/Web --clear
Neo4j__Database=full codegraph analyze ./Solution.sln --clear

Splitting Large Solutions

By Module

# Analyze each module separately
for module in Core Domain Infrastructure Web; do
  codegraph analyze ./src/$module/*.csproj \
    --database "module_$module"
done

By Team

If you have team ownership:
# Team A's code
codegraph analyze ./Solution.sln \
  --include "TeamA.*" \
  --database team_a

# Team B's code
codegraph analyze ./Solution.sln \
  --include "TeamB.*" \
  --database team_b

Performance Benchmarks

Real-world performance on Apple M1 Pro:
CodebaseNodesEdgesAnalysisGPU Layout
Small app2004002s0.5s
Medium app2,0005,00015s2s
Large app10,00030,00060s12s
Roslyn50,000150,000300s45s

Troubleshooting

  • Reduce analysis depth to class
  • Exclude test projects
  • Analyze in smaller batches
# Increase .NET memory limit
DOTNET_GCHeapHardLimit=8000000000 codegraph analyze ./Solution.sln
  • Enable filters to reduce visible nodes
  • Use isolation mode
  • Reduce render quality in settings
  • Use a machine with dedicated GPU
  • Ensure GPU server is running
  • Reduce iterations for initial layout
  • Increase barnesHutTheta for approximation
  • Check indexes are created
  • Increase Neo4j memory
  • Use parameterized queries
  • Add specific indexes for your query patterns