From 856819c9278018fec1efe352cba17d4ed4602cfc Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Mon, 14 Oct 2024 09:52:03 -0700 Subject: [PATCH] [sui-types] avoid deserialization when fetching ID of non-upgraded packages The `original_package_id` function is showing up in some slow traces, so make it less expensive in the (common) case of grabbing the ID of a non-upgraded package --- crates/sui-types/src/move_package.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/sui-types/src/move_package.rs b/crates/sui-types/src/move_package.rs index 787c83adc3da6..8b12643e4ec16 100644 --- a/crates/sui-types/src/move_package.rs +++ b/crates/sui-types/src/move_package.rs @@ -483,6 +483,10 @@ impl MovePackage { /// The ObjectID that this package's modules believe they are from, at runtime (can differ from /// `MovePackage::id()` in the case of package upgrades). pub fn original_package_id(&self) -> ObjectID { + if self.version == OBJECT_START_VERSION { + // for a non-upgraded package, original ID is just the package ID + return self.id; + } let bytes = self.module_map.values().next().expect("Empty module map"); let module = CompiledModule::deserialize_with_defaults(bytes) .expect("A Move package contains a module that cannot be deserialized");