1use serde::{Deserialize, Serialize};
4
5#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
7#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8pub struct OptimizationConfig {
9 #[serde(default)]
11 pub memory_pool: MemoryPoolConfig,
12
13 #[serde(default)]
15 pub tool_registry: ToolRegistryConfig,
16
17 #[serde(default)]
19 pub async_pipeline: AsyncPipelineConfig,
20
21 #[serde(default)]
23 pub llm_client: LLMClientConfig,
24
25 #[serde(default)]
27 pub agent_execution: AgentExecutionConfig,
28
29 #[serde(default)]
31 pub profiling: ProfilingConfig,
32
33 #[serde(default)]
35 pub file_read_cache: FileReadCacheConfig,
36
37 #[serde(default)]
39 pub command_cache: CommandCacheConfig,
40}
41
42#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct FileReadCacheConfig {
46 pub enabled: bool,
48
49 pub min_size_bytes: usize,
51
52 pub max_size_bytes: usize,
54
55 pub ttl_secs: u64,
57
58 pub max_entries: usize,
60}
61
62#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct CommandCacheConfig {
66 pub enabled: bool,
68
69 pub ttl_ms: u64,
71
72 pub max_entries: usize,
74
75 pub allowlist: Vec<String>,
77}
78
79#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct MemoryPoolConfig {
83 pub enabled: bool,
85
86 pub max_string_pool_size: usize,
88
89 pub max_value_pool_size: usize,
91
92 pub max_vec_pool_size: usize,
94}
95
96#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct ToolRegistryConfig {
100 pub use_optimized_registry: bool,
102
103 pub max_concurrent_tools: usize,
105
106 pub hot_cache_size: usize,
108
109 pub default_timeout_secs: u64,
111}
112
113#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
115#[derive(Debug, Clone, Serialize, Deserialize)]
116pub struct AsyncPipelineConfig {
117 pub enable_batching: bool,
119
120 pub enable_caching: bool,
122
123 pub max_batch_size: usize,
125
126 pub batch_timeout_ms: u64,
128
129 pub cache_size: usize,
131}
132
133#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136pub struct LLMClientConfig {
137 pub enable_connection_pooling: bool,
139
140 pub enable_response_caching: bool,
142
143 pub enable_request_batching: bool,
145
146 pub connection_pool_size: usize,
148
149 pub response_cache_size: usize,
151
152 pub cache_ttl_secs: u64,
154
155 pub rate_limit_rps: f64,
157
158 pub rate_limit_burst: usize,
160}
161
162#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
164#[derive(Debug, Clone, Serialize, Deserialize)]
165pub struct AgentExecutionConfig {
166 pub use_optimized_loop: bool,
168
169 pub enable_performance_prediction: bool,
171
172 pub state_history_size: usize,
174
175 pub resource_monitor_interval_ms: u64,
177
178 pub max_memory_mb: u64,
180
181 pub max_execution_time_secs: u64,
183
184 pub idle_timeout_ms: u64,
187
188 pub idle_backoff_ms: u64,
191
192 pub max_idle_cycles: usize,
194}
195
196#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
198#[derive(Debug, Clone, Serialize, Deserialize)]
199pub struct ProfilingConfig {
200 pub enabled: bool,
202
203 pub monitor_interval_ms: u64,
205
206 pub max_history_size: usize,
208
209 pub auto_export_results: bool,
211
212 pub export_file_path: String,
214
215 pub enable_regression_testing: bool,
217
218 pub max_regression_percent: f64,
220}
221
222impl Default for MemoryPoolConfig {
223 fn default() -> Self {
224 Self {
225 enabled: true,
226 max_string_pool_size: 64,
227 max_value_pool_size: 32,
228 max_vec_pool_size: 16,
229 }
230 }
231}
232
233impl Default for FileReadCacheConfig {
234 fn default() -> Self {
235 Self {
236 enabled: true,
237 min_size_bytes: crate::constants::optimization::FILE_READ_CACHE_MIN_SIZE_BYTES,
238 max_size_bytes: crate::constants::optimization::FILE_READ_CACHE_MAX_SIZE_BYTES,
239 ttl_secs: crate::constants::optimization::FILE_READ_CACHE_TTL_SECS,
240 max_entries: crate::constants::optimization::FILE_READ_CACHE_MAX_ENTRIES,
241 }
242 }
243}
244
245impl Default for CommandCacheConfig {
246 fn default() -> Self {
247 Self {
248 enabled: true,
249 ttl_ms: crate::constants::optimization::COMMAND_CACHE_TTL_MS,
250 max_entries: crate::constants::optimization::COMMAND_CACHE_MAX_ENTRIES,
251 allowlist: crate::constants::optimization::COMMAND_CACHE_ALLOWLIST
252 .iter()
253 .map(|s| s.to_string())
254 .collect(),
255 }
256 }
257}
258
259impl Default for ToolRegistryConfig {
260 fn default() -> Self {
261 Self {
262 use_optimized_registry: true, max_concurrent_tools: 4,
264 hot_cache_size: 16,
265 default_timeout_secs: 180,
266 }
267 }
268}
269
270impl Default for AsyncPipelineConfig {
271 fn default() -> Self {
272 Self {
273 enable_batching: false, enable_caching: true,
275 max_batch_size: 5,
276 batch_timeout_ms: 100,
277 cache_size: 100,
278 }
279 }
280}
281
282impl Default for LLMClientConfig {
283 fn default() -> Self {
284 Self {
285 enable_connection_pooling: false, enable_response_caching: true,
287 enable_request_batching: false, connection_pool_size: 4,
289 response_cache_size: 50,
290 cache_ttl_secs: 300,
291 rate_limit_rps: 10.0,
292 rate_limit_burst: 20,
293 }
294 }
295}
296
297impl Default for AgentExecutionConfig {
298 fn default() -> Self {
299 Self {
300 use_optimized_loop: true, enable_performance_prediction: false, state_history_size: 1000,
303 resource_monitor_interval_ms: 100,
304 max_memory_mb: 1024,
305 max_execution_time_secs: 300,
306 idle_timeout_ms: 5000, idle_backoff_ms: 100, max_idle_cycles: 10, }
310 }
311}
312
313impl Default for ProfilingConfig {
314 fn default() -> Self {
315 Self {
316 enabled: false, monitor_interval_ms: 100,
318 max_history_size: 1000,
319 auto_export_results: false,
320 export_file_path: "benchmark_results.json".to_string(),
321 enable_regression_testing: false,
322 max_regression_percent: 10.0,
323 }
324 }
325}
326
327impl OptimizationConfig {
328 pub fn development() -> Self {
330 Self {
331 memory_pool: MemoryPoolConfig {
332 enabled: true,
333 ..Default::default()
334 },
335 tool_registry: ToolRegistryConfig {
336 use_optimized_registry: true,
337 max_concurrent_tools: 2,
338 ..Default::default()
339 },
340 async_pipeline: AsyncPipelineConfig {
341 enable_batching: true,
342 enable_caching: true,
343 max_batch_size: 3,
344 ..Default::default()
345 },
346 llm_client: LLMClientConfig {
347 enable_connection_pooling: true,
348 enable_response_caching: true,
349 connection_pool_size: 2,
350 rate_limit_rps: 5.0,
351 ..Default::default()
352 },
353 agent_execution: AgentExecutionConfig {
354 use_optimized_loop: true,
355 enable_performance_prediction: false, max_memory_mb: 512,
357 idle_timeout_ms: 2000, idle_backoff_ms: 50, max_idle_cycles: 5, ..Default::default()
361 },
362 profiling: ProfilingConfig {
363 enabled: true, auto_export_results: true,
365 ..Default::default()
366 },
367 file_read_cache: FileReadCacheConfig::default(),
368 command_cache: CommandCacheConfig::default(),
369 }
370 }
371
372 pub fn production() -> Self {
374 Self {
375 memory_pool: MemoryPoolConfig {
376 enabled: true,
377 max_string_pool_size: 128,
378 max_value_pool_size: 64,
379 max_vec_pool_size: 32,
380 },
381 tool_registry: ToolRegistryConfig {
382 use_optimized_registry: true,
383 max_concurrent_tools: 8,
384 hot_cache_size: 32,
385 default_timeout_secs: 300,
386 },
387 async_pipeline: AsyncPipelineConfig {
388 enable_batching: true,
389 enable_caching: true,
390 max_batch_size: 10,
391 batch_timeout_ms: 50,
392 cache_size: 200,
393 },
394 llm_client: LLMClientConfig {
395 enable_connection_pooling: true,
396 enable_response_caching: true,
397 enable_request_batching: true,
398 connection_pool_size: 8,
399 response_cache_size: 100,
400 cache_ttl_secs: 600,
401 rate_limit_rps: 20.0,
402 rate_limit_burst: 50,
403 },
404 agent_execution: AgentExecutionConfig {
405 use_optimized_loop: true,
406 enable_performance_prediction: true,
407 state_history_size: 2000,
408 resource_monitor_interval_ms: 50,
409 max_memory_mb: 2048,
410 max_execution_time_secs: 600,
411 idle_timeout_ms: 10000, idle_backoff_ms: 200, max_idle_cycles: 20, },
415 profiling: ProfilingConfig {
416 enabled: false, monitor_interval_ms: 1000,
418 max_history_size: 500,
419 auto_export_results: false,
420 export_file_path: "/var/log/vtcode/benchmark_results.json".to_string(),
421 enable_regression_testing: true,
422 max_regression_percent: 5.0,
423 },
424 file_read_cache: FileReadCacheConfig {
425 enabled: true,
426 min_size_bytes: crate::constants::optimization::FILE_READ_CACHE_PROD_MIN_SIZE_BYTES,
427 max_size_bytes: crate::constants::optimization::FILE_READ_CACHE_PROD_MAX_SIZE_BYTES,
428 ttl_secs: crate::constants::optimization::FILE_READ_CACHE_PROD_TTL_SECS,
429 max_entries: crate::constants::optimization::FILE_READ_CACHE_PROD_MAX_ENTRIES,
430 },
431 command_cache: CommandCacheConfig {
432 enabled: true,
433 ttl_ms: crate::constants::optimization::COMMAND_CACHE_PROD_TTL_MS,
434 max_entries: crate::constants::optimization::COMMAND_CACHE_PROD_MAX_ENTRIES,
435 allowlist: crate::constants::optimization::COMMAND_CACHE_PROD_ALLOWLIST
436 .iter()
437 .map(|s| s.to_string())
438 .collect(),
439 },
440 }
441 }
442}