sandbox the JavaScirpt program on nodejs

27 views
Skip to first unread message

Mon

unread,
Sep 24, 2015, 11:24:22 AM9/24/15
to nodejs
Is it possible to sandbox a JavaScript program running on top of nodejs so that execution time reported using "process.hrtime()" will not vary much across executions?

Jimb Esser

unread,
Sep 28, 2015, 4:56:55 PM9/28/15
to nodejs
The short answer: No.

Execution time of Javascript code is highly dependent on a number of factors, the largest and most varied is the garbage collector.  It's fairly easy to come up with code which, when ran and timed a large number of times, is orders of magnitude slower some of those times, depending on how much work the garbage collector decides to do during allocations during the run.  And, in Javascript, nearly *everything* creates allocations and garbage.

The most reliable sandboxing would probably be to start an entirely separate process, but even that, I suspect, will be pretty highly variable in terms of performance (and, of course, have huge amounts of overhead if the Javascript you're running is relatively small).
Reply all
Reply to author
Forward
0 new messages