Skip to content

Commit 13b7588

Browse files
⚡ perf: cache tech.toml parsing during dependency resolution
Introduces a HashMap to cache the parsed entry paths from `tech.toml` files during module resolution in `cli/src/project.rs`. This avoids redundantly reading and parsing the TOML manifest when a package is imported multiple times. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com>
1 parent 43c970d commit 13b7588

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎.gitignore‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,10 @@ bin/
8282
build/
8383
dist/
8484
site/
85+
mock_heavy_project/
86+
mock_project/
87+
mock_project_fast/
88+
run_bench.sh
89+
run_heavy_bench.sh
90+
mock_many_imports/
91+
run_many_imports.sh

‎cli/src/project.rs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl ProjectBuildGraph {
163163

164164
// 2. Resolve imports recursively
165165
let mut visited = HashSet::new();
166+
let mut manifest_cache: HashMap<PathBuf, String> = HashMap::new();
166167
while let Some((fid, path, pkg_name)) = to_resolve.pop() {
167168
if visited.contains(&fid) {
168169
continue;
@@ -256,14 +257,18 @@ impl ProjectBuildGraph {
256257
}
257258
if !try_file.exists() {
258259
let manifest_toml = pkg_path.join("tech.toml");
259-
if manifest_toml.exists() {
260+
if let Some(cached_entry) = manifest_cache.get(&manifest_toml) {
261+
try_file = pkg_path.join(cached_entry);
262+
} else if manifest_toml.exists() {
260263
if let Ok(toml_content) = std::fs::read_to_string(&manifest_toml) {
261264
if let Ok(manifest) =
262265
toml::from_str::<techscript_package_manager::Manifest>(
263266
&toml_content,
264267
)
265268
{
266-
try_file = pkg_path.join(manifest.package.entry);
269+
let entry = manifest.package.entry;
270+
try_file = pkg_path.join(&entry);
271+
manifest_cache.insert(manifest_toml, entry);
267272
}
268273
}
269274
}

0 commit comments

Comments
 (0)