News for hackers. Stuff that matters.
Re:ChakraCore GitHub repository is now open by dmm on Wednesday January 13, 2016 @12:48PM (#10896063)
> Finally, you can also use ChakraCore as the JavaScript engine in Node.

This is interesting. You can use it as an alternative to v8 for node.js

Re:ChakraCore GitHub repository is now open by ksp4186 on Wednesday January 13, 2016 @01:25PM (#10896337)
Microsoft is already working on lighting Node.js with ChakraCore.

See https://github.com/Microsoft/node

Re:ChakraCore GitHub repository is now open by morebetterer on Wednesday January 13, 2016 @02:50PM (#10896973)
Ironically Microsoft had to create a V8 C++ API facade over Chakra in order for Node to compile with it.

https://github.com/Microsoft/node/tree/chnext/deps/chakrashi...

It's interesting that the license of the Chakra shim is the V8 license:

https://github.com/Microsoft/node/blob/chnext/deps/chakrashi...

Re:ChakraCore GitHub repository is now open by ksp4186 on Wednesday January 13, 2016 @03:35PM (#10897282)
That's correct. V8 license is required in v8-*.h files because they are v8 header files that chakra shim uses. The implementation files has Microsoft license.

E.g. All files in https://github.com/Microsoft/node/tree/chnext/deps/chakrashi...

Disclaimer: I work for Chakra team (powering node.js)

Re:ChakraCore GitHub repository is now open by Matthias247 on Wednesday January 13, 2016 @05:20PM (#10898063)
Just curious:

If I would like to write a native extension for a possible Chakra powered node.js, which methods would then be possible?

  - Use V8 C++ API
  - Use Chakra extension API
  - Use NAN
  - All of those?
And in your port are Nodes inbuilt native functions (like the libuv based IO functions) still using V8 APIs which are mapped to Chakra by this shim or are they reimplemented directly on top of Chakra APIs?
Re:ChakraCore GitHub repository is now open by ksp4186 on Wednesday January 13, 2016 @06:36PM (#10898538)
For native modules, below options are ideal: - V8 C++ API : These APIs will continue to work with node.js v8 as well as with Chakra because in shim layer we map them to equivalent Chakra APIs. If you see problem in any APIs not working as expected using Chakra engine, please file an issue on Microsoft/node and we will happy to fix it. - NAN : Node.js Chakra is compatible with latest NAN version so it should continue to work with V8 and Chakra engine.

Regarding, Node inbuilt native functions (in other works deps) that are independent of v8, continue to work in Chakra without reimplementation. Chakra shim comes into picture to map V8 C++ APIs to Chakra equivalent.

Re:ChakraCore GitHub repository is now open by oldmanjay on Wednesday January 13, 2016 @07:00PM (#10898653)
You disclose facts you wish people to consider. You disclaim things when you want them to not be considered.

Sorry, it's my pet peeve. Downvote at will

Re:ChakraCore GitHub repository is now open by morebetterer on Wednesday January 13, 2016 @04:04PM (#10897489)
I see Chakra has caught to up Dec 30, 2015 with the nodejs tree. Which branch are you basing the fork against?
Re:ChakraCore GitHub repository is now open by ksp4186 on Wednesday January 13, 2016 @05:59PM (#10898338)
We are basing it off nodejs/master - https://github.com/nodejs/node
Re:ChakraCore GitHub repository is now open by morebetterer on Wednesday January 13, 2016 @03:51PM (#10897395)
Any progress in talks with Node.JS to make an implementation independent JS engine API for node?
Re:ChakraCore GitHub repository is now open by ksp4186 on Wednesday January 13, 2016 @06:11PM (#10898410)
Its a long goal as of now that everyone want to achieve. You can follow this discussion at https://github.com/nodejs/nan/issues/349
Re:ChakraCore GitHub repository is now open by morebetterer on Wednesday January 13, 2016 @11:06PM (#10899565)
That thread doesn't show a lot of promise towards an engine neutral API.
Re:ChakraCore GitHub repository is now open by ksp4186 on Friday January 15, 2016 @01:49PM (#10911244)
True. I think it will pick up once Node.js + Chakracore (or other Javascript Engines) starts taking momentum.
Re:ChakraCore GitHub repository is now open by ksp4186 on Tuesday January 19, 2016 @04:53PM (#10934376)
Re:ChakraCore GitHub repository is now open by brianwawok on Wednesday January 13, 2016 @12:56PM (#10896129)
What is the advantage of this? What does 1 more JS engine buy us?
Re:ChakraCore GitHub repository is now open by Klathmon on Wednesday January 13, 2016 @01:15PM (#10896260)
Having more than one engine can mean that there is less of a V8 monoculture. Bugs in V8 don't become "standard" and "things that V8 is really good at" doesn't become "things that Javascript is really good at".
Re:ChakraCore GitHub repository is now open by Artemis2 on Wednesday January 13, 2016 @01:23PM (#10896321)
That's what Go does. The reference of the language is [an actual document](https://golang.org/ref/spec), not a reference implementation. There are two compilers (gc and gccgo), and this way, no edge-case of an implementation can make its way into programmers' habits, something that tends to happen a lot with JavaScript.
Re:ChakraCore GitHub repository is now open by jdmichal on Wednesday January 13, 2016 @01:37PM (#10896417)
Microsoft was surprisingly open in this regard with C#. The C# language and the CLI bytecode are both ECMA standards (334 and 335) that could be implemented by anyone. Of course, this is with the realization that the .NET standard library gives Microsoft's C# implementation a lot of staying power.
Re:ChakraCore GitHub repository is now open by mintplant on Wednesday January 13, 2016 @03:33PM (#10897261)
Is this another [1] standard language feature that's being chalked up to Go now? Everything old is new again.

[1] The first being statically-linked binaries.

Re:ChakraCore GitHub repository is now open by bmarkovic on Thursday January 14, 2016 @09:07AM (#10901424)
If I'm not mistaken, the case with statically linked binaries in Go is more of a "It's not a bug, it's a feature" situation than being touted as Go invention. Besides, they are rectifiing that one if I'm not mistaken.
Re:ChakraCore GitHub repository is now open by addicted on Thursday January 14, 2016 @08:12AM (#10901133)
Didn't JavaScript already have a reference spec going back at least a decade? I mean wouldn't a reference spec be a prerequisite for JavaScript becoming an ECMA standard?
Re:ChakraCore GitHub repository is now open by swang on Wednesday January 13, 2016 @02:12PM (#10896682)
What do you mean by the, "edge-case of an implementation... makes its way into programmers' habits" as something that happens a lot in javascript. Maybe I'm not understanding but I read that statement and I don't see how that applies to javascript.
Re:ChakraCore GitHub repository is now open by Klathmon on Wednesday January 13, 2016 @02:19PM (#10896729)
For example, a try/catch in V8 triggers deoptimization for the entire function it's in, while it might not in other engines. So this leads to many developers avoiding try/catch in performance critical code.

This ends up with them avoiding it in general usage, which means that now "avoiding try/catch" is considered a general purpose performance tip in javascript, even though it might only apply to one engine (and the v8 team has expressed interest in trying to stop that deopt)

This might be a bad example, i'm honestly not sure how try/catch performs in other engines, i just know it deopts in V8. But the fact that i don't know if it's a javascript thing or a V8 thing speaks to my point.

Re:ChakraCore GitHub repository is now open by louislaf on Wednesday January 13, 2016 @02:50PM (#10896971)
It is a good example actually. Chakra does fully optimize functions with try/catch.

Caveat: we don't optimize try/finally yet... Disclaimer: I work for MSFT on Chakra.

Re:ChakraCore GitHub repository is now open by bzbarsky on Wednesday January 13, 2016 @04:53PM (#10897851)
try/catch has pretty much no runtime overhead in SpiderMonkey unless an actual exception is thrown.

So yes, this is an excellent example.

Re:ChakraCore GitHub repository is now open by dsp1234 on Wednesday January 13, 2016 @02:30PM (#10896806)
Since node.js is backed by V8, optimization decisions that the V8 team have made end up in developer code that runs in node.js. For example, Bluebird has a list of "optimization killers"[0] that many developers that I know use as a reference when making node.js libraries. However, these optimizations are V8 only, and so "edge-case of an implementation makes its way into programmers' habits". A quick example is "5.1. The key is not a local variable:", which ends up with having to jump through some hoops in a for-in loop, not because it's easy or because the language forces it, but just because V8 is the engine.

[0] - https://github.com/petkaantonov/bluebird/wiki/Optimization-k...

Re:ChakraCore GitHub repository is now open by mraleph on Wednesday January 13, 2016 @03:38PM (#10897305)
> optimization decisions that the V8 team have made

Optimization decisions that V8 team have made are much more universal than it might seem.

It is true there are sometimes strange artificial corner cases - but those are often either bugs or temporary solutions that are going to be replaced with something more generic as soon as they start to hurt too much code.

> which ends up with having to jump through some hoops in a for-in loop

Could you clarify which hoops precisely do you need to jump through?

I am not sure I can imagine a reasonable chunk of code that strives to be both fast, well written and wants to use a context captured or global for-in variable.

    for (IWantThisVariableToEndUpOnGlobalObject in obj) { }
How often do you write code like this?
Re:ChakraCore GitHub repository is now open by dsp1234 on Wednesday January 13, 2016 @04:46PM (#10897801)
Optimization decisions that V8 team have made are much more universal than it might seem.

That's certainly possible, but maybe a competing VM can do better, but finds that everyone has coded specific V8 optimizations. They may be hesitant to push out their implementation. It may be a better optimization, but it causes existing code to run slower on their VM. Thus back to the original statement that implementation quirks find their way into developer code.

for (IWantThisVariableToEndUpOnGlobalObject in obj) { }

The variable has to be in the local scope and can't be in any higher or lower scope, not just a global scope (which your words acknowledge, but your code snippet doesn't). It's easy to end up sending the prop variable through a closure accidentally. Some real world examples[0][1][2]. Note that the solution requires pushing out to another function just to get around the deopt. With the sproutcore example being very clear, as they made the change specifically to satisfy the V8 VM.

[0] - https://github.com/paperjs/paper.js/issues/466

[1] - http://www.html5rocks.com/en/tutorials/performance/mystery/

[2] - https://github.com/sproutcore/sproutcore/blob/master/CHANGEL... (search "Removes V8 "ForIn is not fast case" warning")

Re:ChakraCore GitHub repository is now open by mraleph on Wednesday January 13, 2016 @06:09PM (#10898394)
> The variable has to be in the local scope and can't be in any higher or lower scope, not just a global scope (which your words acknowledge, but your code snippet doesn't)

Sure! I am just trying to say that in my opinion whenever you have a non-local variable used as iteration variable in for-in then you most probably have a bug in your code. I tried to illustrate this with an global variable example because it's a common source of JS bugs - when people leak things into a global namespace by accident.

> Some real world examples[0][1][2]

These links refer to a different bailout reason --- "ForIn is not fast case". The original ForIn support in Crankshaft (written coincidentally by me) only supported this kind of for-in because it was the important case to support and the one where you can get good performance with reasonable investment of time.

Given time and bug reports from people hitting this bailout I would certainly extend ForIn support to cover a more generic case (assuming that supporting more generic case would make some code faster), however just in a couple of months after I landed this initial support I switched to a different project, so I never had chance to revisit this.

This bailout reason is actually not in V8 anymore - as now V8 supports both fast and slow cases in Crankshaft[1]

[1] https://github.com/v8/v8/blob/master/src/crankshaft/hydrogen...

Re:ChakraCore GitHub repository is now open by STRML on Wednesday January 13, 2016 @11:24PM (#10899630)
Hey, maybe you're the right person to ask - why does `arguments` so easily deoptimize in every major engine (well, V8 and SpiderMonkey, at least)?

It seems that engines could easily detect the most common munging of `arguments` (such as [].slice.call(arguments), Array.prototype.slice.call(arguments). Array.from(arguments) and the like) and allow those to be optimized. Doing so would speed up a very large amount of code.

Do you have any insight on why that still has not been done after so many years?

Re:ChakraCore GitHub repository is now open by mraleph on Thursday January 14, 2016 @07:56PM (#10906241)
> Do you have any insight on why that still has not been done after so many years?

I can't really speak for either V8 or SpiderMonkey but I think there are few reasons -

a) nobody got to doing it, even though it was discussed multiple times, e.g. for V8 it just was not the right time to implement it as its trying to completely revamp its optimization pipeline and certain Crankshaft idiosyncrasies make this sort of optimization pretty brittle;

b) I am not entirely sure that it will actually speedup that much code, this kind of code is rarely on an extremely hot code-path (extremely hot code paths must strive to avoid allocation entirely!);

c) there is a reasonable workaround that provides good performance (manual loop);

d) ES6 provides something better than arguments object: rest arguments.

Re:ChakraCore GitHub repository is now open by STRML on Sunday January 17, 2016 @10:21PM (#10922375)
Thanks for that.

I'll give you an example of where it hits hard - Event Emitters. Some of the largest EE libs in the NodeJS ecosystem still munge the arguments object to pass args to listeners. I've sent PRs to some of them, but the deopt caused by the arguments munging seems to slow down the whole function and everything it calls, which can be quite significant (like an entire render loop).

ES6 solves this problem nicely but it will be a long time before we can deploy it natively. Thankfully, Babel handles it correctly and uses a proper for loop. So the need to fix this is less urgent than ever.

Re:ChakraCore GitHub repository is now open by dsp1234 on Thursday January 14, 2016 @11:58AM (#10902590)
As a super late followup:

This really cements the case that the poster above was stating.

no edge-case of an implementation can make its way into programmers' habits, something that tends to happen a lot with JavaScript.

There is code in the wild right now that fixes (perceived or actual) problems in the code's interaction with the V8 engine. And worse, that developer code no longer solves any problem.

whenever you have a non-local variable used as iteration variable in for-in then you most probably have a bug in your code.

Agreed, I'm pretty sure every linter would pick that up anyways. That's not really the cases that I saw though, mostly it was stuff where the key is needed in a function/closure (just threw this together straight in the text area here):

  function Intercept(obj1, obj2){
     for(var key in obj1){
       obj2[key] = function(){
           console.log('called: ', key);
           obj1[key]();
       }
     }
  }
Note that in the document I referenced, this was under section 5.1. I'm not sure if you would consider them being the same or not, but that's where it's listed in the document, so that's I how I cited it.
Re:ChakraCore GitHub repository is now open by mraleph on Thursday January 14, 2016 @07:50PM (#10906204)
> no edge-case of an implementation can make its way into programmers' habits, something that tends to happen a lot with JavaScript.

Edge cases should not, and they almost never do... However performance optimizations is a very special area - you have to know how things are implemented and utilize this knowledge.

> mostly it was stuff where the key is needed in a function/closure (just threw this together straight in the text area here):

This code is also buggy - all closures will point to the same `key`.

Re:ChakraCore GitHub repository is now open by PeCaN on Wednesday January 13, 2016 @01:11PM (#10896234)
Well, Chakra is a bit ahead of V8 in ES6 implementation right now.

https://kangax.github.io/compat-table/es6/

Re:ChakraCore GitHub repository is now open by magicalist on Wednesday January 13, 2016 @01:44PM (#10896470)
Actually, try it with current Chrome Canary (V8 version 4.9.355). They just hit 92% with no flags.
Re:ChakraCore GitHub repository is now open by zbraniecki on Wednesday January 13, 2016 @07:45PM (#10898859)
That's awesome! With SpiderMonkey hitting 90%, WebKit at 81%, V8 92% and Chakra at 80%, ES6 as production target becomes realistic!

I'm wondering when Android/iOS default browsers will get updates because that's going to be the one remaining blocker. (and IE11 of course... but that's just waiting for userbase to move away from it :/)

Re:ChakraCore GitHub repository is now open by realityking on Thursday January 14, 2016 @11:15AM (#10902246)
Apparently iOS 9.3 will include a bigger-than-usual Safari update. While there are no new big ES6 features mentioned in the announcement, I'm hoping for some smaller improvements.
Re:ChakraCore GitHub repository is now open by sylvinus on Wednesday January 13, 2016 @12:59PM (#10896147)
Competition! Now both teams have one more incentive to innovate and we get better software in the end.
Re:ChakraCore GitHub repository is now open by saurik on Wednesday January 13, 2016 @01:40PM (#10896445)
As far as I understand, v8 doesn't care about node, and would never think twice about doing something that breaks the entire node ecosystem if it makes Chrome slightly faster. FWIW, they aren't even "wrong": it makes sense to me. What is interesting here is not "competition" but "someone who builds a JavaScript engine wants you as a user".
Re:ChakraCore GitHub repository is now open by sylvinus on Wednesday January 13, 2016 @02:14PM (#10896701)
That is probably true, but maybe this position stems more from the fact that they were never challenged than we think. I'm hoping some pride will be thrown into the mix and will make them care just a bit more than they currently do.
Re:ChakraCore GitHub repository is now open by murukesh_s on Wednesday January 13, 2016 @01:03PM (#10896183)
perhaps more competition? v8, though much faster than other engines when released, is still roughly twice as slow as go. while jvm (also uses JIT) is roughly twice as fast as go and reaching near native/c/c++ performance. I know it's not a fair comparison between javascript(dynamic) and java (typed), but I am sure there is still room for improvement.
Re:ChakraCore GitHub repository is now open by LamaOfRuin on Wednesday January 13, 2016 @01:07PM (#10896211)
Independent implementations of standards.
Re:ChakraCore GitHub repository is now open by bsimpson on Wednesday January 13, 2016 @03:56PM (#10897437)
Before Node was popular, I tried a command-line JS engine called Narwhal. It was built by 280 North, and as I recall, it had pluggable engines. I remember being surprised at how much faster JSCore (Safari's) felt than the others.

Not being permanently coupled to a particular platform is probably a good thing for Node, and provides a healthy incentive for V8 to stay on-top of its game.

Re:ChakraCore GitHub repository is now open by pookeh on Wednesday January 13, 2016 @12:58PM (#10896143)
Better ES6 support.
Re:ChakraCore GitHub repository is now open by whatever_dude on Wednesday January 13, 2016 @01:09PM (#10896224)
Re:ChakraCore GitHub repository is now open by dsp1234 on Wednesday January 13, 2016 @12:58PM (#10896145)
Competition
Re:ChakraCore GitHub repository is now open by tootie on Wednesday January 13, 2016 @01:45PM (#10896480)
Oracle was working on getting node to run on the JVM, but it wasn't really open and it looks like it was abandoned:

https://avatar-js.java.net/

Re:ChakraCore GitHub repository is now open by chrisseaton on Wednesday January 13, 2016 @03:14PM (#10897129)
Re:ChakraCore GitHub repository is now open by hjek on Wednesday January 13, 2016 @04:19PM (#10897583)
RingoJS is pretty nice for JS server apps on the JVM though: http://ringojs.org/