Skip to content

[PERFORMANCE]: Remove exc_info=True from Plugin Manager critical path #2064

@araujof

Description

@araujof

Summary

Critical Finding: The plugin framework spends ~80% of execution time formatting exception tracebacks that are never thrown or displayed.

Impact: For a typical plugin hook invocation taking 0.207ms:

  • 0.165ms (80%) - Exception/traceback formatting
  • 0.042ms (20%) - Actual plugin execution

Root Cause: exc_info=True in logger.error() calls within exception handlers in hot path.

Tasks

Remove exc_info=True (CRITICAL - 6.7x speedup)

Change in mcpgateway/plugins/framework/manager.py:

Before (Lines 284, 288):

logger.error("Plugin %s failed with error: %s", hook_ref.plugin_ref.name, str(pe), exc_info=True)
logger.error("Plugin %s failed with error: %s", hook_ref.plugin_ref.name, str(e), exc_info=True)

After:

logger.error("Plugin %s failed with error: %s", hook_ref.plugin_ref.name, str(pe))
logger.error("Plugin %s failed with error: %s", hook_ref.plugin_ref.name, str(e))

Rationale:

  • Exception details are already in the error message via str(pe) and str(e)
  • Full traceback is rarely needed for plugin errors
  • If traceback is needed, it can be enabled via logging configuration
  • Removes 80% of execution overhead

Expected Impact:

  • Reduce hook execution time from ~0.207ms to ~0.047ms (4.4x faster)
  • Improve throughput from ~4,800 hooks/sec to ~21,000 hooks/sec

Metadata

Metadata

Assignees

Labels

performancePerformance related itemspluginspythonPython / backend development (FastAPI)

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions