Expand description
Optimized thread-local parser infrastructure
This module provides an optimized thread-local parser pool that eliminates duplication and reduces initialization overhead across the codebase.
§Performance Optimizations
- OnceLock initialization - Parser created once per thread, not on every call
- Direct language detection - Uses Language::from_extension directly
- Reduced RefCell overhead - Single borrow per parse operation
- Centralized API - Eliminates code duplication across CLI commands
§Usage
use infiniloom_engine::parser::parse_file_symbols;
use std::path::Path;
let content = "fn main() {}";
let path = Path::new("src/main.rs");
let symbols = parse_file_symbols(content, path);§Migration from Old Pattern
Before (duplicated in 3 places):
ⓘ
use std::cell::RefCell;
use crate::parser::{Parser, Language};
thread_local! {
static THREAD_PARSER: RefCell<Parser> = RefCell::new(Parser::new());
}
let symbols = THREAD_PARSER.with(|parser| {
let mut parser = parser.borrow_mut();
if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
if let Some(lang) = Language::from_extension(ext) {
parser.parse(content, lang).unwrap_or_default()
} else {
Vec::new()
}
} else {
Vec::new()
}
});After (centralized):
ⓘ
use infiniloom_engine::parser::parse_file_symbols;
let symbols = parse_file_symbols(content, path);Functions§
- parse_
file_ symbols - Parse file content using optimized thread-local parser
- parse_
with_ language - Parse content with explicit language (bypasses extension detection)