4 ms·
Is JS a good bytecode? Is compiling to it from Java about as efficient as compiling to a bytecode would be? If so (within an order of magnitude, I'm not fussy
by AndrewDucker 16y ago
Is JS a good bytecode? Is compiling to it from Java about as efficient as compiling to a bytecode would be?
If so (within an order of magnitude, I'm not fussy), then that's awesome - I hadn't realised that things were so efficient.
- stevecooperorg 16y agoI'd also be interested in knowing. AFAIK, things like coffeescript compile to readable, plain JS. Can a relatively efficient system be made which interprets something more 'bytecodey' than readable JS; eg, interpret(['.maxstack 8', 'ldstr "Hello World!"', 'call void window.alert', 'ret']);
- nathanwdavis 16y agoThis is what I've been thinking about too. If javascript like what you wrote above were much faster than nicely structured, readable javascript, then perhaps the idea of "Javascript is the bytecode" may not be such a bad one. <br /> I'm just not sure that it would really provide the performance improvement we would hope for.
- stevecooperorg 16y agoIt would almost certainly be a good deal slower. Or at least, it would be if I wrote it. I know cappucino (http://cappuccino.org/ http://cappuccino.org/) works with a JavaScript language interepreter, so there are mature products out there heading along these lines.
- balakk 16y agoLars Bak (author of V8) talks about this quite a bit in this video with Erik Meijer. http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Erik-Meijer-and-Lars-Bak-Inside-V8-A-Javascript-Virtual-Machine/ http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-E... summary version - there's not a lot to be gained by doing that(at least from a Goog perspective).
- silentbicycle 16y agoIt'll probably be slower than smartly written, natively compiled code, but not necessarily by enough to matter. It really depends on what you're trying to do, so the best way to know is to try it and measure. Compiling to a human-readable format can be pretty straightforward. You can skip some steps entirely (e.g. register selection), and modern tools make it easy to ignore others (lexing & parsing) for quite a while. Don't think about it as "compiling", if you think that's a scary hard thing. Think of it as "reading in a couple kinds of simple structures and converting them to text". Like a templating engine. Figure out what kind of operations you want to support, how to map them into small chunks of Javascript, and go for it. You can pass hand-written JSON, XML, sexps, dicts, etc. to the compiler in a REPL and worry about parsing and other stuff later.