27 ms·
Rhizome – A pedagogical example of a JIT for Ruby, implemented in Ruby
- burlesona 5y agoI was disappointed that this isn't a complete working project, but I have to say the documentation is well-written and informative. This seems like a great learning project.
- chrisseaton 5y agoYeah, sorry, it was designed to be deep but not broad, and of course it's unfinished. It's a bit of a shame. The reading list is the starting point https://github.com/chrisseaton/rhizome#how-to-read-this-repository https://github.com/chrisseaton/rhizome#how-to-read-this-repo..., as is the code in lib of course. You can also run the experiments to generate programs before and after passes. Someone who knows about basic things like bytecode might like to start reading at https://github.com/chrisseaton/rhizome/blob/main/doc/construction.md https://github.com/chrisseaton/rhizome/blob/main/doc/constru... and may find that then starts to be new information.
- stormbrew 5y agoI did something very similar to this (though I never got to JITing to actual machine code, it was on my roadmap, and there were differences in goals[1]) back in the 1.8.x days and the reality is that writing any kind of ruby interpreter is an astoundingly complex task. It is not a simple language and it has a lot of awkward corners. I spent months getting it to the point where it could just properly run rubyspec, and then months more just making it pass a decent number of its tests. I can't imagine this has gotten any easier since then, it would be a hell of a project to make anything like this a complete working project. [1] it's kind of horrifying to me now but it's still up on my github at github.com/stormbrew/channel9 -- the actual goal was a multilanguage vm where you can implement languages in themselves. It was originally written in ruby and eventually the bytecode interpreter core was rewritten in C++. The OP project is much nicer, more directed, and better documented by far than what I wrote there though.
- adenozine 5y agoThunderbong with an excellent link! Chris Seaton is one of the most influential programmers out there for me. I'm so interested in just about everything he's touched. What a guy. Ruby will never die so long as people have ideas like his, though not all can follow through and create such cool things! I'm curious to see where performant ruby goes in the midst of Crystal. I quite like Ruby for exploring, Pry is an unrivalled repl experience, but then Crystal is very fast and quite efficient for big things. I like the idea of types guiding me amongst a big large codebase that I might not be familiar with. We'll just have to keep hacking and see what happens!
- vinceguidry 5y agoIt should be kept in mind that the Ruby ecosystem has quite a bit of depth to it and there are solutions that have been around for quite some time to make it useful in places you wouldn't ordinarily think to. The performance issue has many angles to it. There are lots of different ways to extend Ruby with code in other languages such as C or Rust, there's DragonRuby if you wanna make games, you can run Ruby on the JVM, JRuby and nowadays TruffleRuby, there's even a slimmed-down Ruby suitable for use in embedded contexts, mruby, which is what I replaced all of my Crystal code with. (if you go this route, the best way I've found is to compile your own mruby with whatever you want in it, and put a #!/path/to/mruby shebang at the top of your scripts. Compile if you need even more perf, I found JITted mruby to be more than sufficient.) Crystal isn't a bad language, but the only thing it shares with Ruby is a small subset of syntax. It's sorely lacking in maturity and in libraries and tools. It's unfortunate because Crystal is an idea worth exploring, but its proximity to Ruby means people will always position it against Ruby, and it will always fall short. And with types now in Ruby that's one less reason to pick Crystal over Ruby.
- colesantiago 5y agoWasn't Rust also lacking libraries as well? Example: Last time I checked couldn't find a firebase library for Rust, so gave up on it. Rust seems a bit immature in the library department no? But didn't stop it becoming popular. I bet Crystal will do the same.
- rattray 5y agoRelated project for those interested in alternative/experimental ruby implementations: Artichoke, a ruby for Wasm built with Rust. https://www.artichokeruby.org/ https://www.artichokeruby.org/
- dleslie 5y agoThe code is quite legible; I recommend having a peak.
- mike1o1 5y agoI really appreciate the recommended reading order mentioned in the repository. Many times when looking at a repository as a learning resource it can be pretty daunting to know where to start, so I'm glad to see that in the readme.
- adenozine 5y agoOut of curiosity and for possible discussion, do you have any hard and fast methods for approaching a medium-to-large unfamiliar codebase? In the past, I've tried looking in the past of the repo and trying to make maps of the dependencies between different files over time, to better understand which classes or types are the most widespread. In dynamic languages, I really don't know how I'd start, I'd probably just see how it's invoked and start depth-first from there.
- mike1o1 5y agoIt depends on the type of app. If it's a rails app, I usually start with user.rb or whatever the equivalent is (account.rb or something) as those usually have most of the functionality. From there, I'll either look start looking at routes config and going from there or some of the base controllers to get a sense of things (i.e. ApplicationController or maybe AuthenticatedController). For non-rails web apps (and rails apps), I'll usually find a portion of the UI and just start tracking from the front-end to the back-end. Something like finding some text on the page, and trying to reverse back to where that particular piece of text was defined and what steps it took to get there (which view, helper, controller, etc.) For non web-apps, I don't have any good techniques, unfortunately.
- inopinatus 5y agoTo understand code, start with data. For database-driven applications, that means, read the DB schema first. For everything else, look at their in-memory equivalents. "Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowchart; it'll be obvious." -- Fred Brooks, The Mythical Man Month (1975) "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." -- Linus Torvalds (2006)
- alberth 5y agoI wonder what the folks at Shopify think of this given that they are doing a huge amount of performance work with Ruby/Truffle-ruby. Off topic: If Ruby could achieve the performance that Crystal provides, it'd wager the adoption rate would be huge.
- Malp 5y agoThis is created by Chris Seaton, who works on TruffleRuby at Shopify
- alberth 5y agoLol. I couldn’t remember his name from his HN comments.
- Thaxll 5y agoIt's just impossible, ruby / python will always be fast'ish never really fast because the foundation was not built for it.
- vorticalbox 5y agoWhat you lose in execution time you generally gain in development.
- goldenkey 5y ago> "What you lose in apples you gain in oranges" I didn't know different units could be compared as if they had an equivalence ratio...
- vorticalbox 5y agolanguages like python usually have shorter time to market at the cost of it running slower. So sure they can't be directly compared but that doesn't mean that one cannot effect the other.
- jonnyone 5y agoWonder if the name is a Deleuze/Guattari nod.
- hestefisk 5y agoA thousand plateaus of Ruby compilers? On compilers and schizophrenia?
- chrisseaton 5y agoSorry, it's just a reference to the ruby-red control flow edge flowing through the intermediate representation graph nodes, like a root. The same line in the logo. And it starts with R, so the idea was I could write a new command-line option -rhizome to enable it, but that would actually run a library hizome.rb, with -r being the standard option to load libraries in Ruby, so letting me add a new option to an unmodified Ruby.