Far from a Javascript VM of ruby?

124 views
Skip to first unread message

Bráulio Bhavamitra

unread,
Dec 13, 2014, 11:07:17 PM12/13/14
to opa...@googlegroups.com
Hello all,

First of all, congratulations for the work done, you have achieved
pretty hard stuff!

When I first looked to the Opal project, I started to think how it
could make an entire ruby application to be run, for example, using v8
and node.js.
I think of this because one of the main claims today is that
javascript is fast and ruby is slow. I know these claims are not
really true in many real world applications.

For this I think the corelib would have to be implemented in such a
way to map existing core api of node.js and maybe useful npm modules.
And probably not only corelib, but some important ruby libraries like
net. C Extensions would not be supported.

So the dream would be to have an entire ruby application run inside
v8. Just like JRuby runs an entire ruby app inside a Java VM.

Have you ever thought of that? Is there already some work on this direction?

Sorry if I'm being to idealistic.

cheers,
bráulio

--
"Lute pela sua ideologia. Seja um com sua ideologia. Viva pela sua
ideologia. Morra por sua ideologia" P.R. Sarkar

EITA - Educação, Informação e Tecnologias para Autogestão
http://cirandas.net/brauliobo
http://eita.org.br

"Paramapurusha é meu pai e Parama Prakriti é minha mãe. O universo é
meu lar e todos nós somos cidadãos deste cosmo. Este universo é a
imaginação da Mente Macrocósmica, e todas as entidades estão sendo
criadas, preservadas e destruídas nas fases de extroversão e
introversão do fluxo imaginativo cósmico. No âmbito pessoal, quando
uma pessoa imagina algo em sua mente, naquele momento, essa pessoa é a
única proprietária daquilo que ela imagina, e ninguém mais. Quando um
ser humano criado mentalmente caminha por um milharal também
imaginado, a pessoa imaginada não é a propriedade desse milharal, pois
ele pertence ao indivíduo que o está imaginando. Este universo foi
criado na imaginação de Brahma, a Entidade Suprema, por isso a
propriedade deste universo é de Brahma, e não dos microcosmos que
também foram criados pela imaginação de Brahma. Nenhuma propriedade
deste mundo, mutável ou imutável, pertence a um indivíduo em
particular; tudo é o patrimônio comum de todos."
Restante do texto em
http://cirandas.net/brauliobo/blog/a-problematica-de-hoje-em-dia

Bráulio Bhavamitra

unread,
Dec 13, 2014, 11:11:48 PM12/13/14
to opalrb
BTW, the list of unsupported features at
http://opalrb.org/docs/unsupported_features/ are really small and of
non critical stuff :)

Bráulio Bhavamitra

unread,
Dec 13, 2014, 11:37:41 PM12/13/14
to opalrb
Correction:

2014-12-14 1:06 GMT-03:00 Bráulio Bhavamitra <bra...@eita.org.br>:
> Hello all,
>
> First of all, congratulations for the work done, you have achieved
> pretty hard stuff!
>
> When I first looked to the Opal project, I started to think how it
> could make an entire ruby application to be run, for example, using v8
> and node.js.
> I think of this because one of the main claims today is that
> javascript is fast and ruby is slow. I know these claims are not
> really true in many real world applications.
>
> For this I think the corelib would have to be implemented in such a
> way to map existing ruby corelib APIs to node.js APIs or/and maybe handy npm modules.
> And not only corelib, but some important ruby libraries like

yar...@gmail.com

unread,
Jul 2, 2015, 11:47:57 AM7/2/15
to opa...@googlegroups.com
A first step would be to target something like asm.js with Opal. Right now Opal seems to output much more "normal" javascript and many libraries currently exec JS snippets internally to make their "toll-free" bridge to javascript libraries and functions.  For example, the opal-jquery gem does this a lot. Basically your Element Ruby class calls $(...) internally and makes using jquery within Ruby almost trivial.  I'm not entirely sure how this would work if you compiled your Ruby to asm.js bytecode.  You'd have to reimplement jquery entirely in Ruby, I'd think. I don't know how calling out to JS would work in that situation. But maybe it's actually not a problem.

You might even go so far as to try to build the MRI RubyVM itself for asm.js and run the real Ruby inside the browser. Of course that's complicated as there's no filesystem and all that in a browser. And any network operations woudl be severely limited. 

I do question the value of running regular Ruby apps/scripts in the browser. I don't see a whole lot of need to just straight port stuff from server-side to the browser. Any Ruby you do run in the browser should be aware of it's context and be written accordingly. For example, what good is a commandline utility script in a browser? What good would it do to run Ruby on Rails in your browser? Sure that stuff would be neat, but most Ruby you write in the browser is probably going to be doing DOM manipulation, XHR requests, and stuff like that. 

In short, I do think it woudl be cool to have a much tighter RUby <-> browser integration, but I'm not convinced it's very practical. I'm already part way through a big project that would clone AngularJS in Ruby (not a 1:1 clone, but extremely similar), and I'm questioning the value of it. I mean, I definitely prefer writing code in Ruby as a general rule, but I'm not seeing a lot of savings over writing straight JS. For now it's just an exercise in learning Angular better.

Bráulio Bhavamitra

unread,
Jul 2, 2015, 12:15:38 PM7/2/15
to opalrb
Hello yarnosh,

The idea is to run Ruby on the server side, not only on the browser.

If node.js and opal supported asm.js, then you could run Rails using
Opal, right?

cheers,
bráulio
> --
> You received this message because you are subscribed to the Google Groups
> "opalrb" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to opalrb+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

yar...@gmail.com

unread,
Jul 2, 2015, 1:11:08 PM7/2/15
to opa...@googlegroups.com
We already can run Ruby on the server side, obviously, so I 'm not sure I understand where node.js part comes in. Yes, node.js makes a full stack JS framework handy by managing all dependencies in one place and web sockets can be cool, but in the end it's just a web framework that the developer has to explicitly program for. It isn't going to help you any in getting Ruby in the browser. Running Opal on node.js would be.. weird and kind of pointless. It's probably possible right now.  

If you want something like Node.js written in Ruby, do it.I'd love to play with it. But running Opal server side in node.js wouldn't make much sense.

If you use the opal-rails gem, you can actually get something that looks a lot like full-stack Ruby similar to how node.js works. Opal allows you to "require" gems in the browser just like you were writing a server side script. It's the Ruby equivalent of npm. 

You will likely never be able to write a Ruby app that transparently executes on both server and client. You will always have to be conscious of the distinction

Bráulio Bhavamitra

unread,
Jul 2, 2015, 1:15:33 PM7/2/15
to opalrb
yarnosh: the point of running Ruby on Rails from node.js/opal is
performance, as v8 is faster than MRI.

yar...@gmail.com

unread,
Jul 2, 2015, 1:35:01 PM7/2/15
to opa...@googlegroups.com
Is it? I know MRI Ruby 2.x caught up with JRuby in performance. Is V8 faster than Java? As far as I understand it, node.js's claims of  superior performance center around concurrency and not really VM performance. If you have CPU intensive operations, you really don't want to be using node.js. Even node.js advocates admit as much. It's not necessarily slow, it just has no advantage if you're not doing a lot of IO.  Not to mention the performance loses in transpiling Ruby to run on V8 JS

MRI Ruby has made great stride in performance in recent years. The only advantage to executing Ruby under a different VM at this point is to integrate with that VM's native libraries. And can't say I've ever had any need to use a JS (npm) library outside of a browser.  And I don't use node.js anywhere currently.

Bráulio Bhavamitra

unread,
Jul 2, 2015, 1:41:54 PM7/2/15
to opalrb
Yearnosh,

JRuby is far more slower than Java is. JRuby Truffle promises to have
Ruby running almost as fast as Java, see http://jruby.org/bench9000/

See V8/MRI comparison:
http://benchmarksgame.alioth.debian.org/u64/compare.php?lang=yarv&lang2=v8
This is almost what most people say: MRI is around 10 times slower than v8.

The main reason is that there is not JIT for MRI. Rujit is still not
ready: https://github.com/imasahiro/rujit

cheers,
bráulio

yar...@gmail.com

unread,
Jul 2, 2015, 2:09:12 PM7/2/15
to opa...@googlegroups.com
Ok, but V8 is slower than Java. So if you were REALLY concerned about performance, wouldn't you just use JRuby Truffle? Would you choose Ruby at all? 

Also, curious how node.js fits in here. It seems completely unrelated.

Bráulio Bhavamitra

unread,
Jul 2, 2015, 7:17:08 PM7/2/15
to opalrb
On Thu, Jul 2, 2015 at 3:09 PM, <yar...@gmail.com> wrote:
> Ok, but V8 is slower than Java. So if you were REALLY concerned about
> performance, wouldn't you just use JRuby Truffle? Would you choose Ruby at
> all?
V8 is almost as fast as Java:
http://benchmarksgame.alioth.debian.org/u64/javascript.html
JRuby Truffle is still far from stable :(

Ruby is quite a nice language, and I pretty mainly work on a lot on a
Rails project, so there is nowhere to scape.
>
> Also, curious how node.js fits in here. It seems completely unrelated.
node.js is the way to implement the layer between the OS and
javascript (e.g. networking, filesystem, etc). So Opal would translate
some of the Ruby's standard lib to node.js' API.

Matthew Isleb

unread,
Jul 6, 2015, 11:34:14 AM7/6/15
to opa...@googlegroups.com
On Jul 2, 2015, at 6:16 PM, Bráulio Bhavamitra <bra...@eita.org.br> wrote:

On Thu, Jul 2, 2015 at 3:09 PM,  <yar...@gmail.com> wrote:
Ok, but V8 is slower than Java. So if you were REALLY concerned about
performance, wouldn't you just use JRuby Truffle? Would you choose Ruby at
all?
V8 is almost as fast as Java:
http://benchmarksgame.alioth.debian.org/u64/javascript.html

“almost” is a bit of a stretch.

JRuby Truffle is still far from stable :(

But it has a tremendous head start over Opal. 


Ruby is quite a nice language, and I pretty mainly work on a lot on a
Rails project, so there is nowhere to scape.

Just run JRuby if performance in Ruby is that critical to you. Though unless you actually use Java and need to interface with it from Ruby, you’ll probably find the tradeoff in gem compatibility to be not worth it. I just don’t get why you’re so set on using V8.


Also, curious how node.js fits in here. It seems completely unrelated.
node.js is the way to implement the layer between the OS and
javascript (e.g. networking, filesystem, etc). So Opal would translate
some of the Ruby's standard lib to node.js' API.

The API node.js provides is for remote apps (running in a browser, normally) through a node.js server. Similar to Rails, except a little more low level.   node.js itself is a collection of CommonJS modules that provide the actual bridge to the OS similar to how Ruby gems extend Ruby core and stdlib.  If Opal did work server side, it might use Node Package Manager, but would have no need to actually run the node.js server and use it’s API. You could ALSO run node.js server but it doesn’t have much to do with making Ruby run server-side on V8. 

And none of this helps you run Ruby the browser, which was the whole point of Opal in the first place. :-)





Reply all
Reply to author
Forward
0 new messages