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

Use array lookup instead of recursion in Context #821

Merged

Conversation

Nevay
Copy link
Contributor

@Nevay Nevay commented Sep 10, 2022

Prevents leaking memory if Context::with() is called iteratively; following example throws an out of memory error with the recursive implementation:

$contextKey = Context::createKey('-');
$context = Context::getCurrent();
for ($i = 0;; $i++) {
    $context = $context->with($contextKey, $i);
}

@Nevay Nevay requested a review from a team as a code owner September 10, 2022 14:10
@codecov
Copy link

codecov bot commented Sep 10, 2022

Codecov Report

Merging #821 (3fc150f) into main (ad3ccd8) will increase coverage by 0.21%.
The diff coverage is 85.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #821      +/-   ##
============================================
+ Coverage     82.82%   83.04%   +0.21%     
+ Complexity     1829     1828       -1     
============================================
  Files           223      222       -1     
  Lines          4723     4725       +2     
============================================
+ Hits           3912     3924      +12     
+ Misses          811      801      -10     
Flag Coverage Δ
7.4 83.06% <85.00%> (+0.22%) ⬆️
8.0 83.08% <85.00%> (+0.21%) ⬆️
8.1 83.08% <85.00%> (+0.21%) ⬆️

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

Impacted Files Coverage Δ
src/API/Trace/AbstractSpan.php 0.00% <0.00%> (ø)
src/Context/Context.php 88.88% <87.50%> (+8.88%) ⬆️
src/API/Baggage/Baggage.php 83.87% <100.00%> (ø)
src/Context/ContextKeys.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

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

src/Context/Context.php Outdated Show resolved Hide resolved
@Nevay Nevay force-pushed the feature/context-non-recursive branch from 489d44d to f319f52 Compare September 13, 2022 18:01
@Nevay Nevay force-pushed the feature/context-non-recursive branch from acabc72 to 3fc150f Compare September 13, 2022 18:38
@bobstrecansky bobstrecansky merged commit 6196d7a into open-telemetry:main Sep 14, 2022
@Nevay Nevay deleted the feature/context-non-recursive branch April 19, 2023 19:11
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.

None yet

3 participants