mcli-framework 7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mcli-framework might be problematic. Click here for more details.
- mcli/app/chat_cmd.py +42 -0
- mcli/app/commands_cmd.py +226 -0
- mcli/app/completion_cmd.py +216 -0
- mcli/app/completion_helpers.py +288 -0
- mcli/app/cron_test_cmd.py +697 -0
- mcli/app/logs_cmd.py +419 -0
- mcli/app/main.py +492 -0
- mcli/app/model/model.py +1060 -0
- mcli/app/model_cmd.py +227 -0
- mcli/app/redis_cmd.py +269 -0
- mcli/app/video/video.py +1114 -0
- mcli/app/visual_cmd.py +303 -0
- mcli/chat/chat.py +2409 -0
- mcli/chat/command_rag.py +514 -0
- mcli/chat/enhanced_chat.py +652 -0
- mcli/chat/system_controller.py +1010 -0
- mcli/chat/system_integration.py +1016 -0
- mcli/cli.py +25 -0
- mcli/config.toml +20 -0
- mcli/lib/api/api.py +586 -0
- mcli/lib/api/daemon_client.py +203 -0
- mcli/lib/api/daemon_client_local.py +44 -0
- mcli/lib/api/daemon_decorator.py +217 -0
- mcli/lib/api/mcli_decorators.py +1032 -0
- mcli/lib/auth/auth.py +85 -0
- mcli/lib/auth/aws_manager.py +85 -0
- mcli/lib/auth/azure_manager.py +91 -0
- mcli/lib/auth/credential_manager.py +192 -0
- mcli/lib/auth/gcp_manager.py +93 -0
- mcli/lib/auth/key_manager.py +117 -0
- mcli/lib/auth/mcli_manager.py +93 -0
- mcli/lib/auth/token_manager.py +75 -0
- mcli/lib/auth/token_util.py +1011 -0
- mcli/lib/config/config.py +47 -0
- mcli/lib/discovery/__init__.py +1 -0
- mcli/lib/discovery/command_discovery.py +274 -0
- mcli/lib/erd/erd.py +1345 -0
- mcli/lib/erd/generate_graph.py +453 -0
- mcli/lib/files/files.py +76 -0
- mcli/lib/fs/fs.py +109 -0
- mcli/lib/lib.py +29 -0
- mcli/lib/logger/logger.py +611 -0
- mcli/lib/performance/optimizer.py +409 -0
- mcli/lib/performance/rust_bridge.py +502 -0
- mcli/lib/performance/uvloop_config.py +154 -0
- mcli/lib/pickles/pickles.py +50 -0
- mcli/lib/search/cached_vectorizer.py +479 -0
- mcli/lib/services/data_pipeline.py +460 -0
- mcli/lib/services/lsh_client.py +441 -0
- mcli/lib/services/redis_service.py +387 -0
- mcli/lib/shell/shell.py +137 -0
- mcli/lib/toml/toml.py +33 -0
- mcli/lib/ui/styling.py +47 -0
- mcli/lib/ui/visual_effects.py +634 -0
- mcli/lib/watcher/watcher.py +185 -0
- mcli/ml/api/app.py +215 -0
- mcli/ml/api/middleware.py +224 -0
- mcli/ml/api/routers/admin_router.py +12 -0
- mcli/ml/api/routers/auth_router.py +244 -0
- mcli/ml/api/routers/backtest_router.py +12 -0
- mcli/ml/api/routers/data_router.py +12 -0
- mcli/ml/api/routers/model_router.py +302 -0
- mcli/ml/api/routers/monitoring_router.py +12 -0
- mcli/ml/api/routers/portfolio_router.py +12 -0
- mcli/ml/api/routers/prediction_router.py +267 -0
- mcli/ml/api/routers/trade_router.py +12 -0
- mcli/ml/api/routers/websocket_router.py +76 -0
- mcli/ml/api/schemas.py +64 -0
- mcli/ml/auth/auth_manager.py +425 -0
- mcli/ml/auth/models.py +154 -0
- mcli/ml/auth/permissions.py +302 -0
- mcli/ml/backtesting/backtest_engine.py +502 -0
- mcli/ml/backtesting/performance_metrics.py +393 -0
- mcli/ml/cache.py +400 -0
- mcli/ml/cli/main.py +398 -0
- mcli/ml/config/settings.py +394 -0
- mcli/ml/configs/dvc_config.py +230 -0
- mcli/ml/configs/mlflow_config.py +131 -0
- mcli/ml/configs/mlops_manager.py +293 -0
- mcli/ml/dashboard/app.py +532 -0
- mcli/ml/dashboard/app_integrated.py +738 -0
- mcli/ml/dashboard/app_supabase.py +560 -0
- mcli/ml/dashboard/app_training.py +615 -0
- mcli/ml/dashboard/cli.py +51 -0
- mcli/ml/data_ingestion/api_connectors.py +501 -0
- mcli/ml/data_ingestion/data_pipeline.py +567 -0
- mcli/ml/data_ingestion/stream_processor.py +512 -0
- mcli/ml/database/migrations/env.py +94 -0
- mcli/ml/database/models.py +667 -0
- mcli/ml/database/session.py +200 -0
- mcli/ml/experimentation/ab_testing.py +845 -0
- mcli/ml/features/ensemble_features.py +607 -0
- mcli/ml/features/political_features.py +676 -0
- mcli/ml/features/recommendation_engine.py +809 -0
- mcli/ml/features/stock_features.py +573 -0
- mcli/ml/features/test_feature_engineering.py +346 -0
- mcli/ml/logging.py +85 -0
- mcli/ml/mlops/data_versioning.py +518 -0
- mcli/ml/mlops/experiment_tracker.py +377 -0
- mcli/ml/mlops/model_serving.py +481 -0
- mcli/ml/mlops/pipeline_orchestrator.py +614 -0
- mcli/ml/models/base_models.py +324 -0
- mcli/ml/models/ensemble_models.py +675 -0
- mcli/ml/models/recommendation_models.py +474 -0
- mcli/ml/models/test_models.py +487 -0
- mcli/ml/monitoring/drift_detection.py +676 -0
- mcli/ml/monitoring/metrics.py +45 -0
- mcli/ml/optimization/portfolio_optimizer.py +834 -0
- mcli/ml/preprocessing/data_cleaners.py +451 -0
- mcli/ml/preprocessing/feature_extractors.py +491 -0
- mcli/ml/preprocessing/ml_pipeline.py +382 -0
- mcli/ml/preprocessing/politician_trading_preprocessor.py +569 -0
- mcli/ml/preprocessing/test_preprocessing.py +294 -0
- mcli/ml/scripts/populate_sample_data.py +200 -0
- mcli/ml/tasks.py +400 -0
- mcli/ml/tests/test_integration.py +429 -0
- mcli/ml/tests/test_training_dashboard.py +387 -0
- mcli/public/oi/oi.py +15 -0
- mcli/public/public.py +4 -0
- mcli/self/self_cmd.py +1246 -0
- mcli/workflow/daemon/api_daemon.py +800 -0
- mcli/workflow/daemon/async_command_database.py +681 -0
- mcli/workflow/daemon/async_process_manager.py +591 -0
- mcli/workflow/daemon/client.py +530 -0
- mcli/workflow/daemon/commands.py +1196 -0
- mcli/workflow/daemon/daemon.py +905 -0
- mcli/workflow/daemon/daemon_api.py +59 -0
- mcli/workflow/daemon/enhanced_daemon.py +571 -0
- mcli/workflow/daemon/process_cli.py +244 -0
- mcli/workflow/daemon/process_manager.py +439 -0
- mcli/workflow/daemon/test_daemon.py +275 -0
- mcli/workflow/dashboard/dashboard_cmd.py +113 -0
- mcli/workflow/docker/docker.py +0 -0
- mcli/workflow/file/file.py +100 -0
- mcli/workflow/gcloud/config.toml +21 -0
- mcli/workflow/gcloud/gcloud.py +58 -0
- mcli/workflow/git_commit/ai_service.py +328 -0
- mcli/workflow/git_commit/commands.py +430 -0
- mcli/workflow/lsh_integration.py +355 -0
- mcli/workflow/model_service/client.py +594 -0
- mcli/workflow/model_service/download_and_run_efficient_models.py +288 -0
- mcli/workflow/model_service/lightweight_embedder.py +397 -0
- mcli/workflow/model_service/lightweight_model_server.py +714 -0
- mcli/workflow/model_service/lightweight_test.py +241 -0
- mcli/workflow/model_service/model_service.py +1955 -0
- mcli/workflow/model_service/ollama_efficient_runner.py +425 -0
- mcli/workflow/model_service/pdf_processor.py +386 -0
- mcli/workflow/model_service/test_efficient_runner.py +234 -0
- mcli/workflow/model_service/test_example.py +315 -0
- mcli/workflow/model_service/test_integration.py +131 -0
- mcli/workflow/model_service/test_new_features.py +149 -0
- mcli/workflow/openai/openai.py +99 -0
- mcli/workflow/politician_trading/commands.py +1790 -0
- mcli/workflow/politician_trading/config.py +134 -0
- mcli/workflow/politician_trading/connectivity.py +490 -0
- mcli/workflow/politician_trading/data_sources.py +395 -0
- mcli/workflow/politician_trading/database.py +410 -0
- mcli/workflow/politician_trading/demo.py +248 -0
- mcli/workflow/politician_trading/models.py +165 -0
- mcli/workflow/politician_trading/monitoring.py +413 -0
- mcli/workflow/politician_trading/scrapers.py +966 -0
- mcli/workflow/politician_trading/scrapers_california.py +412 -0
- mcli/workflow/politician_trading/scrapers_eu.py +377 -0
- mcli/workflow/politician_trading/scrapers_uk.py +350 -0
- mcli/workflow/politician_trading/scrapers_us_states.py +438 -0
- mcli/workflow/politician_trading/supabase_functions.py +354 -0
- mcli/workflow/politician_trading/workflow.py +852 -0
- mcli/workflow/registry/registry.py +180 -0
- mcli/workflow/repo/repo.py +223 -0
- mcli/workflow/scheduler/commands.py +493 -0
- mcli/workflow/scheduler/cron_parser.py +238 -0
- mcli/workflow/scheduler/job.py +182 -0
- mcli/workflow/scheduler/monitor.py +139 -0
- mcli/workflow/scheduler/persistence.py +324 -0
- mcli/workflow/scheduler/scheduler.py +679 -0
- mcli/workflow/sync/sync_cmd.py +437 -0
- mcli/workflow/sync/test_cmd.py +314 -0
- mcli/workflow/videos/videos.py +242 -0
- mcli/workflow/wakatime/wakatime.py +11 -0
- mcli/workflow/workflow.py +37 -0
- mcli_framework-7.0.0.dist-info/METADATA +479 -0
- mcli_framework-7.0.0.dist-info/RECORD +186 -0
- mcli_framework-7.0.0.dist-info/WHEEL +5 -0
- mcli_framework-7.0.0.dist-info/entry_points.txt +7 -0
- mcli_framework-7.0.0.dist-info/licenses/LICENSE +21 -0
- mcli_framework-7.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main performance optimizer that applies all available optimizations
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import importlib.util
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Any, Dict, Optional
|
|
10
|
+
|
|
11
|
+
from mcli.lib.logger.logger import get_logger
|
|
12
|
+
from mcli.lib.performance.rust_bridge import check_rust_extensions, print_performance_summary
|
|
13
|
+
from mcli.lib.performance.uvloop_config import get_event_loop_info, install_uvloop
|
|
14
|
+
|
|
15
|
+
logger = get_logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PerformanceOptimizer:
|
|
19
|
+
"""Centralized performance optimizer for MCLI"""
|
|
20
|
+
|
|
21
|
+
def __init__(self):
|
|
22
|
+
self.optimizations_applied = {}
|
|
23
|
+
self.rust_status = None
|
|
24
|
+
self.redis_available = False
|
|
25
|
+
self.uvloop_installed = False
|
|
26
|
+
|
|
27
|
+
def apply_all_optimizations(self) -> Dict[str, Any]:
|
|
28
|
+
"""Apply all available performance optimizations"""
|
|
29
|
+
results = {}
|
|
30
|
+
|
|
31
|
+
# 1. Install UVLoop for better async performance
|
|
32
|
+
results["uvloop"] = self._optimize_event_loop()
|
|
33
|
+
|
|
34
|
+
# 2. Check and initialize Rust extensions
|
|
35
|
+
results["rust"] = self._initialize_rust_extensions()
|
|
36
|
+
|
|
37
|
+
# 3. Check Redis availability
|
|
38
|
+
results["redis"] = self._check_redis_availability()
|
|
39
|
+
|
|
40
|
+
# 4. Configure Python optimizations
|
|
41
|
+
results["python"] = self._optimize_python_settings()
|
|
42
|
+
|
|
43
|
+
# 5. Apply environment-specific optimizations
|
|
44
|
+
results["environment"] = self._apply_environment_optimizations()
|
|
45
|
+
|
|
46
|
+
self.optimizations_applied = results
|
|
47
|
+
return results
|
|
48
|
+
|
|
49
|
+
def _optimize_event_loop(self) -> Dict[str, Any]:
|
|
50
|
+
"""Optimize asyncio event loop with UVLoop"""
|
|
51
|
+
try:
|
|
52
|
+
self.uvloop_installed = install_uvloop()
|
|
53
|
+
|
|
54
|
+
loop_info = get_event_loop_info()
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
"success": self.uvloop_installed,
|
|
58
|
+
"loop_type": loop_info.get("type", "unknown"),
|
|
59
|
+
"is_uvloop": loop_info.get("is_uvloop", False),
|
|
60
|
+
"performance_gain": "2-4x faster I/O" if loop_info.get("is_uvloop") else "baseline",
|
|
61
|
+
}
|
|
62
|
+
except Exception as e:
|
|
63
|
+
logger.error(f"Failed to optimize event loop: {e}")
|
|
64
|
+
return {"success": False, "error": str(e)}
|
|
65
|
+
|
|
66
|
+
def _initialize_rust_extensions(self) -> Dict[str, Any]:
|
|
67
|
+
"""Initialize Rust extensions for maximum performance"""
|
|
68
|
+
try:
|
|
69
|
+
self.rust_status = check_rust_extensions()
|
|
70
|
+
|
|
71
|
+
if self.rust_status["available"]:
|
|
72
|
+
# Try to load each extension
|
|
73
|
+
extensions_loaded = {}
|
|
74
|
+
|
|
75
|
+
if self.rust_status["tfidf"]:
|
|
76
|
+
try:
|
|
77
|
+
import mcli_rust
|
|
78
|
+
|
|
79
|
+
# Test TF-IDF
|
|
80
|
+
vectorizer = mcli_rust.TfIdfVectorizer()
|
|
81
|
+
test_docs = ["hello world", "rust is fast"]
|
|
82
|
+
vectorizer.fit_transform(test_docs)
|
|
83
|
+
extensions_loaded["tfidf"] = True
|
|
84
|
+
except Exception as e:
|
|
85
|
+
logger.warning(f"TF-IDF extension test failed: {e}")
|
|
86
|
+
extensions_loaded["tfidf"] = False
|
|
87
|
+
|
|
88
|
+
if self.rust_status["file_watcher"]:
|
|
89
|
+
try:
|
|
90
|
+
import mcli_rust
|
|
91
|
+
|
|
92
|
+
# Test file watcher
|
|
93
|
+
watcher = mcli_rust.FileWatcher()
|
|
94
|
+
extensions_loaded["file_watcher"] = True
|
|
95
|
+
except Exception as e:
|
|
96
|
+
logger.warning(f"File watcher extension test failed: {e}")
|
|
97
|
+
extensions_loaded["file_watcher"] = False
|
|
98
|
+
|
|
99
|
+
if self.rust_status["command_matcher"]:
|
|
100
|
+
try:
|
|
101
|
+
import mcli_rust
|
|
102
|
+
|
|
103
|
+
# Test command matcher
|
|
104
|
+
matcher = mcli_rust.CommandMatcher()
|
|
105
|
+
extensions_loaded["command_matcher"] = True
|
|
106
|
+
except Exception as e:
|
|
107
|
+
logger.warning(f"Command matcher extension test failed: {e}")
|
|
108
|
+
extensions_loaded["command_matcher"] = False
|
|
109
|
+
|
|
110
|
+
if self.rust_status["process_manager"]:
|
|
111
|
+
try:
|
|
112
|
+
import mcli_rust
|
|
113
|
+
|
|
114
|
+
# Test process manager
|
|
115
|
+
manager = mcli_rust.ProcessManager()
|
|
116
|
+
extensions_loaded["process_manager"] = True
|
|
117
|
+
except Exception as e:
|
|
118
|
+
logger.warning(f"Process manager extension test failed: {e}")
|
|
119
|
+
extensions_loaded["process_manager"] = False
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
"success": True,
|
|
123
|
+
"extensions": extensions_loaded,
|
|
124
|
+
"performance_gain": "10-100x faster for compute-intensive operations",
|
|
125
|
+
}
|
|
126
|
+
else:
|
|
127
|
+
return {
|
|
128
|
+
"success": False,
|
|
129
|
+
"reason": "Rust extensions not available",
|
|
130
|
+
"fallback": "Using Python implementations",
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
except Exception as e:
|
|
134
|
+
logger.error(f"Failed to initialize Rust extensions: {e}")
|
|
135
|
+
return {"success": False, "error": str(e)}
|
|
136
|
+
|
|
137
|
+
def _check_redis_availability(self) -> Dict[str, Any]:
|
|
138
|
+
"""Check Redis availability for caching"""
|
|
139
|
+
try:
|
|
140
|
+
import redis
|
|
141
|
+
|
|
142
|
+
# Try to connect to Redis
|
|
143
|
+
client = redis.Redis(host="localhost", port=6379, decode_responses=True)
|
|
144
|
+
client.ping()
|
|
145
|
+
client.close()
|
|
146
|
+
|
|
147
|
+
self.redis_available = True
|
|
148
|
+
return {
|
|
149
|
+
"success": True,
|
|
150
|
+
"performance_gain": "Caching enabled for TF-IDF vectors and command data",
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
except ImportError:
|
|
154
|
+
return {
|
|
155
|
+
"success": False,
|
|
156
|
+
"reason": "Redis package not installed",
|
|
157
|
+
"install_command": "pip install redis",
|
|
158
|
+
}
|
|
159
|
+
except Exception as e:
|
|
160
|
+
return {
|
|
161
|
+
"success": False,
|
|
162
|
+
"reason": f"Redis server not available: {e}",
|
|
163
|
+
"fallback": "In-memory caching only",
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
def _optimize_python_settings(self) -> Dict[str, Any]:
|
|
167
|
+
"""Apply Python-specific optimizations"""
|
|
168
|
+
optimizations = {}
|
|
169
|
+
|
|
170
|
+
# 1. Disable garbage collection during critical operations
|
|
171
|
+
import gc
|
|
172
|
+
|
|
173
|
+
gc.set_threshold(700, 10, 10) # More aggressive GC
|
|
174
|
+
optimizations["gc_tuned"] = True
|
|
175
|
+
|
|
176
|
+
# 2. Optimize import system
|
|
177
|
+
if hasattr(sys, "dont_write_bytecode"):
|
|
178
|
+
# In production, enable bytecode for faster imports
|
|
179
|
+
if not os.environ.get("MCLI_DEBUG"):
|
|
180
|
+
sys.dont_write_bytecode = False
|
|
181
|
+
optimizations["bytecode_enabled"] = True
|
|
182
|
+
|
|
183
|
+
# 3. Set optimal recursion limit
|
|
184
|
+
current_limit = sys.getrecursionlimit()
|
|
185
|
+
if current_limit < 3000:
|
|
186
|
+
sys.setrecursionlimit(3000)
|
|
187
|
+
optimizations["recursion_limit_increased"] = True
|
|
188
|
+
|
|
189
|
+
# 4. Configure multiprocessing
|
|
190
|
+
try:
|
|
191
|
+
import multiprocessing as mp
|
|
192
|
+
|
|
193
|
+
if hasattr(mp, "set_start_method"):
|
|
194
|
+
if sys.platform != "win32":
|
|
195
|
+
mp.set_start_method("fork", force=True)
|
|
196
|
+
optimizations["multiprocessing_optimized"] = True
|
|
197
|
+
except RuntimeError:
|
|
198
|
+
# Start method already set
|
|
199
|
+
pass
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
"success": True,
|
|
203
|
+
"optimizations": optimizations,
|
|
204
|
+
"performance_gain": "Reduced overhead and improved memory management",
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
def _apply_environment_optimizations(self) -> Dict[str, Any]:
|
|
208
|
+
"""Apply environment-specific optimizations"""
|
|
209
|
+
optimizations = {}
|
|
210
|
+
|
|
211
|
+
# 1. Production vs Development optimizations
|
|
212
|
+
if os.environ.get("MCLI_ENV") == "production":
|
|
213
|
+
# Disable debug features
|
|
214
|
+
os.environ["PYTHONOPTIMIZE"] = "1"
|
|
215
|
+
optimizations["debug_disabled"] = True
|
|
216
|
+
|
|
217
|
+
# Enable optimized logging
|
|
218
|
+
logger.setLevel("INFO")
|
|
219
|
+
optimizations["logging_optimized"] = True
|
|
220
|
+
|
|
221
|
+
# 2. Memory optimizations based on available RAM
|
|
222
|
+
try:
|
|
223
|
+
import psutil
|
|
224
|
+
|
|
225
|
+
available_memory = psutil.virtual_memory().available
|
|
226
|
+
|
|
227
|
+
if available_memory > 8 * 1024**3: # 8GB+
|
|
228
|
+
# Large memory optimizations
|
|
229
|
+
os.environ["MCLI_LARGE_CACHE"] = "1"
|
|
230
|
+
optimizations["large_memory_mode"] = True
|
|
231
|
+
elif available_memory < 2 * 1024**3: # <2GB
|
|
232
|
+
# Low memory optimizations
|
|
233
|
+
os.environ["MCLI_LOW_MEMORY"] = "1"
|
|
234
|
+
optimizations["low_memory_mode"] = True
|
|
235
|
+
except ImportError:
|
|
236
|
+
pass
|
|
237
|
+
|
|
238
|
+
# 3. CPU optimizations
|
|
239
|
+
try:
|
|
240
|
+
import psutil
|
|
241
|
+
|
|
242
|
+
cpu_count = psutil.cpu_count()
|
|
243
|
+
|
|
244
|
+
if cpu_count >= 8:
|
|
245
|
+
# Multi-core optimizations
|
|
246
|
+
os.environ["MCLI_PARALLEL_WORKERS"] = str(min(cpu_count - 1, 16))
|
|
247
|
+
optimizations["parallel_processing"] = True
|
|
248
|
+
except ImportError:
|
|
249
|
+
pass
|
|
250
|
+
|
|
251
|
+
# 4. Storage optimizations
|
|
252
|
+
try:
|
|
253
|
+
import shutil
|
|
254
|
+
|
|
255
|
+
total, used, free = shutil.disk_usage("/")
|
|
256
|
+
|
|
257
|
+
if free > 10 * 1024**3: # 10GB+ free
|
|
258
|
+
# Enable aggressive caching
|
|
259
|
+
os.environ["MCLI_AGGRESSIVE_CACHE"] = "1"
|
|
260
|
+
optimizations["aggressive_caching"] = True
|
|
261
|
+
except:
|
|
262
|
+
pass
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
"success": True,
|
|
266
|
+
"optimizations": optimizations,
|
|
267
|
+
"performance_gain": "Environment-specific optimizations applied",
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
def get_optimization_summary(self) -> Dict[str, Any]:
|
|
271
|
+
"""Get a summary of all applied optimizations"""
|
|
272
|
+
if not self.optimizations_applied:
|
|
273
|
+
self.apply_all_optimizations()
|
|
274
|
+
|
|
275
|
+
summary = {
|
|
276
|
+
"total_optimizations": len(self.optimizations_applied),
|
|
277
|
+
"successful_optimizations": sum(
|
|
278
|
+
1 for opt in self.optimizations_applied.values() if opt.get("success", False)
|
|
279
|
+
),
|
|
280
|
+
"estimated_performance_gain": self._estimate_performance_gain(),
|
|
281
|
+
"details": self.optimizations_applied,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return summary
|
|
285
|
+
|
|
286
|
+
def _estimate_performance_gain(self) -> str:
|
|
287
|
+
"""Estimate overall performance gain"""
|
|
288
|
+
gains = []
|
|
289
|
+
|
|
290
|
+
if self.optimizations_applied.get("uvloop", {}).get("success"):
|
|
291
|
+
gains.append("2-4x async I/O performance")
|
|
292
|
+
|
|
293
|
+
if self.optimizations_applied.get("rust", {}).get("success"):
|
|
294
|
+
rust_extensions = self.optimizations_applied["rust"].get("extensions", {})
|
|
295
|
+
if any(rust_extensions.values()):
|
|
296
|
+
gains.append("10-100x compute performance")
|
|
297
|
+
|
|
298
|
+
if self.optimizations_applied.get("redis", {}).get("success"):
|
|
299
|
+
gains.append("Significant caching speedup")
|
|
300
|
+
|
|
301
|
+
if gains:
|
|
302
|
+
return " + ".join(gains)
|
|
303
|
+
else:
|
|
304
|
+
return "Baseline performance with Python optimizations"
|
|
305
|
+
|
|
306
|
+
def benchmark_performance(self, test_size: str = "small") -> Dict[str, Any]:
|
|
307
|
+
"""Run performance benchmarks"""
|
|
308
|
+
from mcli.lib.performance.rust_bridge import PerformanceMonitor
|
|
309
|
+
|
|
310
|
+
monitor = PerformanceMonitor()
|
|
311
|
+
|
|
312
|
+
# Prepare test data
|
|
313
|
+
if test_size == "small":
|
|
314
|
+
documents = [f"test document {i}" for i in range(100)]
|
|
315
|
+
queries = [f"query {i}" for i in range(10)]
|
|
316
|
+
elif test_size == "medium":
|
|
317
|
+
documents = [f"test document {i} with more content" for i in range(1000)]
|
|
318
|
+
queries = [f"query {i}" for i in range(50)]
|
|
319
|
+
else: # large
|
|
320
|
+
documents = [
|
|
321
|
+
f"test document {i} with much more content and details" for i in range(5000)
|
|
322
|
+
]
|
|
323
|
+
queries = [f"query {i}" for i in range(100)]
|
|
324
|
+
|
|
325
|
+
# Run benchmarks
|
|
326
|
+
tfidf_results = monitor.benchmark_tfidf(documents, queries)
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
"test_size": test_size,
|
|
330
|
+
"tfidf_benchmark": tfidf_results,
|
|
331
|
+
"system_info": monitor.get_system_info(),
|
|
332
|
+
"optimization_status": self.get_optimization_summary(),
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
def print_performance_report(self):
|
|
336
|
+
"""Print a detailed performance report"""
|
|
337
|
+
summary = self.get_optimization_summary()
|
|
338
|
+
|
|
339
|
+
print("\n" + "=" * 60)
|
|
340
|
+
print("š MCLI PERFORMANCE OPTIMIZATION REPORT")
|
|
341
|
+
print("=" * 60)
|
|
342
|
+
|
|
343
|
+
print(f"\nš Optimization Summary:")
|
|
344
|
+
print(f" ⢠Total optimizations attempted: {summary['total_optimizations']}")
|
|
345
|
+
print(f" ⢠Successful optimizations: {summary['successful_optimizations']}")
|
|
346
|
+
print(f" ⢠Estimated performance gain: {summary['estimated_performance_gain']}")
|
|
347
|
+
|
|
348
|
+
print(f"\nā” Applied Optimizations:")
|
|
349
|
+
for name, details in summary["details"].items():
|
|
350
|
+
status = "ā
" if details.get("success") else "ā"
|
|
351
|
+
print(f" {status} {name.replace('_', ' ').title()}")
|
|
352
|
+
if details.get("performance_gain"):
|
|
353
|
+
print(f" ā {details['performance_gain']}")
|
|
354
|
+
if details.get("reason"):
|
|
355
|
+
print(f" ā {details['reason']}")
|
|
356
|
+
|
|
357
|
+
print(f"\nš§ Recommendations:")
|
|
358
|
+
|
|
359
|
+
# Rust extensions
|
|
360
|
+
if not self.optimizations_applied.get("rust", {}).get("success"):
|
|
361
|
+
print(" ⢠Install Rust and build extensions for maximum performance:")
|
|
362
|
+
print(" cd mcli_rust && cargo build --release")
|
|
363
|
+
|
|
364
|
+
# Redis
|
|
365
|
+
if not self.optimizations_applied.get("redis", {}).get("success"):
|
|
366
|
+
print(" ⢠Install and start Redis for caching:")
|
|
367
|
+
print(" docker run -d -p 6379:6379 redis:alpine")
|
|
368
|
+
|
|
369
|
+
# UVLoop
|
|
370
|
+
if not self.optimizations_applied.get("uvloop", {}).get("success"):
|
|
371
|
+
print(" ⢠Install UVLoop for better async performance:")
|
|
372
|
+
print(" pip install uvloop")
|
|
373
|
+
|
|
374
|
+
print("\n" + "=" * 60)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
# Global optimizer instance
|
|
378
|
+
_global_optimizer: Optional[PerformanceOptimizer] = None
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def get_global_optimizer() -> PerformanceOptimizer:
|
|
382
|
+
"""Get the global performance optimizer instance"""
|
|
383
|
+
global _global_optimizer
|
|
384
|
+
|
|
385
|
+
if _global_optimizer is None:
|
|
386
|
+
_global_optimizer = PerformanceOptimizer()
|
|
387
|
+
|
|
388
|
+
return _global_optimizer
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def apply_optimizations() -> Dict[str, Any]:
|
|
392
|
+
"""Apply all available optimizations"""
|
|
393
|
+
optimizer = get_global_optimizer()
|
|
394
|
+
return optimizer.apply_all_optimizations()
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def print_optimization_report():
|
|
398
|
+
"""Print the optimization report"""
|
|
399
|
+
optimizer = get_global_optimizer()
|
|
400
|
+
optimizer.print_performance_report()
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
# Auto-apply optimizations when module is imported (can be disabled)
|
|
404
|
+
if os.environ.get("MCLI_AUTO_OPTIMIZE", "1").lower() not in ("0", "false", "no"):
|
|
405
|
+
_optimization_results = apply_optimizations()
|
|
406
|
+
|
|
407
|
+
# Print summary if in debug mode
|
|
408
|
+
if os.environ.get("MCLI_DEBUG") or os.environ.get("MCLI_SHOW_OPTIMIZATIONS"):
|
|
409
|
+
print_optimization_report()
|