How do ‘cluster’ and ‘worker_threads’ work in Node.js?

Effectively what you are differing is process based vs thread based. Threads share memory (e.g. SharedArrayBuffer) whereas processes don’t. Essentially they are the same thing categorically. cluster One process is launched on each CPU and can communicate via IPC. Each process has it’s own memory with it’s own Node (v8) instance. Creating tons of them … Read more

Embed a JavaScript engine in an iOS application

There are two projects you might be interested in: JavaScriptCore-iOS iMonkey It is absolutely possible to build and ship a JavaScript engine with your iOS app, see http://www.phoboslab.org/log/2011/04/ios-and-javascript-for-real-this-time. Titanium does that, too: https://github.com/appcelerator/webkit_titanium/tree/master/Source/JavaScriptCore. Also see http://www.phoboslab.org/log/2011/06/javascriptcore-project-files-for-ios. I’ve also made a small app that shows how to use JSC on iOS: https://github.com/jfahrenkrug/AddressBookSpy Enjoy.

Math.random() returns value greater than one?

The edge case occurs when you happen to generate a very small number, expressed with an exponent, like this for example 9.546056389808655e-8. Combined with parseInt, which interprets the argument as a string, hell breaks loose. And as suggested before me, it can be solved using Math.floor. Try it yourself with this piece of code: var … Read more

How to read nodejs internal profiler tick-processor output

Indeed, you are right in your assumption about time actually spent compiling the code: it takes milliseconds (which could be seen with –trace-opt flag). Now talking about that LazyCompile. Here is a quotation from Vyacheslav Egorov’s (former v8 dev) blog: If you are using V8’s tick processors keep in mind that LazyCompile: prefix does not … Read more

What’s the maximum size of a Node.js Buffer

Maximum length of a typed array in V8 is currently set to kSmiMaxValue which depending on the platform is either: 1Gb – 1byte on 32-bit 2Gb – 1byte on 64-bit Relevant constant in the code is v8::internal::JSTypedArray::kMaxLength (source). V8 team is working on increasing this even further on 64-bit platforms, where currently ArrayBuffer objects can … Read more

Android utilize V8 without WebView

You can create a new V8 Context via its API and use that to execute your JavaScript, look into https://android.googlesource.com/platform/external/v8 include directory which contains two C++ header files. Link against the libwebcore.so (compiled from https://android.googlesource.com/platform/external/webkit) library via the NDK, nothing special. v8::Persistent<v8::Context> context = v8::Persistent<v8::Context>::New(v8::Context::New()); context->Enter(); Refer to https://developers.google.com/v8/get_started which will work on Android. Just … Read more

What’s the time complexity of array.splice() in Google Chrome?

Worst case should be O(n) (copying all n-1 elements to new array). A linked list would be O(1) for a single deletion. For those interested I’ve made this lazily-crafted benchmark. (Please don’t run on Windows XP/Vista). As you can see from this though, it looks fairly constant (i.e. O(1)), so who knows what they’re doing … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)