Reading a tutorial on ruby, which starts with the introduction to basics of programming (although I know some already) there was an obligatory mention of two different types of programming languages, compiled and interpreted. Compiled programs don't have to be interpreted on the fly which seems to make their performance inherently better.
However advancements in interpreted languages and use of caching is apparently supposed to make the performance of interpreted languages better.
I'm curious though, it can't be that caching and those sort of "tricks" are the only ways in which interpreted languages gain on performance. There must be something more and closer to the nature of these programs. When talking about caching I usually think about something that's not ideal, but must be used or else.. it's going to be slow. Caching always implies delays that we don't want to have, right? It can't be an ideal solution.
So what else is there?
Thanks












Most modern interpreted languages probably use Just-in-time compilation of some form: when a function, module or something is used for the first time, it is compiled to a format that can be executed quickly, when it is used again, the code is available. In the case of python, a modules are saved as a machine-independent bytecode on disk and can be re-used as such on the next run.
Interpreted languages are slower, but not significantly more than bytecode-based languages like Java or .net. On modern machines, this makes little difference in practice - I/O is slower anyway. Realistically, only complex computations are significantly slower.
Thomas Jollans
GnuPG key: 1024D/A6B5 9461 B60F 2C80 2399 6B1E 2698 A70E F421 434B
Login or register to post comments 1 point
Most modern interpreted languages probably use Just-in-time compilation of some form: when a function, module or something is used for the first time, it is compiled to a format that can be executed quickly, when it is used again, the code is available. In the case of python, a modules are saved as a machine-independent bytecode on disk and can be re-used as such on the next run.
That sounds a lot like caching actually. Run and "compile" first time, cache and run from cache next time, if I understand correctly. So if you change something in the cached modules or functions in the meantime it will update this "cache" automatically, right?
OK I guess it's not a big deal on today's machines. Most of the problem with server loads and such come due to mysql more than actual code interpreting (although if code is good I suppose it would issue less mysql queries to do what it needs to do).
Thanks for an informative reply.
Let's not fear freedom.
Login or register to post comments 1 point
Yes, bytecode interpreters usually are faster than direct interpreters, but not quite as fast as true compiled languages (with platform-dependent binaries). The advantage of using an interpreted language on a webserver is that it tends to be less vulnerable to buffer overflows (although it's perfectly possible to create a compiled language in which buffer overflows are impossible).
If you think about it, the binary created by a compiler is (more or less) a cached version of what a JIT-compiling interpreter creates.
A cache simply means you're trading space for time: keep your finished work so you won't have to do it again later. If you have enough space, and are managing it properly, caches are always good.
Can an interpreted language be made very fast? Sure can, just make it very simple
.
CAN I HAS FIXD CAPSLOK KEE PLZ?
Login or register to post comments 1 point
By the way, for python scripts, the moto is : "Speed is not a problem till it is a problem."
I got better performance from Perl than Python, but since both are interpreted language, I prefer the one my brain likes reading and writing, and that is Python.
I can't stand reading Ruby.. it is so... wierd. I just don't like the way Ruby is written. Perl scripts are hard to maintain because a task can be written in incredible amount of ways, and it is hard to get back in when you haven't touched it for years.
For performance, if you run a .py, it turns into a .pyc (for compiled)
If you need C kind of performance, something like Pyrex can be used. It is a language very very similar and 100% compatible with Python (including bindings and objects) and can be automagically translated to C and compiled natively.
Login or register to post comments 1 point
I don't know much about Pyrex, but PyPy is interesting - it is a pure-python implementation of python and includes a machine code compiler, which can compile PyPy itself/
Thomas Jollans
GnuPG key: 1024D/A6B5 9461 B60F 2C80 2399 6B1E 2698 A70E F421 434B
Login or register to post comments 1 point
By the way, for python scripts, the moto is : "Speed is not a problem till it is a problem."
That's interesting. It does make sense.
Anyway, I'm thinking of trying CakePHP before I go into Ruby now.. I was reading some discussions on PHP vs. Ruby and since Drupal runs PHP and I already have some familiarity with it, that may be a better way to go.. Ruby or Python can come next.
Thanks
Let's not fear freedom.
Login or register to post comments 1 point
otherwise I can tell I'm using django (python based framework) and it does an awesome job!
http://blog.watersoul.ca runs with django, I wrote all the 'blog' code in python, and there isn't much!
Login or register to post comments 1 point
So that's what django is all about, a python framework. Sounds great.
Btw, that blog looks awesome.
Let's not fear freedom.
Login or register to post comments 1 point
Thanks
Here is informations about django caching capabilities : http://www.djangoproject.com/documentation/cache/
Login or register to post comments 1 point