-
Notifications
You must be signed in to change notification settings - Fork 169
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
refactor(userspace/libsinsp)!: reduce usage of raw pointers #1702
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
Yes this is great, plus some const correction as well, thank you!
LGTM label has been added. Git tree hash: 9b424b4f2652de9ed90c38a38eadac61e8edb8cc
|
/milestone 0.15.0 |
Agreed to separate this and check later.
That's right! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of questions; aside them, PR LGTM! Great job @jasondellaluce !
Also, since some public methods changed interface, i'd add the !
breaking change signal :D
/hold |
bc00baf
to
397a492
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note, I do like we are trying to improve our handling of memory and there's active work on it, I just fear making these changes assuming things like std::unique_ptr
will not have a meaningful performance impact on the code as a whole could turn us from discussing "we have memory errors" into "we have performance issues".
TL;DR we need better performance testing alongside these sorts of changes IMO.
@Molter73 I appreciate raising concerns about performance, definitely onboard with double checking. My thesis is that the adoption of unique_ptrs in this contribution will add no visible cost to our critical paths. I went on and ran some benchmarks of our internal products to see if this change could negatively affect performance. This led to non-visibile performance regression compared to the current mainline. To be extra-sure and transparent, I went on and played around with Compiler Explorer (https://godbolt.org/) to see how this gets compiled in practice. The compiler is a
Some minor differences are visibile, but as you can see it only comes down to few POP and MOV instructions due to the C++ ABI, and everything else is all inlined and completely equivalent to the raw pointer case. Note, the block added on the bottom is there only for exception handling code (makes sure the ptr is deleted in case of exception), which is far more optimized than catching the exception by hand (which we also don't do in most of the codebase). To me, this seems like negligible and acceptable impact. |
397a492
to
f7632c8
Compare
…_new Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
…ass members Signed-off-by: Jason Dellaluce <[email protected]>
…ager Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
Co-authored-by: Federico Di Pierro <[email protected]> Co-authored-by: Mauro Ezequiel Moltrasio <[email protected]> Signed-off-by: Jason Dellaluce <[email protected]>
Signed-off-by: Jason Dellaluce <[email protected]>
f7632c8
to
578d50c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: 80da7b370bea21dec71bf8edf9a899d4c064219f
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, incertum, jasondellaluce, Molter73 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/unhold |
What type of PR is this?
/kind bug
/kind cleanup
/kind design
Any specific area of the project related to this PR?
/area libsinsp
Does this PR require a change in the driver versions?
What this PR does / why we need it:
This has been discussed for a while, and also during one of the past few maintainers call. Basically, the usage of raw pointers is the root of many debugging nightmares and memory-related issues both during the development cycles and at release time.
This PR hunts for all the evident places where a raw pointer could be substituted by a unique_ptr. This has been "optimized" to be as low impact as possible in terms of LOC, so I didn't spend too much time refactoring some legacy code parts like chisels but put extra attention to the core codebase. The most important components involved in the changes are the ones of thread management, filterchecks, filters, formatters, and their factory classes/methods. Overall, most of raw pointers are now gone.
Which issue(s) this PR fixes:
Special notes for your reviewer:
With this, most of our pointers will be safely managed as unique or shared. However, my opinion is that we may have put too many pointed as shared (with ref count) whereas they could be simpler unique_ptr in many cases. Will look into this if/after this one goes through.
Does this PR introduce a user-facing change?: