Why is my javascript source code kept in the heap during runtime?

36 views
Skip to first unread message

Doron Roberts-Kedes

unread,
Sep 5, 2020, 5:10:29 PM9/5/20
to v8-users
Hello V8 community,

In a heap snapshot of my production node server I noticed that every "compiled code" entry has a "source" field containing a string of what appears to be the original javascript source code. I have a few questions about this:
  1. Are these strings required at runtime for JIT compilation? This source I've found says that: "bytecode is used as the source of truth, removing the need to re-parse Javascript during compilation. This means that with bytecode, TurboFan’s deoptimization no longer requires the original source code." I'm taking this to mean these strings are not needed at runtime for JIT compilation. Am I interpreting this correctly?
  2. If these strings are not needed for JIT compilation at runtime, are they maintained at runtime in order to make the program more easily debug-able?
  3. If they are included for debugging purposes and not strictly necessary, is there any way to disable this? 

Thanks!

Best,
Doron

Ben Noordhuis

unread,
Sep 6, 2020, 5:25:55 AM9/6/20
to v8-users
I'm 98% sure it's primarily because of Function.prototype.toString()
and that there's no way to disable that, secondarily for debugging.

There's an internal mechanism to mark JS functions as native that lets
V8 throw away the source code but it's not available to regular JS. I
don't think it's even exposed through the public C++ API.
Reply all
Reply to author
Forward
0 new messages