A comprehensive benchmarking repository to evaluate the impact of Go runtime flags (GOMAXPROCS, GOMEMLIMIT, GOGC) on applications built with the Agent Development Kit for Go.
This project benchmarks real agentic coding tasks with different Go runtime configurations to help you optimize your ADK-based applications for:
- Performance: Execution speed and throughput
- Memory efficiency: RAM usage and GC behavior
- Resource constraints: Container and cloud deployments
The repository includes realistic agentic coding scenarios:
- Code Generator - Generates Go source files with functions and types
- File Searcher - Searches codebases for patterns using concurrent workers
- Refactorer - Performs code transformations across multiple files
- AST Parser - Memory-intensive parsing of Go abstract syntax trees
Each task is designed to stress different aspects of the Go runtime.
# Generate test data
./scripts/generate_testdata.sh
# Run all benchmarks
go run ./cmd/benchmark
# Generate report
go run ./cmd/report -input=benchmark_results.json -output=BENCHMARK_REPORT.mdControls maximum OS threads for Go code execution.
GOMAXPROCS=4 go run ./cmd/agents/code_generatorImpact:
- CPU-bound tasks: Higher values improve parallelism
- I/O-bound tasks: Lower values reduce overhead
- Default:
runtime.NumCPU()
Sets soft memory limit for the runtime (Go 1.19+).
GOMEMLIMIT=512MiB go run ./cmd/agents/ast_parserImpact:
- Triggers aggressive GC near limit
- Essential for containers with memory limits
- Prevents OOM kills in constrained environments
Controls garbage collector aggressiveness.
GOGC=200 go run ./cmd/agents/file_searcherImpact:
- Lower values (50): More frequent GC, less memory
- Higher values (200): Less frequent GC, more memory
- -1: Disables automatic GC
- Default: 100
.
├── cmd/
│ ├── agents/ # Agent programs for benchmarking
│ │ ├── code_generator/ # Generates Go code files
│ │ ├── file_searcher/ # Searches files concurrently
│ │ ├── refactor/ # Refactors code across files
│ │ └── ast_parser/ # Parses Go AST (memory-intensive)
│ ├── benchmark/ # Benchmark runner
│ └── report/ # Report generator
├── tools/ # Reusable ADK tools
├── testdata/ # Test files for benchmarking
├── scripts/ # Helper scripts
└── examples/ # Example configurations
go run ./cmd/benchmarkThis tests 13 configurations across 4 agent tasks (52 total runs):
- Default settings
- GOMAXPROCS variations (1, 2, 4, 8)
- GOMEMLIMIT variations (256MB, 512MB, 1GB)
- GOGC variations (50, 200, off)
- Combined scenarios (constrained, performance)
# Run only code generation benchmarks
go run ./cmd/benchmark -task=code-gen
# Run only AST parser (memory-intensive)
go run ./cmd/benchmark -task=ast-parserModify cmd/benchmark/main.go to add your own configurations:
configs := []BenchmarkConfig{
{"my-config", 4, 1024, 150},
// MaxProcs, MemLimit(MB), GCPercent
}go run ./cmd/report -input=results/benchmark_results.json -output=BENCHMARK_REPORT.mdThe report includes:
- Executive Summary: Overall statistics
- Task Analysis: Best configurations per task
- Recommendations: Flag tuning guidance based on results
- Complete Data: Full results table
See SAMPLE_REPORT.md for example benchmark results from an Apple M2 with 24GB RAM. Your results will vary based on your hardware.
Key findings from sample run:
- Fastest: GOMAXPROCS=4 (56ms)
- 52 configurations tested across 4 agent tasks
- All runs successful with minimal memory usage
- Optimal sweet spot: 4 cores for these workloads
Run agents independently to test specific scenarios:
go run ./cmd/agents/code_generator \
-files=20 \
-lines=200 \
-output=./generated
# With custom flags
GOMAXPROCS=4 GOGC=200 go run ./cmd/agents/code_generator -files=50go run ./cmd/agents/file_searcher \
-pattern="func" \
-dir=./testdata \
-workers=8
# Memory constrained
GOMEMLIMIT=256MiB GOGC=50 go run ./cmd/agents/file_searchergo run ./cmd/agents/refactor \
-target=./testdata \
-operation=rename \
-old=oldVar \
-new=newVar
# Or add comments
go run ./cmd/agents/refactor -operation=add-commentsgo run ./cmd/agents/ast_parser \
-target=./testdata \
-imports=true \
-funcs=true \
-types=true
# Test memory limits
GOMEMLIMIT=128MiB go run ./cmd/agents/ast_parserThis repository uses Google's Agent Development Kit for Go:
import "google.golang.org/adk"The tools/ package demonstrates creating custom ADK tools for file operations:
FileReadTool- Read filesFileWriteTool- Write filesGrepTool- Search patternsListFilesTool- List directories
GOMAXPROCS=8 GOGC=200 GOMEMLIMIT=2GiBMaximize parallelism, reduce GC frequency.
GOMAXPROCS=2 GOGC=50 GOMEMLIMIT=450MiB # for 512MB containerAggressive GC, respect memory limits.
GOMAXPROCS=16 GOGC=400Maximum performance, plenty of memory.
GOMAXPROCS=4 GOGC=75 GOMEMLIMIT=1GiBFrequent GC for consistent latency.
- Establish Baseline: Run benchmarks with default settings first
- Measure Real Workloads: Use tasks similar to your production code
- Test Under Load: Simulate production traffic patterns
- Monitor in Production: Validate benchmark findings with real metrics
- Container Awareness: Always set GOMEMLIMIT in containerized environments
Each benchmark reports:
- Duration: Total execution time
- Memory Allocated: Bytes allocated during execution
- GC Runs: Number of garbage collection cycles
- GC Pause Time: Total time spent in GC pauses
- Exit Code: Success/failure status
Contributions welcome! Areas for improvement:
- Additional agent tasks (API clients, database operations)
- Cloud-specific optimizations (GKE, Cloud Run)
- Integration with profiling tools (pprof)
- Statistical analysis of results
MIT
Sources: