75 points · by ksec · 11y ago · 46 comments
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.
(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.
I know Perl is in that category.
Our syntax probably isn't simpler :)
- 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.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.
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.
export PYTHONDONTWRITEBYTECODE=true is the first thing anyone should be doing.
I guess it figures that we copy each others' mistakes.
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.
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
This would just improve the time to initially start a Ruby process.
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.