From cd7c3fce2472656b2a1247429751e43350976677 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 19 Aug 2026 23:45:38 +0900 Subject: perf(package): hand out link maps behind Rc PackageInterface::getRequires() and friends return the array of Link objects; in PHP that is a copy-on-write array of object references, so a caller pays nothing to look at it. The port returned IndexMap by value, so every call deep-cloned the whole map, keys and constraints included. Pool building calls these accessors once per package per candidate, which put IndexMap::clone at 13.5% of `require laravel/laravel`. Store the maps as Rc> and return a handle. Callers that mutate the map clone it explicitly at the point of mutation, matching where PHP would separate the array. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/package/alias_package.rs | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'crates/shirabe/src/package/alias_package.rs') diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index 9df804f1..4eeb408a 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -39,15 +39,15 @@ pub struct AliasPackage { /// @var BasePackage pub(crate) alias_of: PackageHandle, /// @var Link[] - pub(crate) requires: IndexMap, + pub(crate) requires: std::rc::Rc>, /// @var Link[] - pub(crate) dev_requires: IndexMap, + pub(crate) dev_requires: std::rc::Rc>, /// @var array - pub(crate) conflicts: IndexMap, + pub(crate) conflicts: std::rc::Rc>, /// @var array - pub(crate) provides: IndexMap, + pub(crate) provides: std::rc::Rc>, /// @var array - pub(crate) replaces: IndexMap, + pub(crate) replaces: std::rc::Rc>, } impl AliasPackage { @@ -74,15 +74,15 @@ impl AliasPackage { stability, has_self_version_requires: false, alias_of, - requires: IndexMap::new(), - dev_requires: IndexMap::new(), - conflicts: IndexMap::new(), - provides: IndexMap::new(), - replaces: IndexMap::new(), + requires: std::rc::Rc::new(IndexMap::new()), + dev_requires: std::rc::Rc::new(IndexMap::new()), + conflicts: std::rc::Rc::new(IndexMap::new()), + provides: std::rc::Rc::new(IndexMap::new()), + replaces: std::rc::Rc::new(IndexMap::new()), }; for r#type in Link::types() { - let links: IndexMap = match r#type { + let links: std::rc::Rc> = match r#type { Link::TYPE_REQUIRE => this.alias_of.get_requires(), Link::TYPE_DEV_REQUIRE => this.alias_of.get_dev_requires(), Link::TYPE_PROVIDE => this.alias_of.get_provides(), @@ -90,7 +90,8 @@ impl AliasPackage { Link::TYPE_REPLACE => this.alias_of.get_replaces(), _ => unreachable!(), }; - let replaced = this.replace_self_version_dependencies(links, r#type); + let replaced = + std::rc::Rc::new(this.replace_self_version_dependencies((*links).clone(), r#type)); match r#type { Link::TYPE_REQUIRE => this.requires = replaced, Link::TYPE_DEV_REQUIRE => this.dev_requires = replaced, @@ -252,27 +253,27 @@ impl PackageInterface for AliasPackage { &self.pretty_version } - fn get_requires(&self) -> IndexMap { - self.requires.clone() + fn get_requires(&self) -> std::rc::Rc> { + std::rc::Rc::clone(&self.requires) } /// @inheritDoc - fn get_conflicts(&self) -> IndexMap { - self.conflicts.clone() + fn get_conflicts(&self) -> std::rc::Rc> { + std::rc::Rc::clone(&self.conflicts) } /// @inheritDoc - fn get_provides(&self) -> IndexMap { - self.provides.clone() + fn get_provides(&self) -> std::rc::Rc> { + std::rc::Rc::clone(&self.provides) } /// @inheritDoc - fn get_replaces(&self) -> IndexMap { - self.replaces.clone() + fn get_replaces(&self) -> std::rc::Rc> { + std::rc::Rc::clone(&self.replaces) } - fn get_dev_requires(&self) -> IndexMap { - self.dev_requires.clone() + fn get_dev_requires(&self) -> std::rc::Rc> { + std::rc::Rc::clone(&self.dev_requires) } fn get_type(&self) -> String { -- cgit v1.3.1-4-g156e