aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-20 01:54:09 +0900
committernsfisis <nsfisis@gmail.com>2026-08-20 02:49:30 +0900
commit80c2120a64ce9b989da288ce1fcf80dec5cf38c1 (patch)
treedca0844c4d037db685591e5dacc04fbd11263fb2 /crates/shirabe
parentad335434e5376d29f38882d0dceb2461bfd8d5c6 (diff)
downloadphp-shirabe-80c2120a64ce9b989da288ce1fcf80dec5cf38c1.tar.gz
php-shirabe-80c2120a64ce9b989da288ce1fcf80dec5cf38c1.tar.zst
php-shirabe-80c2120a64ce9b989da288ce1fcf80dec5cf38c1.zip
perf(semver): build CompilingMatcher's cache key without allocating
CompilingMatcher::match formats `<operator><constraint>;<version>` into a fresh String on every call, including the cache hits the key exists to serve. Profiling put the formatting at 2.9 % of self time, more than the match it guards. Build the key into a reused thread-local buffer and copy it only when there is a miss to record. Taking the version as `&str` rather than `String` removes the copy the callers made for the same reason: `optimize_by_identical_dependencies` allocated one per candidate package in its innermost loop. laravel/framework require --no-install (warm cache, network disabled): instructions:u 9142799608 -> 8895247586 (-2.7 %) cycles:u 4626440169 -> 4496152041 (-2.8 %) wall (hyperfine, 25 runs) 1.239 s +- 0.014 s -> 1.227 s +- 0.016 s (-1.0 %) monolog/monolog is unchanged (102.1 ms -> 101.6 ms, within noise). composer.lock is byte-identical for both packages. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe')
-rw-r--r--crates/shirabe/src/dependency_resolver/default_policy.rs2
-rw-r--r--crates/shirabe/src/dependency_resolver/pool.rs2
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_builder.rs2
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_optimizer.rs10
-rw-r--r--crates/shirabe/src/repository/composer_repository.rs2
5 files changed, 9 insertions, 9 deletions
diff --git a/crates/shirabe/src/dependency_resolver/default_policy.rs b/crates/shirabe/src/dependency_resolver/default_policy.rs
index f753dc48..fee54a90 100644
--- a/crates/shirabe/src/dependency_resolver/default_policy.rs
+++ b/crates/shirabe/src/dependency_resolver/default_policy.rs
@@ -203,7 +203,7 @@ impl PolicyInterface for DefaultPolicy {
CompilingMatcher::r#match(
&SimpleConstraint::new(operator.to_string(), b.get_version(), None).into(),
CmpOp::Eq,
- a.get_version(),
+ &a.get_version(),
)
}
diff --git a/crates/shirabe/src/dependency_resolver/pool.rs b/crates/shirabe/src/dependency_resolver/pool.rs
index c12f819d..7ec6196b 100644
--- a/crates/shirabe/src/dependency_resolver/pool.rs
+++ b/crates/shirabe/src/dependency_resolver/pool.rs
@@ -305,7 +305,7 @@ impl Pool {
if candidate_name == name {
return constraint.is_none()
- || CompilingMatcher::r#match(constraint.unwrap(), CmpOp::Eq, candidate_version);
+ || CompilingMatcher::r#match(constraint.unwrap(), CmpOp::Eq, &candidate_version);
}
let provides = candidate.get_provides();
diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs
index a47952af..0d2b7797 100644
--- a/crates/shirabe/src/dependency_resolver/pool_builder.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs
@@ -286,7 +286,7 @@ impl PoolBuilder {
if CompilingMatcher::r#match(
&constraint,
CmpOp::Eq,
- package_or_alias.get_version(),
+ &package_or_alias.get_version(),
) {
found = true;
}
diff --git a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
index c71feb4d..b06cdd54 100644
--- a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs
@@ -156,7 +156,7 @@ impl PoolOptimizer {
let constraint = irremovable_package_constraints
.get(&package.get_name())
.unwrap();
- if CompilingMatcher::r#match(constraint, CmpOp::Eq, package.get_version().to_string()) {
+ if CompilingMatcher::r#match(constraint, CmpOp::Eq, &package.get_version()) {
self.mark_package_irremovable(package.clone());
}
}
@@ -249,7 +249,7 @@ impl PoolOptimizer {
if CompilingMatcher::r#match(
require_constraint,
CmpOp::Eq,
- package.get_version().to_string(),
+ &package.get_version(),
) {
group_hash_parts.push(format!(
"require:{}",
@@ -262,7 +262,7 @@ impl PoolOptimizer {
if CompilingMatcher::r#match(
link.get_constraint(),
CmpOp::Eq,
- package.get_version().to_string(),
+ &package.get_version(),
) {
// Use the same hash part as the regular require hash because that's what the replacement does
group_hash_parts.push(format!(
@@ -280,7 +280,7 @@ impl PoolOptimizer {
if CompilingMatcher::r#match(
conflict_constraint,
CmpOp::Eq,
- package.get_version().to_string(),
+ &package.get_version(),
) {
group_hash_parts.push(format!(
"conflict:{}",
@@ -601,7 +601,7 @@ impl PoolOptimizer {
.and_then(|m| m.get(&id))
.map(|p| p.get_version());
if let Some(version_str) = version_str
- && !CompilingMatcher::r#match(link_constraint, CmpOp::Eq, version_str)
+ && !CompilingMatcher::r#match(link_constraint, CmpOp::Eq, &version_str)
{
self.mark_package_for_removal(id);
if let Some(map) = package_index.get_mut(require) {
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs
index ad755d50..89226e4c 100644
--- a/crates/shirabe/src/repository/composer_repository.rs
+++ b/crates/shirabe/src/repository/composer_repository.rs
@@ -2133,7 +2133,7 @@ impl ComposerRepository {
}
if let Some(c) = constraint
- && !CompilingMatcher::r#match(c, CmpOp::Eq, version.clone())
+ && !CompilingMatcher::r#match(c, CmpOp::Eq, version)
{
continue;
}