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

fix: Profiling memory leak in std::thread #3061

Merged
merged 4 commits into from
May 25, 2023
Merged

Conversation

indragiek
Copy link
Member

📜 Description

This is a follow up to #3055 that fixes the final memory leak reported in #2980

std::thread appears to have some kind of bug (or maybe we were using it incorrectly, but I don't understand how) that causes it to not free the parameters that were passed to the thread entry function. In this PR we switch to using the pthread APIs directly and managing memory manually, which fixes the leak.

💚 How did you test it?

Verified with Instruments that the leak no longer reproduces:

CleanShot 2023-05-24 at 14 18 25@2x

📝 Checklist

You have to check all boxes before merging:

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

std::thread does not free the parameters that are passed to it correctly, fall back to pthread APIs.
@codecov
Copy link

codecov bot commented May 24, 2023

Codecov Report

Merging #3061 (af09a4d) into main (98752f3) will decrease coverage by 0.013%.
The diff coverage is 85.294%.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #3061       +/-   ##
=============================================
- Coverage   88.859%   88.846%   -0.013%     
=============================================
  Files          492       492               
  Lines        52994     53024       +30     
  Branches     18983     18997       +14     
=============================================
+ Hits         47090     47110       +20     
- Misses        4950      4955        +5     
- Partials       954       959        +5     
Impacted Files Coverage Δ
Sources/Sentry/SentrySamplingProfiler.cpp 79.279% <85.294%> (-2.165%) ⬇️

... and 7 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 98752f3...af09a4d. Read the comment docs.

@github-actions
Copy link

github-actions bot commented May 24, 2023

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1249.76 ms 1273.67 ms 23.92 ms
Size 20.76 KiB 434.62 KiB 413.86 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c021422 1199.15 ms 1222.20 ms 23.05 ms
d40512b 1231.12 ms 1244.54 ms 13.42 ms
3f366ee 1244.49 ms 1257.28 ms 12.79 ms
b2f82fa 1237.78 ms 1256.02 ms 18.24 ms
8f397a7 1230.10 ms 1253.88 ms 23.77 ms
98a8c16 1206.40 ms 1232.14 ms 25.74 ms
a6f8b18 1236.96 ms 1240.14 ms 3.18 ms
7bc3c0d 1259.74 ms 1268.45 ms 8.71 ms
7e8d5fd 1208.69 ms 1228.14 ms 19.45 ms
cd3bfeb 1226.61 ms 1226.96 ms 0.35 ms

App size

Revision Plain With Sentry Diff
c021422 20.76 KiB 435.64 KiB 414.88 KiB
d40512b 20.76 KiB 427.77 KiB 407.00 KiB
3f366ee 20.76 KiB 427.84 KiB 407.08 KiB
b2f82fa 20.76 KiB 419.62 KiB 398.86 KiB
8f397a7 20.76 KiB 420.55 KiB 399.79 KiB
98a8c16 20.76 KiB 431.00 KiB 410.24 KiB
a6f8b18 20.76 KiB 431.87 KiB 411.11 KiB
7bc3c0d 20.76 KiB 427.35 KiB 406.59 KiB
7e8d5fd 20.76 KiB 435.50 KiB 414.74 KiB
cd3bfeb 20.76 KiB 425.77 KiB 405.01 KiB

Previous results on branch: indragiek/fix-last-leak

Startup times

Revision Plain With Sentry Diff
c731cab 1238.06 ms 1249.82 ms 11.76 ms

App size

Revision Plain With Sentry Diff
c731cab 20.76 KiB 434.56 KiB 413.80 KiB

Copy link
Contributor

@brustolin brustolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brustolin brustolin merged commit 438e21a into main May 25, 2023
@brustolin brustolin deleted the indragiek/fix-last-leak branch May 25, 2023 07:41
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.

3 participants