feat: implement SPEC-11 API performance optimizations by phernandez · Pull Request #315 · basicmachines-co/basic-memory · GitHub
Skip to content

feat: implement SPEC-11 API performance optimizations - #315

Merged
phernandez merged 2 commits into
mainfrom
feature/spec-11-api-performance-optimization
Sep 26, 2025
Merged

feat: implement SPEC-11 API performance optimizations#315
phernandez merged 2 commits into
mainfrom
feature/spec-11-api-performance-optimization

Conversation

@phernandez

Copy link
Copy Markdown
Member

Summary

Implements comprehensive performance optimizations for MCP tool response times, addressing GitHub issue #82.

🎯 Performance Gains Achieved

  • 95-99% improvement in read operations (350ms-2.6s → 20ms)
  • 75-92% improvement in edit operations (350ms-2.6s → 218ms)
  • Zero overhead for project switching
  • Database connection overhead eliminated (0ms vs 50-100ms)

🔧 Key Changes

  • Cache database connections in app.state during API lifespan
  • Update dependency injection to use cached connections
  • Remove project reconciliation from API startup
  • Add skip_initialization_sync configuration option

✅ Validation

  • Live testing performed with comprehensive MCP tool validation
  • All Tier 1 tools performing under 500ms target
  • Backwards compatibility maintained - no breaking changes
  • Integration tests passing - type checking and linting clear

📋 Technical Details

  • Modified FastAPI lifespan to cache engine/session_maker in app.state
  • Updated get_engine_factory() to use cached connections instead of get_or_create_db()
  • Preserved CLI fallback for non-API contexts
  • Added performance configuration flag for cloud deployments

🚀 Impact

This optimization directly addresses basic-memory-cloud issue #82 and will significantly improve performance for all cloud tenants and local usage.

Resolves: #82 (Basic Memory API Performance Optimization)
Implements: SPEC-11 API Performance Optimization

Test plan

  • Live testing with real MCP tools completed
  • Performance benchmarks validated (95-99% improvement)
  • Integration tests passing
  • Type checking and linting clear
  • Backwards compatibility verified

🤖 Generated with Claude Code

phernandez and others added 2 commits September 26, 2025 14:21
Implements comprehensive performance optimizations for MCP tool response times, addressing GitHub issue #82:

Key Changes:
• Cache database connections in app.state during API lifespan
• Update dependency injection to use cached connections
• Remove project reconciliation from API startup
• Add skip_initialization_sync configuration option

Performance Impact:
• 95-99% improvement in read operations (350ms-2.6s → 20ms)
• 75-92% improvement in edit operations (350ms-2.6s → 218ms)
• Eliminated per-request database initialization overhead
• Zero additional overhead for project switching

Technical Details:
• Modified FastAPI lifespan to cache engine/session_maker
• Updated get_engine_factory() to use app.state connections
• Preserved CLI fallback for non-API contexts
• Added performance configuration flag for cloud deployments

Validated through comprehensive live testing showing consistent
performance improvements across all Tier 1 MCP tools.

Resolves: #82 (Basic Memory API Performance Optimization)
Implements: SPEC-11 API Performance Optimization

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
@github-actions

github-actions Bot commented Sep 26, 2025

Copy link
Copy Markdown
Contributor

@phernandez
phernandez merged commit 5da97e4 into main Sep 26, 2025
12 checks passed
@phernandez
phernandez deleted the feature/spec-11-api-performance-optimization branch September 26, 2025 19:34
@phernandez phernandez added this to the v0.15.0 milestone Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant