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 async_pipeline: AsyncPipelineConfig,
20
21 #[serde(default)]
23 llm_client: LLMClientConfig,
24
25 #[serde(default)]
27 pub agent_execution: AgentExecutionConfig,
28
29 #[serde(default)]
31 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)]
45#[serde(default)]
46pub struct FileReadCacheConfig {
47 pub enabled: bool,
49
50 pub min_size_bytes: usize,
52
53 pub max_size_bytes: usize,
55
56 pub ttl_secs: u64,
58
59 max_entries: usize,
61
62 #[serde(default = "default_max_read_lines")]
66 pub max_read_lines: usize,
67}
68
69fn default_max_read_lines() -> usize {
71 crate::constants::optimization::DEFAULT_MAX_READ_LINES
72}
73
74#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(default)]
78pub struct CommandCacheConfig {
79 pub enabled: bool,
81
82 pub ttl_ms: u64,
84
85 pub max_entries: usize,
87
88 pub allowlist: Vec<String>,
90}
91
92#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
94#[derive(Debug, Clone, Serialize, Deserialize)]
95#[serde(default)]
96pub struct MemoryPoolConfig {
97 pub enabled: bool,
99
100 pub max_string_pool_size: usize,
102
103 pub max_value_pool_size: usize,
105
106 pub max_vec_pool_size: usize,
108}
109
110#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
112#[derive(Debug, Clone, Serialize, Deserialize)]
113#[serde(default)]
114pub struct ToolRegistryConfig {
115 pub use_optimized_registry: bool,
117
118 max_concurrent_tools: usize,
120
121 pub hot_cache_size: usize,
123
124 default_timeout_secs: u64,
130
131 pub middleware_fail_open: bool,
135}
136
137#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(default)]
141pub struct AsyncPipelineConfig {
142 enable_batching: bool,
144
145 enable_caching: bool,
147
148 max_batch_size: usize,
150
151 batch_timeout_ms: u64,
153
154 cache_size: usize,
156}
157
158#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(default)]
162pub struct LLMClientConfig {
163 enable_connection_pooling: bool,
165
166 enable_response_caching: bool,
168
169 enable_request_batching: bool,
171
172 connection_pool_size: usize,
174
175 response_cache_size: usize,
177
178 cache_ttl_secs: u64,
180
181 rate_limit_rps: f64,
183
184 rate_limit_burst: usize,
186}
187
188#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(default)]
192pub struct AgentExecutionConfig {
193 use_optimized_loop: bool,
195
196 enable_performance_prediction: bool,
198
199 state_history_size: usize,
201
202 resource_monitor_interval_ms: u64,
204
205 max_memory_mb: u64,
207
208 pub max_execution_time_secs: u64,
210
211 pub idle_timeout_ms: u64,
214
215 pub idle_backoff_ms: u64,
218
219 pub max_idle_cycles: usize,
221}
222
223#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
225#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(default)]
227pub struct ProfilingConfig {
228 enabled: bool,
230
231 monitor_interval_ms: u64,
233
234 max_history_size: usize,
236
237 auto_export_results: bool,
239
240 export_file_path: String,
242
243 enable_regression_testing: bool,
245
246 max_regression_percent: f64,
248}
249
250impl Default for MemoryPoolConfig {
251 fn default() -> Self {
252 Self {
253 enabled: true,
254 max_string_pool_size: 64,
255 max_value_pool_size: 32,
256 max_vec_pool_size: 16,
257 }
258 }
259}
260
261impl Default for FileReadCacheConfig {
262 fn default() -> Self {
263 Self {
264 enabled: true,
265 min_size_bytes: crate::constants::optimization::FILE_READ_CACHE_MIN_SIZE_BYTES,
266 max_size_bytes: crate::constants::optimization::FILE_READ_CACHE_MAX_SIZE_BYTES,
267 ttl_secs: crate::constants::optimization::FILE_READ_CACHE_TTL_SECS,
268 max_entries: crate::constants::optimization::FILE_READ_CACHE_MAX_ENTRIES,
269 max_read_lines: default_max_read_lines(),
272 }
273 }
274}
275
276impl Default for CommandCacheConfig {
277 fn default() -> Self {
278 Self {
279 enabled: true,
280 ttl_ms: crate::constants::optimization::COMMAND_CACHE_TTL_MS,
281 max_entries: crate::constants::optimization::COMMAND_CACHE_MAX_ENTRIES,
282 allowlist: crate::constants::optimization::COMMAND_CACHE_ALLOWLIST
283 .iter()
284 .map(|s| s.to_string())
285 .collect(),
286 }
287 }
288}
289
290impl Default for ToolRegistryConfig {
291 fn default() -> Self {
292 Self {
293 use_optimized_registry: true, max_concurrent_tools: 4,
295 hot_cache_size: 16,
296 default_timeout_secs: 180,
297 middleware_fail_open: false, }
299 }
300}
301
302impl Default for AsyncPipelineConfig {
303 fn default() -> Self {
304 Self {
305 enable_batching: false, enable_caching: true,
307 max_batch_size: 5,
308 batch_timeout_ms: 100,
309 cache_size: 100,
310 }
311 }
312}
313
314impl Default for LLMClientConfig {
315 fn default() -> Self {
316 Self {
317 enable_connection_pooling: false, enable_response_caching: true,
319 enable_request_batching: false, connection_pool_size: 4,
321 response_cache_size: 50,
322 cache_ttl_secs: 300,
323 rate_limit_rps: 10.0,
324 rate_limit_burst: 20,
325 }
326 }
327}
328
329impl Default for AgentExecutionConfig {
330 fn default() -> Self {
331 Self {
332 use_optimized_loop: true, enable_performance_prediction: false, state_history_size: 1000,
335 resource_monitor_interval_ms: 100,
336 max_memory_mb: 1024,
337 max_execution_time_secs: 600,
341 idle_timeout_ms: 5000, idle_backoff_ms: 100, max_idle_cycles: 10, }
345 }
346}
347
348impl Default for ProfilingConfig {
349 fn default() -> Self {
350 Self {
351 enabled: false, monitor_interval_ms: 100,
353 max_history_size: 1000,
354 auto_export_results: false,
355 export_file_path: "benchmark_results.json".to_string(),
356 enable_regression_testing: false,
357 max_regression_percent: 10.0,
358 }
359 }
360}
361
362impl OptimizationConfig {
363 pub fn development() -> Self {
365 Self {
366 memory_pool: MemoryPoolConfig { enabled: true, ..Default::default() },
367 tool_registry: ToolRegistryConfig {
368 use_optimized_registry: true,
369 max_concurrent_tools: 2,
370 middleware_fail_open: false,
371 ..Default::default()
372 },
373 async_pipeline: AsyncPipelineConfig {
374 enable_batching: true,
375 enable_caching: true,
376 max_batch_size: 3,
377 ..Default::default()
378 },
379 llm_client: LLMClientConfig {
380 enable_connection_pooling: true,
381 enable_response_caching: true,
382 connection_pool_size: 2,
383 rate_limit_rps: 5.0,
384 ..Default::default()
385 },
386 agent_execution: AgentExecutionConfig {
387 use_optimized_loop: true,
388 enable_performance_prediction: false, max_memory_mb: 512,
390 idle_timeout_ms: 2000, idle_backoff_ms: 50, max_idle_cycles: 5, ..Default::default()
394 },
395 profiling: ProfilingConfig {
396 enabled: true, auto_export_results: true,
398 ..Default::default()
399 },
400 file_read_cache: FileReadCacheConfig::default(),
401 command_cache: CommandCacheConfig::default(),
402 }
403 }
404
405 pub fn production() -> Self {
407 Self {
408 memory_pool: MemoryPoolConfig {
409 enabled: true,
410 max_string_pool_size: 128,
411 max_value_pool_size: 64,
412 max_vec_pool_size: 32,
413 },
414 tool_registry: ToolRegistryConfig {
415 use_optimized_registry: true,
416 max_concurrent_tools: 8,
417 hot_cache_size: 32,
418 default_timeout_secs: 300,
419 middleware_fail_open: false,
420 },
421 async_pipeline: AsyncPipelineConfig {
422 enable_batching: true,
423 enable_caching: true,
424 max_batch_size: 10,
425 batch_timeout_ms: 50,
426 cache_size: 200,
427 },
428 llm_client: LLMClientConfig {
429 enable_connection_pooling: true,
430 enable_response_caching: true,
431 enable_request_batching: true,
432 connection_pool_size: 8,
433 response_cache_size: 100,
434 cache_ttl_secs: 600,
435 rate_limit_rps: 20.0,
436 rate_limit_burst: 50,
437 },
438 agent_execution: AgentExecutionConfig {
439 use_optimized_loop: true,
440 enable_performance_prediction: true,
441 state_history_size: 2000,
442 resource_monitor_interval_ms: 50,
443 max_memory_mb: 2048,
444 max_execution_time_secs: 600,
445 idle_timeout_ms: 10000, idle_backoff_ms: 200, max_idle_cycles: 20, },
449 profiling: ProfilingConfig {
450 enabled: false, monitor_interval_ms: 1000,
452 max_history_size: 500,
453 auto_export_results: false,
454 export_file_path: "/var/log/vtcode/benchmark_results.json".to_string(),
455 enable_regression_testing: true,
456 max_regression_percent: 5.0,
457 },
458 file_read_cache: FileReadCacheConfig {
459 enabled: true,
460 min_size_bytes: crate::constants::optimization::FILE_READ_CACHE_PROD_MIN_SIZE_BYTES,
461 max_size_bytes: crate::constants::optimization::FILE_READ_CACHE_PROD_MAX_SIZE_BYTES,
462 ttl_secs: crate::constants::optimization::FILE_READ_CACHE_PROD_TTL_SECS,
463 max_entries: crate::constants::optimization::FILE_READ_CACHE_PROD_MAX_ENTRIES,
464 max_read_lines: crate::constants::optimization::DEFAULT_MAX_READ_LINES,
465 },
466 command_cache: CommandCacheConfig {
467 enabled: true,
468 ttl_ms: crate::constants::optimization::COMMAND_CACHE_PROD_TTL_MS,
469 max_entries: crate::constants::optimization::COMMAND_CACHE_PROD_MAX_ENTRIES,
470 allowlist: crate::constants::optimization::COMMAND_CACHE_PROD_ALLOWLIST
471 .iter()
472 .map(|s| s.to_string())
473 .collect(),
474 },
475 }
476 }
477}