Questions tagged [v8]

V8 is Google's open source JavaScript engine.

About V8

V8 is Google's Javascript engine that is used in Google Chrome (). It is written in C++ (), and is open source, which can be checked out by following the instructions on the v8 wiki.

V8 can run standalone, or can be embedded into C++ applications.

Documentation on V8 can be found on its wiki pages.

There are a number of flags that can be passed to V8 to expose its internals. For instance, --trace-deopt gets V8 to log code deoptimizations, and --expose-gc allows scripts to manually invoke a garbage collection. The full list of flags can be found by reading the source.

Links:

Tag Usage

Use this tag to ask questions about:

  • Usage of the V8 API
  • Performance and profiling with V8
  • How V8 works
2955 questions
32
votes
3 answers

Why is Function.prototype.bind slow?

When comparing this benchmark with chrome 16 vs opera 11.6 we find that in chrome native bind is almost 5 times slower then an emulated version of bind in opera native bind is almost 4 times faster then an emulated version of bind Where an…
Raynos
  • 166,823
  • 56
  • 351
  • 396
32
votes
3 answers

stack and heap in V8 ( JavaScript)

does V8 uses stack and heap like the JVM? if so does it put primitives on the stack and objects on the heap?
user815070
32
votes
3 answers

garbage collection with node.js

I was curious about how the node.js pattern of nested functions works with the garbage collector of v8. here's a simple example readfile("blah", function(str) { var val = getvaluefromstr(str); function restofprogram(val2) { ... } (val) }) if…
Vishnu
  • 521
  • 1
  • 6
  • 12
32
votes
2 answers

nodejs v8.getHeapStatistics method

In nodejs v8 module, there's a function called getHeapStatistics which return an object that contains information about memory usage: { total_heap_size: 221540352, total_heap_size_executable: 5242880, total_physical_size: 221540352, …
王如锵
  • 941
  • 7
  • 17
32
votes
2 answers

Under the hood, are Javascript objects hash tables?

I was wondering about how Objects are implemented under the hood in Javascript engines (V8, Spidermonkey, etc). Are they really just Hash Tables? If so, how do they handle collisions?
Newtang
  • 6,414
  • 10
  • 49
  • 70
31
votes
3 answers

Converting from v8::Arguments to C++ Types

I'm playing with creating Node.js modules in C++, but I'm stumped on the v8::Arguments class. Lets say I have a Javascript class for sending emails, which has a method with this signature: Mailer::sendEmail(Array recipients, String sender, String…
mellowsoon
  • 22,273
  • 19
  • 57
  • 75
31
votes
1 answer

V8 and ECMAScript differences

Where can I find a list of all the differences between V8 and ECMAScript? For example V8 supports const, which isn't part of the ECMAScript standard.
knex
  • 1,733
  • 3
  • 15
  • 11
31
votes
5 answers

Why is new slow?

The benchmark: JsPerf The invariants: var f = function() { }; var g = function() { return this; } The tests: Below in order of expected speed new f; g.call(Object.create(Object.prototype)); new (function() { }) (function() { return this;…
Raynos
  • 166,823
  • 56
  • 351
  • 396
31
votes
1 answer

Is node.js a viable alternative to traditional scripting languages like Perl and Python?

Recently I've fallen out of love with Perl as a cross-platform general purpose scripting language, and niether Python nor Ruby ever really appealed to me either. But I've been getting more and more comfortable with JavaScript in the browser, it's…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
30
votes
2 answers

Tail Call Optimization implementation in Javascript Engines

As of February 2019 in Chrome Version 71.0.3578.98 on Mac , the following program throws Uncaught RangeError: Maximum call stack size exceeded error. at a count of 16516. const a = x => { console.log(x) a(x + 1) } a(1) I've done quite a bit…
Ben
  • 5,085
  • 9
  • 39
  • 58
30
votes
3 answers

How do you expose a C++ class in the V8 Javascript Engine so it can be created using new?

The official examples of exposing a Point class seem to assume that there will be a fixed number of instances of it in your program. It is not clear how new instances are allocated in the C++ code, when new is called in Javascript. How would you…
Steve Hanov
  • 11,316
  • 16
  • 62
  • 69
29
votes
3 answers

nodejs out of memory

I came across a curious issue today. This may be an easy answer for others, but it has me stumped. Why does the code below cause a memory error? var cur = 167772160; var bcast = 184549375; var addresses = []; while (cur <= bcast){ cur += 1; …
Sneaky Wombat
  • 1,838
  • 2
  • 21
  • 29
29
votes
7 answers

Are there any precompiled binaries for V8?

V8 is an important part of node.js, which uses the Google V8 Javascript engine. Building V8 on my windows box [Windows 7/64-bit] is going to take me hours of grabbing and installing tools I'm not familiar with (though I do use Cygwin). It'd save me…
F. Randall Farmer
  • 627
  • 1
  • 6
  • 13
29
votes
2 answers

Working with arrays in V8 (performance issue)

I tried next code (it shows similar results in Google Chrome and nodejs): var t = new Array(200000); console.time('wtf'); for (var i = 0; i < 200000; ++i) {t.push(Math.random());} console.timeEnd('wtf'); wtf: 27839.499ms undefined I also runned…
Yurij
  • 1,530
  • 16
  • 30
29
votes
1 answer

Why V8 in Node.JS is faster than in my native C++ addon?

Why Google's V8 JavaScript engine in my C++ addon works significantly slower than in Node.JS? I've tried to write some stupidly simple code for generating prime numbers in the JavaScript and ran it in V8 via my C++ addon and directly in Node.JS. I…
Void-995
  • 1,735
  • 2
  • 13
  • 8