News for hackers. Stuff that matters.
Re:Add bytecode cache to Ruby by 3JPLW on Wednesday June 17, 2015 @02:32PM (#9734236)
What's the relationship between github/ruby and ruby/ruby? It looks like they've diverged quite a far ways away from each other, but that might just be an artifact of which branches GitHub uses when comparing the two.
Re:Add bytecode cache to Ruby by randall on Wednesday June 17, 2015 @03:11PM (#9734508)
Seems like this is Github's (the company's) fork of Ruby. ruby/ruby seems like the official ruby.
Re:Add bytecode cache to Ruby by YorickPeterse on Wednesday June 17, 2015 @03:40PM (#9734716)
Correct, Github uses their own fork to apply changes for their own needs.
Re:Add bytecode cache to Ruby by 3JPLW on Wednesday June 17, 2015 @05:02PM (#9735289)
Do you know how much they try to push their own changes back upstream?
Re:Add bytecode cache to Ruby by sams99 on Wednesday June 17, 2015 @06:32PM (#9735704)
Yes, Aman and Koichi work very closely, the main point of difference at the moment is the method cache patches, Koichi is working on getting something similar implemented in MRI
Re:Add bytecode cache to Ruby by ksec on Wednesday June 17, 2015 @11:01PM (#9736616)
Why something similar but not the same?
Re:Add bytecode cache to Ruby by claudiug on Thursday June 18, 2015 @05:40AM (#9737583)
That is a very good question, and I also I'm curious to find out
Re:Add bytecode cache to Ruby by ksec on Thursday June 18, 2015 @06:52AM (#9737769)
As if the Ruby Community has more then enough resources to improve on TWO Compiler / Interpreter at the same time. Isn't it better to work together then to reinvent the wheel?

Speaking of compiler, the JIT for Ruby development has been very quiet for months.

Re:Add bytecode cache to Ruby by elektronaut on Wednesday June 17, 2015 @06:33PM (#9735710)
Aman Gupta (who wrote this PR) is a Ruby core committer.
Re:Add bytecode cache to Ruby by haberman on Thursday June 18, 2015 @02:48AM (#9737131)
I wrote a benchmark that measures the speed of various VM parsers and the speedup that precompiling brings. I found that precompiling was a huge speed benefit: http://blog.reverberate.org/2014/10/the-speed-of-python-ruby...
Re:Add bytecode cache to Ruby by daurnimator on Wednesday June 17, 2015 @07:53PM (#9735998)
Interesting...

The Lua community has found that bytecode is actually slower to load than it is to generate from source: The extra latency of loading the (larger) bytecode from disk/ssd/flash, exceeds the cpu time to lex/parse.

Re:Add bytecode cache to Ruby by ploxiln on Wednesday June 17, 2015 @08:00PM (#9736015)
On the other hand, Lua syntax is much simpler

(slightly out of date: http://programmingisterrible.com/post/42432568185/how-to-par...)

Re:Add bytecode cache to Ruby by daurnimator on Wednesday June 17, 2015 @08:07PM (#9736047)
> slightly out of date: http://programmingisterrible.com/post/42432568185/how-to-par...

Ouch.... Perhaps a lesson in making your language's grammar too complex: if you do, you'll eventually have to pre-compile.

Re:Add bytecode cache to Ruby by TheLoneWolfling on Wednesday June 17, 2015 @08:18PM (#9736078)
So has Ruby joined the ranks of languages that formally cannot be parsed due to the halting problem?

I know Perl is in that category.

Re:Add bytecode cache to Ruby by vidarh on Wednesday June 17, 2015 @08:51PM (#9736166)
I don't think so. There are a few things that looks distinctly iffy in that respect on the surface, but they are resolved.

e.g. is "foo" a method call or an instance variable? You can't know in isolation, but it doesn't matter at parse time, as if it's part of a larger construct that is only valid as a method call, such as if there's an argument list after "foo", it is parsed as a method call. E.g:

    foo = 1
    foo(42)
will result in:

    test.rb:4:in `<main>': undefined method `foo' for main:Object (NoMethodError)
I think all of the potential cases that might have otherwise made Ruby impossible to formally parse are resolved in similar ways.

Now, there are certainly layering violations. The aforementioned example of "foo" by itself can only be resolved by determining whether or not "foo" is in scope as a local variable at the point it is referenced, for example, but you can opt to defer the decision until after parsing.

Re:Add bytecode cache to Ruby by chrisseaton on Wednesday June 17, 2015 @08:35PM (#9736119)
> So has Ruby joined the ranks of languages that formally cannot be parsed due to the halting problem?

No I don't think anyone has suggested that, have they?

Re:Add bytecode cache to Ruby by ploxiln on Wednesday June 17, 2015 @10:28PM (#9736504)
ruby has a parse.y yacc grammar source file (linked to from the post I linked), and yes it can be parsed separately from being executed.

However, IIRC, no one has been able to re-implement parse.y; jruby and the other ruby re-implementations copied it and made what adaptations were necessary.

Re:Add bytecode cache to Ruby by mst on Wednesday June 17, 2015 @10:47PM (#9736572)
I've seen similar results with perl bytecode.

Our syntax probably isn't simpler :)

Re:Add bytecode cache to Ruby by haberman on Thursday June 18, 2015 @02:43AM (#9737123)
I wrote a benchmark that measures just CPU impacts, and it finds that loading source code takes 25x longer: http://blog.reverberate.org/2014/10/the-speed-of-python-ruby...
Re:Add bytecode cache to Ruby by daurnimator on Thursday June 18, 2015 @07:14AM (#9737838)
A few things:

  - you don't drop the disk cache; so you're loading from RAM (echo 3 > /proc/sys/vm/drop_caches)
  - you don't have very complex code
  - you timing includes starting/loading the intepreter itself.
Re:Add bytecode cache to Ruby by haberman on Thursday June 18, 2015 @12:14PM (#9739575)
> you don't drop the disk cache

Yes that is why I said the benchmark measures "just CPU impacts."

I don't think dropping cache alone would be sufficient to simulate loading of a large project -- I think the benchmark would also need to split the input across many files to recreate the seek time effects.

> you don't have very complex code

Given what I know about parsers, I highly doubt that the performance profile of parsing real code differs from my benchmark very much (ie. >30%). But I'm happy to be proven wrong on this, if anyone wants to try.

> you timing includes starting/loading the intepreter itself

That is why the benchmark makes the files pretty big, so the constant interpreter startup overhead is not a significant factor. Again, I don't think that you're going to be able to significantly change the shape of the results by adjusting for this.

Re:Add bytecode cache to Ruby by Arnor on Wednesday June 17, 2015 @04:24PM (#9734995)
How significant is the performance impact on a mid-large Ruby on Rails application?
Re:Add bytecode cache to Ruby by cheald on Wednesday June 17, 2015 @04:28PM (#9735025)
A bytecode cache is unlikely to affect runtime performance; only load times.
Re:Add bytecode cache to Ruby by fizx on Wednesday June 17, 2015 @07:44PM (#9735965)
It's mostly annoying in development when your mid-large Rails app takes 30s-2m to start-up and/or reload after an edit.
Re:Add bytecode cache to Ruby by vidarh on Wednesday June 17, 2015 @08:54PM (#9736175)
Most of the time that is likely due to bundler/rubygems stuffing your load path full and causing thousands of unnecessary stat calls.

The actual time spent loading/parsing files is in most cases a tiny fraction of the startup time of any large project using rubygems and bundler.

I counted several hundred thousand unnecessary stat calls on the biggest app I have, and ended up with a ugly hack where we trimmed the load path around each set of require's to only paths needed by that specific gem.

Re:Add bytecode cache to Ruby by foz on Thursday June 18, 2015 @12:43AM (#9736880)
Or, as I've seen a few times, you have circular references in your rails asset includes.
Re:Add bytecode cache to Ruby by JulianWasTaken on Wednesday June 17, 2015 @08:10PM (#9736053)
Hah. .pyc files are one of the worst part of Python for developers.

export PYTHONDONTWRITEBYTECODE=true is the first thing anyone should be doing.

I guess it figures that we copy each others' mistakes.

Re:Add bytecode cache to Ruby by michaelmior on Wednesday June 17, 2015 @09:21PM (#9736234)
I've been coding in Python for many years and I can count on one hand the number of times that this has actually caused me any problems.
Re:Add bytecode cache to Ruby by JulianWasTaken on Wednesday June 17, 2015 @11:26PM (#9736694)
What is the total amount of time you spent during those few times, although including the amount of time to learn what happened, and how many thousands of times larger is that amount than the sum total of the time saved by caching bytecode compilation every single time you loaded a pyc for every file you ever wrote?
Re:Add bytecode cache to Ruby by michaelmior on Friday June 19, 2015 @08:41PM (#9748466)
Probably a few minutes spent. I'm not sure how to quantify the overhead of caching compiled bytecode, but I'm guessing it beats that.
Re:Add bytecode cache to Ruby by JulianWasTaken on Sunday June 21, 2015 @07:26PM (#9755432)
It doesn't, which was my point :)

The overhead is tiny, less than milliseconds for sane modules. It's a useless optimization, especially when it can be done at install time only, say, as opposed to for every module import, but even that is somewhat silly.

Re:Add bytecode cache to Ruby by michaelmior on Thursday June 25, 2015 @02:24PM (#9779908)
Without seeing any numbers, it doesn't mean much to me. I'm assuming someone much smarter than me has identified the benefit of bytecode caching and unless it really gets in my way, I see no need to do away with it.
Re:Add bytecode cache to Ruby by gerner on Wednesday June 17, 2015 @09:55PM (#9736362)
can you be more specific?
Re:Add bytecode cache to Ruby by robbles on Wednesday June 17, 2015 @10:36PM (#9736532)
Refactoring a module to a package (e.g. mymodule.py -> mymodule/__init__.py) can cause errors if you don't clear the bytecode, since it can pick up mymodule.pyc and fail to see the new files.

Not sure about the exact conditions when this occurs, but it's definitely happened to me when code is refactored and you pull the newest version in with git.

Re:Add bytecode cache to Ruby by aaronbrethorst on Thursday June 18, 2015 @01:05AM (#9736929)
Does anyone know, offhand (or have a good educated guess), on what the largest monolithic Ruby codebase in existence is? Is it GitHub?
Re:Add bytecode cache to Ruby by ksec on Thursday June 18, 2015 @03:36AM (#9737243)
Cookpad from Japan?

https://speakerdeck.com/a_matsuda/the-recipe-for-the-worlds-...

50 million unique user / month 15,000 Req/Sec

I posted this awhile ago but didn't pulled much attention

https://news.ycombinator.com/item?id=9161220

Re:Add bytecode cache to Ruby by claudiug on Wednesday June 17, 2015 @02:34PM (#9734253)
what is the advantages of adding bytecode cache?
Re:Add bytecode cache to Ruby by nnq on Wednesday June 17, 2015 @02:50PM (#9734388)
speculating: it allows you to still be fine with a slower parser. and this means you can theoretically make the parser smarter (like make it do some inference and catch some bugs at parse-time?) without worrying that much about performance. but then again, I can't imagine what kind of bugs could a parser catch for such a dynamic language like Ruby, so they're probably just doing it to shave some milliseconds from program-start-up time...
Re:Add bytecode cache to Ruby by btown on Wednesday June 17, 2015 @05:16PM (#9735377)
With huge libraries (like SpreeCommerce, for instance), startup time can be seconds or more even on recent hardware, and the vast majority of that code isn't changing between runs. So if every gem was cached, they could see radically faster times to load their test suites across their entire organization. It's well worth it even without a smarter parser.
Re:Add bytecode cache to Ruby by Zash on Wednesday June 17, 2015 @02:38PM (#9734288)
It lets you skip parsing of source code into bytecode if the sources have not changed.
Re:Add bytecode cache to Ruby by cpr on Wednesday June 17, 2015 @02:38PM (#9734292)
Same as for .pyc -- caches the result of parsing and translating the parse tree into bytecodes.
Re:Add bytecode cache to Ruby by FooBarWidget on Wednesday June 17, 2015 @02:44PM (#9734348)
In other words, faster loading times?
Re:Add bytecode cache to Ruby by Mojah on Wednesday June 17, 2015 @06:12PM (#9735636)
This is the equivalent of APC or OpCache in PHP's world?
Re:Add bytecode cache to Ruby by cheald on Wednesday June 17, 2015 @06:29PM (#9735691)
No, Ruby behaves like APC by default; code is loaded and parsed once per process, and then the AST is reused from memory. You can do some stuff to hot reload from disk (ie, Rails' reloader), but you have to intentionally do it.

This would just improve the time to initially start a Ruby process.

Re:Add bytecode cache to Ruby by Freaky on Wednesday June 17, 2015 @09:42PM (#9736305)
PHP needs an opcache because its standard behaviour is to discard all state after each request - including all compiled bytecode - kind of emulating the CGI model.

Ruby web apps on the other hand tend to be run in a loop - the script never exits after a request, it just goes back to the top of the loop to accept the next request to serve.

e.g. https://github.com/rack/rack/blob/master/lib/rack/handler/fa...

        FCGI.each { |request|
          serve request, app
        }
It's nice because it completely decouples your app's startup time from request processing time, so you can do expensive setup stuff up-front without slowing down each request. The disadvantage to that is there's not much pressure to keep startup time low, since it's only happening once.
Re:Add bytecode cache to Ruby by juliangregorian on Wednesday June 17, 2015 @10:01PM (#9736394)
Yeah man, PHP makes scaling easy, it's shared nothing by default, do you even web scale bro? /s