v8

v8 Engine - Why is calling native code from JS so expensive?

梦想的初衷 提交于 2019-12-12 09:04:30
问题 Based on multiple answers to other questions, calling native C++ from Javascript is expensive. I checked myself with the node module "benchmark" and came to the same conclusion. A simple JS function can get ~90 000 000 calls directly, when calling a C++ function I can get a maximum of about 25 000 000 calls. That in itself is not that bad. But when adding the creation of an object the JS still is about 70 000 000 calls/sec, but the native version suffers dramatically and goes down to about 2

How do i access v8 parse tree how can it be done?

微笑、不失礼 提交于 2019-12-12 08:33:04
问题 I like to take the v8 engine and to transform its code to other programming language based on this for example if i understand it right first step i need to get the parse tree my question is : can i get it already from v8 or do i need to generate it from the js code . what is the easer way ? 回答1: It looks hard to get the AST (Annotated Syntax Tree, the Parse tree) from V8 itself but there are plenty of other parsers for JavaScript that will do what you're looking for. I'd recommend having a

Maximum number of entries in Node.js Map?

北城以北 提交于 2019-12-12 07:26:04
问题 I was making a large Map in Node.js v11.9.0 and it kept failing with "FATAL ERROR: invalid table size Allocation failed - JavaScript heap out of memory". My map's keys and values shouldn't be getting anywhere near the size of Node's heap size, so I tried just making a map and inserting numeric keys and values into it: var N = Math.pow(2, 26); var map = new Map(); for (var i = 0; i < N; i++) { map.set(i, i + 1); if (i % 1e5 === 0) { console.log(i / 1e6); } } This program crashes Node after

Does nextTick means next phase in Node.js (Event Loop)?

╄→гoц情女王★ 提交于 2019-12-12 05:44:10
问题 What does process.nextTick exactly mean ? Does nextTick mean, after callback queue pop for one element in the current phase ? Or before moving to the next phase after executing all callbacks in the current phase's queue ? 回答1: This is described in the documentation. nextTick queues callbacks to be invoked at the end of the current tick. The entire queue is emptied before moving to the next tick. Contrast with setImmediate, which queues callbacks to be invoked during the next tick. (Yes, the

Partial garbage collection of objects possible? (server-side JS)

末鹿安然 提交于 2019-12-12 02:49:58
问题 Assume a server-side JavaScript environment, that provides a function like so: var parseIsoDuration = /... complex regex .../ function dateDiff(date, isoDurationStr){ var duration = parseIsoDuration.exec(isoDurationStr); return timeLibrary.add(date, duration); } That function will be called from outside, on hundreds of dates, but mostly the same ISO duration. Because RexExp parsing is not a cheap operation, an application-level cache could be implemented: var parseIsoDuration = /... complex

Many erros when i try compile c++ in V8 - JavaScript

泄露秘密 提交于 2019-12-11 23:18:06
问题 I try using: git clone git://github.com/v8/v8.git v8 && cd v8 or svn checkout http://v8.googlecode.com/svn/trunk/ v8 Use libs: make dependencies sudo apt-get install apt-file; sudo apt-get install libc6-dev-i368 lib32stdc++6; When i try compile a simple file as: int main(int argc, char* argv[]) { // Create a string containing the JavaScript source code. String source = String::New("'Hello' + ', World'"); // Compile the source code. Script script = Script::Compile(source); // Run the script to

How do I build v8 on Windows?

﹥>﹥吖頭↗ 提交于 2019-12-11 19:37:42
问题 Could someone tell me how to install and build v8 on windows? I am using Windows 7 with VS 2008. 回答1: The following worked for me in VS2013: From http://gneu.org/2014/02/integrating-v8/ git clone git://github.com/v8/v8.git v8 cd v8 svn co http://gyp.googlecode.com/svn/trunk build/gyp svn co http://src.chromium.org/svn/trunk/tools/third_party/python_26@89111 third_party/python_26 svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin@231940 third_party/cygwin svn co https://src

How v8 stores arrays in a fragmented memory

試著忘記壹切 提交于 2019-12-11 17:46:53
问题 I am wondering how v8 solves the problem of storing arrays in a fragmented memory. Basically, what is the array data structure in v8. I assume under the hood v8 has to deal with the problem of memory fragmentation. I have read that C allocated arrays with contiguous memory which makes sense since you are allocating it directly anyways. But with JavaScript it is dynamic so it seems you can't allocate them contiguously always. Given memory blocks of 8 bytes free ○ and allocated ●, imagine this

How to implement a robust hash table like v8

时光怂恿深爱的人放手 提交于 2019-12-11 16:33:34
问题 Looking to learn how to implement a hash table in a decent way in JavaScript. I would like for it to be able to: Efficiently resolve collisions , Be space efficient , and Be unbounded in size (at least in principle, like v8 objects are, up to the size of the system memory). From my research and help from SO, there are many ways to resolve collisions in hash tables. The way v8 does it is Quadratic probing: hash-table.h The wikipedia algorithm implementing quadratic probing in JavaScript looks

If v8 rehashes when an object grows

混江龙づ霸主 提交于 2019-12-11 15:52:30
问题 Say you have a change in an object that triggers a change in the size of the underlying array or data structure storing the hash values. var x = { a: 1, b: 2, c: 3 } // trigger a resize theoretically x.d = 4 x.e = 5 x.f = 6 Say the underlying array for the hash looked like this in v8 [ 1, 3, 2, null, null ] It created some extra space initially. But it wasn't quite enough so then it had to grow. There are two options. It grows leaving the original values in there current place. It grows and