
Running Optcarrot, a Ruby NES Emulator, at 150 Fps with the GUI - eregon
https://eregon.me/blog/2016/11/28/optcarrot.html
======
Retr0spectrum
I was intrigued by the method of piping pixel values to MPlayer as a frontend.
I'll definitely be using that in future projects.

It makes use of this video format, which seems almost like a video equivalent
of the PNM image format:
[https://wiki.multimedia.cx/index.php?title=YUV4MPEG2](https://wiki.multimedia.cx/index.php?title=YUV4MPEG2)

I wish there was something similar that used RGB though.

------
kayamon
While it's interesting how you can accelerate Ruby, 150 fps is still _awful_
for a NES emulator on modern platforms.

It kinda shows how bad Ruby's performance is compared to most other languages.

~~~
eregon
On the other hand, I am confident it's written in a much nicer way than most
NES emulators (look at cpu.rb/ppu.rb).

The goal of optcarrot is explicitly not to be the "practical"or "the fastest
NES emulator".

From [https://github.com/mame/optcarrot](https://github.com/mame/optcarrot) >
NOTE: We do not aim to create a practical NES emulator. There have been
already many great emulators available. We recommend you use another emulator
if you just want to play a game.

JRuby+Truffle's performance is not bad compared to other languages:
[https://github.com/smarr/are-we-fast-yet#current-
status](https://github.com/smarr/are-we-fast-yet#current-status)

------
tbrock
How does truffle enhance JRuby to create such a dramatic performance
improvement?

~~~
chrisseaton
Truffle uses Graal, a new JIT compiler for the JVM written in Java. As it's
written in Java, it can be used like a library - directly calling methods to
compile exactly what you want, exactly how you want. Truffle uses this to
compile your Ruby program using partial evaluation, a technique which is
really good at removing the kind of overhead that the JVM usually adds, like
costs for allocation.

This blog post and video explain where a lot of the big speedups come from.

[http://chrisseaton.com/rubytruffle/deoptimizing/](http://chrisseaton.com/rubytruffle/deoptimizing/)

I wrote my PhD about this topic, so there is even a whole thesis if you really
want to get the details on how it works.

[http://chrisseaton.com/phd/](http://chrisseaton.com/phd/)

------
claudiug
can we predict that jruby+truffle, will be usable for ruby gems in the next
few years?

~~~
qwertyuiop924
No, no we can't.

Or at least, I doubt it. You're free to predict whatever you like.

At the very least, I don't think any amb implementations are making their way
to jruby any time soon. Although that's not an issue with any real-world code.

~~~
MrBra
What's amb?

~~~
qwertyuiop924
amb is a nondeterministic operator. It's a fun toy, although not terribly
practical. It's usually implemented in terms of call/cc, a rare (and, as
commonly implemented, expensive) function. CRuby implements it, JRuby doesn't.

It's not revelant to my main point, but I thought I'd have a bit of fun.

