
JXCore LLVM JavaScript Frontend - andreyvit
http://jxcore.com/jxcore-llvm-javascript-frontend-b/
======
cliffbean
This blog post is either spectacularly naive, or ridiculously over-hyped, or
both.

"Consistent performance. (not like the V8 engine pausing the whole application
for GC)"

Static complication doesn't get you out of having to worry about memory
management. What's the alternative here? Reference counting? Leaking
everything? Using a subset of JS that doesn't allocate anything? All of these
things come with considerable costs.

~~~
lohan
So you are okay with having the server process is not responding for ten
seconds? Come on!

~~~
mbreese
Be serious. It's not a question of the process not responding for 10 seconds.

If the same code in V8 is causing a pause to deal with GC, then the LLVM
compiled code must be doing _something_ different to handle the memory. Is it
using a different GC? Is it running on a different thread? Is it just sucking
up memory without freeing it?

These are all things that need to be known before getting too excited about
the speed of LLVM compiled Javascript.

~~~
moisy
I don't know the details but in my opinion a deamon thread like with the Java
could work. Besides, I don't think V8 specifically designed for the server
use.

~~~
cliffbean
If you implement a GC which runs on its own thread, doesn't pause the
application, and achieves good overall performance on any real-world code,
then it would be a terrific thing to mention in your big blog post announcing
the system. We'd love to hear anything you'd like to say about it.

If you don't mention it, and if you also say numerous other things which give
the impression that you may not have given the entire topic much thought, then
even people who would otherwise prefer to be positive and supportive may
struggle to take you seriously, and may react with frustration if you also
make extraordinary claims.

~~~
ithkuil
Perhaps because they take those features for granted because it uses some GC
provided by LLVM ?

(I don't know anything about LLVM support for GC, but I would be surprised if
it comes with a GC that doesn't require to do something special in order to
make it concurrent)

~~~
azakai
LLVM GC support has been fairly weak, however Apple has been working on using
LLVM in JavaScriptCore (FTL project), which requires that, so it should be
getting better. I have no idea if this project is related to that in any way.

------
a-priori
This sounds like the first step in a vision I've had for how the web should
evolve. We now have an LLVM frontend for Javascript, so Javascript code can be
turned into LLVM bytecode.

The next step would be to swap out the existing Javascript runtimes with this
frontend plus a sandboxed backend for the native platform so they can compile
Javascript to LLVM bytecode, then to native code.

Finally, you add an extension to the <script> tag to allow loading arbitrary
LLVM bytecode, something like <script
src="[http://some/url/code.llvm"](http://some/url/code.llvm")
type="text/llvm">.

Once that's in place then you'd be able to execute any language that has an
LLVM front end inside the browser environment. Javascript is no longer the
sole language of the web, and things like Emscripten and asm.js become
obsolete.

~~~
chubot
In other words, you want to use LLVM as a VM. Sorry to be harsh, but you're
only the millionth person to think of this "idea". LLVM is not a well-defined
protocol or specification; it's a library for making a compiler that changes
with every release. Read:

[http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/0437...](http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043719.html)

------
jvilk
Cool hack. Is the source code available somewhere?

> \- Consistent performance.

> (not like the V8 engine pausing the whole application for GC)

But... you're still going to need garbage collection, unless you are only
planning on supporting something like ASM.js. So there will still be
application pauses for GC.

Also, you mention that you have support for JavaScript OO, but I notice the
benchmarks don't exercise programmer-defined JavaScript objects/prototypes. Do
you have numbers on its OO performance, or is that still something you're
working on?

Finally, how do you handle type inference at the LLVM level? I assume you
implemented some form of JIT compilation? I'd be interested to hear more!

------
pjmlp
Nice to see a dynamic language getting an AOT compiler, in this VM age, even
if it is JavaScript. :)

~~~
mpweiher
Objective-C is a dynamic OO language and it has always been AOT compiled.

Also there's Smalltalk/X:
[http://www.exept.de/en/products/smalltalkx](http://www.exept.de/en/products/smalltalkx)

libart for Android also brings AOT to a jitted/VMed language.

~~~
ris
> Objective-C is a dynamic OO language

Objective C is not a dynamic language.

Do not confuse dynamic language with dynamic typing or whatever the standard
wisdom in the Apple cult is.

~~~
mpweiher
Sure is.

Supported:

Dynamic typing.

Fully dynamic message dispatch with doesNotUnderstand: (called
forwardInvocation:), proxies, Higher Order Messaging, etc.

Addition of (a) classes ( objc_registerClassPair() ) and (b) methods (
class_addMethod() ) at runtime.

Changing an object's class at runtime (objc_setClass() slightly hacky, but
done by system services such as KVO, so supported).

Closures/Blocks.

Reflection.

Addition of (associated) instance variables at runtime. Interpreted languages
can be fully interoperable peers.

Not supported:

Eval (but see above re: interpreted peers).

Continuations.

\----

See:
[https://developer.apple.com/library/mac/documentation/Cocoa/...](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/object_setClass)

EDIT: added references.

~~~
pjmlp
How do you dynamically?

\- add fields to a struct

\- create a function

Objective-C is only dynamic typed in the OO runtime, everything else is static
typed.

Dynamic languages are 100% dynamic, unless the CS classification got changed
in the last years.

~~~
mpweiher
That's just silly.

By that definition, Smalltalk is not a dynamic language: you cannot change the
definition of assignment ( := ), message return ( ^ ) or the messenger itself.
You also cannot change the the way the GC works.

~~~
pjmlp
> That's just silly.

No it is not. I can do that in fully dynamic languages like TCL and Python,
for example.

------
jmgrosen
Does this mean I can translate JS to LLVM bitcode with this tool, then
translate that bitcode back to Javscript with Emscripten? Sounds amazing :)

------
azakai
> Javascript has always been considered as a scripting language with low
> performance compared to most low level languages. Thanks to V8 engine, it is
> now becoming a platform where developers can prepare a fully functional
> backend.

This is not accurate, and shows a lack of respect for the JS VM developers at
other browser vendors.

Very close to the time v8 was launched, SquirrelFish Extreme from Apple and
TraceMonkey from Mozilla were also launched, each far faster than previous JS
VMs, beat v8 on various benchmarks while losing on others, etc.

Since then v8 has generally been in the lead, certainly, but not always, and
it would depend on the benchmark and platform.

So it is not fair to say - and this is not the first time I see it, or else I
would not write this comment - that v8 is single-handedly responsible for JS
being fast today.

------
cpeterso
Does Node have an equivalent to the JVM's server and client modes? Node can
probably assume that it will be hosting a long-running server process, skip
the lazy JIT, and just AOT compile all JS code at maximum optimization.

------
TheMakeA
My only concern is Apple's patent for this:
[http://www.google.com/patents/US20100153929](http://www.google.com/patents/US20100153929)

~~~
conanobre
Julia, Rust etc. languages are already doing it.

~~~
pygy_
The patent specifically targets compiling JavaScript to LLVM and running a
monitoring daemon to update the IR when the source changes.

It is ridiculous.

It is a general compilation process, applying it to these specific conditions
is in no way technically original. I hope it isn't from a legal standpoint,
but IANAL...

~~~
obastemur
I'm aware of that patent long before and not following the same structure.
Besides, it also targets other languages by saying 'Javascript or similar'. No
worries here. Thanks for reminding.

------
andreyvit
Found this via [1], would love to hear some opinions from knowledgable people
here.

[1] [http://www.echojs.com/news/8496](http://www.echojs.com/news/8496)

------
ahoge
They should have used one or several of the existing benchmark suites instead
of creating their own micro benchmarks.

~~~
lohan
considering all the other advantages. benchmarks are less important..

~~~
patents-suck
+1

------
moisy
native javascript mobile

~~~
seabrookmx
Agreed.

Write a game once in JS/WebGL. People can play it through the browser on the
desktop, or download an app on Android/iOS/BB10/whatever that is the same code
compiled with JXCore/LLVM for native performance and/or offline play.

Best of both world really. Especially with things out there like CoffeeScript,
LLJS, and Typescript, which make using JS as your dev language manageable even
for us traditional OO-heavy game devs.

------
conanobre
I was expecting this coming

