

Optimize your JS with IRHydra 2 for V8 - bolshchikov
http://alpha.irhydra.googlecode.com/git/build/index.html

======
girvo
So, I think this is pretty cool, and I've been looking at things like this but
for PHP (opcodes). I'm really curious about taking the "compile-to-x"
transpilers, and instead of compiling to another high-level language,
targeting the IR of these various VMs instead. Basically, a poor-man's JVM or
CLR, if you will. I wonder how feasible it actually is when you're dealing
with dynamic language VMs, like V8, Zend, etc.? I have a feeling that to get
the speeds V8 has, a lot of implementation details from the source lang would
probably leak into the IR? Anyone have experience trying these sorts of
things?

~~~
TheHydroImpulse
Unfortunately, many of these VMs don't offer a peak under the hood at runtime.
For instance, V8 doesn't have any bytecode or IR you can compile to and run.
JavaScript, and asm.js is the lowest you can go.

If you want to target an IR language, you can try LLVM. Although it's not a
VM, you can definitely implement your own language on-top of it. It'd be
pretty low-level.

Other alternatives are Ruby VMs, such as Rubinius, which actually uses the
LLVM JIT compiler. Rubinius is pretty fast (I have never used it myself) and
it has it's own bytecode format, so you can easily compile your own language
to it.

Fancy ([https://github.com/bakkdoor/fancy](https://github.com/bakkdoor/fancy))
is a great example of this. It compiles to Rubinius bytecode and executes it
within the virtual machine.

~~~
girvo
Yeah, that's the issue I've run into (with PHP at least). Isn't that what this
tool here is supposed to allow you to do, though? Give you a peek under the
hood to V8? That's why I thought it was really interesting :) Of course, I'm
likely reading it wrong, and just because it gives you access to the IR
doesn't mean it lets you interface with said IR directly, which is the issue!

Yeah I've been fiddling with LLVM lately, it's really quite nice. Fancy looks
awesome, cheers for that!

~~~
TheHydroImpulse
Yeah, V8 has a lot of stuff under the hood that you can access for profiling
and what not, but nothing more than that. V8 has two JIT compilers. One that's
quick at starting up, but doesn't produce very good cpu instructions, and an
optimizing JIT-compiler that takes a lot longer to spin up, but the code is
heavily optimized.

You can ask V8 to give you IR dumps and other meta information about the
runtime of your program.

But, unfortunately, that's all you can get. You can't use V8 to implement a
new language, or compile your language down, unless you transpile it to
JavaScript, which isn't as fun.

Yeah, LLVM is pretty awesome of compilers. I know it used to be somewhat bad
for JIT compilers, but I haven't tried or benchmarked it since then. There's
also LibJit that's written in C, and it's only goal is to JIT compile
([http://eli.thegreenplace.net/2013/10/17/getting-started-
with...](http://eli.thegreenplace.net/2013/10/17/getting-started-with-libjit-
part-1/)). A downside to LibJit is the lack of IR. It just emits x86(-64?)
instructions. LLVM offers it's super awesome IR which makes debugging a ton
easier.

Julia is another smaller VM that makes use of LLVM as a JIT compiler. I don't
know if it has a bytecode you can compile to, or not.

Then you can always go towards an interpreted virtual machine, written in C or
even Rust; if the current VMs don't work out.

------
kevingadd
Finally! It used to be incredibly complicated to get any information on how V8
compiles/optimizes JS - and there was basically zero documentation. This
should be super useful for performance tuning, and it makes a nice counterpart
to Mozilla's JIT Inspector and SPS profiler.

~~~
mraleph
I wish I could integrate it "in-process" like Chrome Dev Tools are integrated.
You still have to generate files and feed them in. With all scalability issues
that follow from that.

If you have any suggestions, requests, etc, please file a bug at
irhydra.googlecode.com.

