Skip to content

[BUG][PERFORMANCE]: Fix minor performance issues in llm-guard plugin #1961

@araujof

Description

@araujof

🐞 Bug Summary

The LLM-Guard plugin has minor performance issues that contribute to overall latency. These are lower priority than #1960 but should be addressed for optimal performance.


🧩 Affected Component

  • mcpgateway - API
  • mcpgateway - UI (admin panel)
  • mcpgateway.wrapper - stdio wrapper
  • Federation or Transports
  • CLI, Makefiles, or shell scripts
  • Container setup (Docker/Podman/Compose)
  • Other: plugins/llm-guard

🔍 Performance Issues Identified

Issue Impact Priority
Eager scanner initialization Slow startup P3
Excessive logging overhead I/O per request P3
Vault retrieval not optimized Extra DB queries P3
Generic error handling Poor debuggability P4
Missing metrics No observability P4

📋 Tasks

  • Lazy scanner initialization

    • Initialize scanners on first use, not plugin load
    • Implement scanner pool for reuse
    • Add initialization timing metrics
  • Reduce logging overhead

    • Use lazy log formatting
    • Add log level guards
    • Batch debug logs where possible
  • Optimize vault retrieval

    • Cache vault lookups
    • Batch vault queries
    • Add vault cache invalidation on updates
  • Improve error handling specificity

    • Add specific exception types
    • Include context in error messages
    • Add error categorization for metrics
  • Add comprehensive metrics

    • Scanner initialization time
    • Per-scanner execution time
    • Error rates by type
    • Vault operation latency

🎯 Success Criteria

  • Plugin startup time reduced by 30%
  • Logging overhead < 1ms per request
  • Vault cache hit rate > 90%
  • All errors have actionable messages
  • Metrics available in Prometheus format

🔗 Related Issues

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't workingperformancePerformance related itemspluginsreadyValidated, ready-to-work-on items

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions