memory_profiler icon indicating copy to clipboard operation
memory_profiler copied to clipboard

Include breakdown of shared strings in objects allocated

Open HoneyryderChuck opened this issue 4 years ago • 5 comments

I've been using memory_profiler to profile a few optimizations around string allocations and usage of byteslice vs string mutation, and although the number of strings allocated has increased, I suspect that the majority is shared. Unfortunately, there's no way to tell just based on the breakdown charts.

Are the current breakdowns already taking that into account, and if not, would it be an interesting addition?

HoneyryderChuck avatar Feb 01 '21 11:02 HoneyryderChuck

I am open to adding this. Optional opt-in feature, would you like to work on a PR?

SamSaffron avatar Feb 02 '21 01:02 SamSaffron

I could try. Could you point me to where the class/string accounting is performed?

HoneyryderChuck avatar Feb 02 '21 14:02 HoneyryderChuck

@HoneyryderChuck Are you still interested in implementing this?

@SamSaffron Looks like determining if a string is shared can be done only from C. Are you ok in adding a little bit of C code to this gem?

fatkodima avatar Sep 19 '21 19:09 fatkodima

@fatkodima I guess since we are MRI only it seems possibly reasonable. Kind of prefer that there is a helper gem we optionally lean on, cause installing C extensions always brings up edge cases and this is the only piece we need now.

SamSaffron avatar Sep 20 '21 08:09 SamSaffron

@fatkodima here's the (closed) MR: https://github.com/SamSaffron/memory_profiler/pull/99 . I'm not actively trying to solve it anymore, so feel free to.

HoneyryderChuck avatar Sep 20 '21 11:09 HoneyryderChuck