From 01c46a2350e25829ebac4bf152a7d0829d620a61 Mon Sep 17 00:00:00 2001 From: Alexandre Choura <42672104+PROFeNoM@users.noreply.github.com> Date: Tue, 12 Mar 2024 04:49:02 +0100 Subject: [PATCH] perf: Re-use empty resource instance (#1251) --- src/SDK/Resource/ResourceInfoFactory.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/SDK/Resource/ResourceInfoFactory.php b/src/SDK/Resource/ResourceInfoFactory.php index 7fc80bcd9..507d967de 100644 --- a/src/SDK/Resource/ResourceInfoFactory.php +++ b/src/SDK/Resource/ResourceInfoFactory.php @@ -17,6 +17,8 @@ class ResourceInfoFactory { use LogsMessagesTrait; + private static ?ResourceInfo $emptyResource = null; + public static function defaultResource(): ResourceInfo { $detectors = Configuration::getList(Env::OTEL_PHP_DETECTORS); @@ -90,6 +92,10 @@ public static function defaultResource(): ResourceInfo public static function emptyResource(): ResourceInfo { - return ResourceInfo::create(Attributes::create([])); + if (null === self::$emptyResource) { + self::$emptyResource = ResourceInfo::create(Attributes::create([])); + } + + return self::$emptyResource; } }