Skip to content

Conversation

@smoreinis
Copy link
Collaborator

Summary

  • Add @lru_cache to repository and service factories for singleton behavior
  • Initialize AgentsUseCase on app.state during startup to bypass FastAPI DI
  • Pre-compute authorized resources in auth middleware instead of per-route DI
  • Update list_agents route to use cached services from request.state and app.state

Performance Results

Metric Before After Improvement
Throughput 304 req/s 587 req/s +93%
Avg Latency 33ms 18ms -45%

Profiling Breakdown

FastAPI DI overhead reduced from 31% to 2.5% of request time.

Test Plan

  • Unit tests pass (make test-unit)
  • Integration tests
  • Manual load test verification

- Add @lru_cache to repository and service factories for singleton behavior
- Initialize AgentsUseCase on app.state during startup to bypass DI
- Pre-compute authorized resources in auth middleware instead of per-route
- Update list_agents route to use cached services from request/app state

Performance improvement: ~93% throughput increase (304 → 587 req/s)
Latency reduction: ~45% (33ms → 18ms avg)
- Clear cached repository factories before each test
- Clear cached temporal adapter and agents use case
- Initialize app.state in test fixture for list_agents route
- Use is_enabled() method call for testability in middleware
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.

2 participants