vtcode_core/tools/registry/
optimization_facade.rs1use std::sync::Arc;
4
5use crate::core::memory_pool::MemoryPool;
6
7use super::ToolRegistry;
8
9impl ToolRegistry {
10 pub fn has_optimizations_enabled(&self) -> bool {
12 self.optimization_config
13 .tool_registry
14 .use_optimized_registry
15 || self.optimization_config.memory_pool.enabled
16 }
17
18 pub fn memory_pool_ref(&self) -> &MemoryPool {
20 self.memory_pool.as_ref()
21 }
22
23 pub fn memory_pool(&self) -> &Arc<MemoryPool> {
25 &self.memory_pool
26 }
27
28 pub fn clear_hot_cache(&self) {
30 if self
31 .optimization_config
32 .tool_registry
33 .use_optimized_registry
34 {
35 self.hot_tool_cache.write().clear();
36 }
37 }
38
39 pub fn hot_cache_stats(&self) -> (usize, usize) {
41 let cache = self.hot_tool_cache.read();
42 (cache.len(), cache.cap().get())
43 }
44
45 pub fn configure_optimizations(&mut self, config: vtcode_config::OptimizationConfig) {
47 self.optimization_config = config;
48
49 if self
51 .optimization_config
52 .tool_registry
53 .use_optimized_registry
54 {
55 let new_size = self.optimization_config.tool_registry.hot_cache_size;
56 if let Some(new_cache_size) = std::num::NonZeroUsize::new(new_size) {
57 *self.hot_tool_cache.write() = lru::LruCache::new(new_cache_size);
58 }
59 }
60 }
61
62 pub fn optimization_config(&self) -> &vtcode_config::OptimizationConfig {
64 &self.optimization_config
65 }
66}