Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs profiling: parent in (sliced string)

Tags:

node.js

v8

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?

like image 579
user4176305 Avatar asked Sep 27 '15 22:09

user4176305


People also ask

What is Node JS profiling and how does it work?

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.

How to get the parent directory name in NodeJS?

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.

What is node retrace profiling?

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.


1 Answers

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.)

like image 112
jmrk Avatar answered Nov 09 '22 16:11

jmrk