I profiled my nodejs application and see some strange strings, it's marked as parent in (sliced string).
I using v8-profiler and node-inspector.
Here is photo of profiler screen (sorry for photo, not screenshot, just my system really overloaded and don't have enough space to make screen): http://i.imgur.com/dkkPbGA.jpg
So, my question, what is this parent in (sliced string) strings?
UPD: After some review looks like i understand, when i made slice on string, it's stored parent string (is it optimization?). In result this parents strings was in memory. After i copied this spliced strings, looks like there this parent strings was cleaned from memory. Am i right?
This type of Node.js profiling is designed to identify and solve Node.js application performance issues down to the line of code. These can show you every element of your code and its success from the end user experience to server monitoring. Plus, they can trace slow database queries, third party APIs, caching layers, background jobs and more.
To get the parent directory name in Node.js, we can use the path.basename and path.dirname methods. to get the folder name of the path of filename with path.dirname. Then we call path.basename to get the parent folder path from the path string returned by path.dirname.
Retrace This type of Node.js profiling is designed to identify and solve Node.js application performance issues down to the line of code. These can show you every element of your code and its success from the end user experience to server monitoring.
Yes, it's an optimization. When you have a long string var longstring = "abc..."
, and you create a substring (a.k.a. "slice") from it var short = longstring.substr(20, 30)
, then the characters are not actually copied around in memory; instead short
is internally just represented as a slice of |longstring| beginning at index 20 with a length of 30
, and longstring
is called short
's "parent". As long as your code keeps a reference to short
, longstring
cannot be freed by the garbage collector.
(For the record, we (V8 developers) know that this optimization can have negative effects on memory consumption, because it can cause long strings to be kept alive when just copying out the part that's still needed would use less memory. The problem is that in the general case, calculating whether that operation makes sense (because only a short chunk is still required) or not (because there are many overlapping slices which, when added up, would account for more memory than their shared parent), is fairly expensive and would make the garbage collector quite a bit slower.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With