perf(ai): decouple AI suite from startup and enable lazy loading across services and CLI
- Decouple connapp.ai from get_parser() via DeferredAIProxy to queue plugin modifications without importing connpy.ai or Pydantic v2 upfront. - Guard connapp.start() finally block to invoke ai.cleanup() only if connpy.ai was actively imported. - Defer CopilotInterface and AIService imports in core.py to execute strictly upon receiving Copilot hotkey (\x00). - Convert heavy services (ai, sync, users, import_export, system, execution) into lazy properties on ServiceProvider and services/__init__.py. - Implement O(1) globals() dict caching in module __getattr__ (PEP 562) across connpy/__init__.py and services/__init__.py. - Defer Google Drive SDK in sync_service.py and interactive CLI components (inquirer) across handlers. - Reduced CLI startup & parser initialization latency from ~1.47s to ~183ms (~87% improvement).
This commit is contained in:
1 parent
bf5bddda5a
commit
835283eba6
8 files changed
+72
-20
No files matched your search
+3
-2
@@ -712,13 +712,14 @@ class node:
|
||||
|
||||
def _copilot_handler(self, config):
|
||||
"""Unified copilot handler for local session."""
|
||||
from .cli.terminal_ui import CopilotInterface
|
||||
from .services.ai_service import AIService
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
async def handler(buffer, node_info, stream, child_fd, cmd_byte_positions=None):
|
||||
try:
|
||||
from .cli.terminal_ui import CopilotInterface
|
||||
from .services.ai_service import AIService
|
||||
|
||||
interface = CopilotInterface(
|
||||
config,
|
||||
history=getattr(stream, 'copilot_history', None),
|
||||
|
||||
Reference in new issue
Block a user