Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Re-use empty resource instance #1251

Merged
merged 2 commits into from
Mar 12, 2024

Conversation

PROFeNoM
Copy link
Contributor

@PROFeNoM PROFeNoM commented Mar 8, 2024

Hello 👋

While searching for low-hanging fruits to improve performance, it appeared from a profile of mine that repeated calls to ResourceInfoFactory::emptyResource would start having a non-negligible impact on the performances.

Screenshot 2024-03-08 at 13 35 47

The instance - being immutable - could be re-used.

Note: I haven't added a test with this PR as imo this is already been tested through the numerous calls to ResourceInfoFactory::emptyResource

Thanks! 😃


FYI, this is the code I used to generate the above profile, if you care, which I ran a few dozen thousand times:

function benchOpenTelemetryAPI($tracer) {
	$span = $tracer->spanBuilder('bench.basic_scenario')->setParent(false)->startSpan();
	$span->setAttribute('foo', 'bar');
	$span->setAttribute('bar', 1);

	$spans = [];
	for ($i = 0; $i < 6; $i++) {
		$childSpan = $tracer->spanBuilder('bench.basic_scenario.child')->startSpan();
		$childSpan->setAttribute('foo', 'bar');
		$childSpan->setAttribute('bar', 1);
		$spans[] = $childSpan;
	}

	for ($i = 5; $i >= 0; $i--) {
		$spans[$i]->end();
	}

	$span->end();
}

@PROFeNoM PROFeNoM requested a review from a team March 8, 2024 12:41
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 84.61%. Comparing base (b20c45d) to head (70d8bc6).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1251      +/-   ##
============================================
+ Coverage     83.09%   84.61%   +1.51%     
+ Complexity     2275     2137     -138     
============================================
  Files           285      284       -1     
  Lines          6460     6056     -404     
============================================
- Hits           5368     5124     -244     
+ Misses         1092      932     -160     
Flag Coverage Δ
7.4 ?
8.0 84.56% <66.66%> (+1.56%) ⬆️
8.1 84.59% <66.66%> (+1.43%) ⬆️
8.2 84.59% <66.66%> (+1.43%) ⬆️
8.3 84.59% <66.66%> (+1.43%) ⬆️
8.4 84.59% <66.66%> (+1.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/SDK/Resource/ResourceInfoFactory.php 97.56% <66.66%> (-2.44%) ⬇️

... and 157 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b20c45d...70d8bc6. Read the comment docs.

@brettmc brettmc merged commit 01c46a2 into open-telemetry:main Mar 12, 2024
11 checks passed
@brettmc
Copy link
Collaborator

brettmc commented Mar 12, 2024

Thanks, @PROFeNoM :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants