Skip to content

Commit

Permalink
perf: Re-use empty resource instance (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM authored Mar 12, 2024
1 parent bb07aca commit 01c46a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/SDK/Resource/ResourceInfoFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 01c46a2

Please sign in to comment.