News for hackers. Stuff that matters.
Re:Lua: the world's most infuriating language? by Demiurge on Friday October 18, 2013 @08:32AM (#6570989)
So why is Lua so much faster than Python? I tried searching about this but primarily people discuss historical context. I'm curious about real language features and whys.
Re:Lua: the world's most infuriating language? by jacques_chester on Friday October 18, 2013 @09:04AM (#6571111)
Partly because it is a simple language and that simplicity allows some optimisations that are hard in a more featuresome language.

There's also the history of development. Lua has always been an embedded language and the Lua team have always had an eye cocked to size and speed.

Finally, size. The Lua runtime is tiny, these days it fits into an L2 cache. If your program doesn't have a lot of data, the effects of cache locality may give you tremendous speedups.

Re:Lua: the world's most infuriating language? by Demiurge on Friday October 18, 2013 @09:38AM (#6571267)
Ok, so the difference seems 'huge' in size. But the language complexity difference doesn't seem proportionate, so I'm curious what the list of these additional python language features is.
Re:Lua: the world's most infuriating language? by masklinn on Friday October 18, 2013 @01:39PM (#6572690)
> so I'm curious what the list of these additional python language features is.

http://docs.python.org/2/reference/datamodel.html#special-me...

Re:Lua: the world's most infuriating language? by RyanZAG on Friday October 18, 2013 @09:05AM (#6571118)
Lua is a far smaller language than Python. Python's complexity makes it extremely difficult to optimize because feature A conflicts with feature B, while Lua you can make much more specific optimization code.

Python's standard methods of creating new objects off common operations also leads to huge amounts of memory being used compared ('functional programming' to use the term of the moment) to Lua's more c-like mutate-in-place standard behavior.

Re:Lua: the world's most infuriating language? by Demiurge on Friday October 18, 2013 @09:08AM (#6571131)
Ok, these comments is exactly what I hear, but leaves me more curious. What exactly is this complexity? On the surface, Python doesn't seem much more complex. It's data-structures also seem more simple to me.
Re:Lua: the world's most infuriating language? by driax on Friday October 18, 2013 @12:25PM (#6572210)
Python is fairly simple in implementation while being as flexible as possible. Look up the concept of descriptors for something fairly difficult to optimize when you consider __getattr__ or __getattribute__. Consider also that you can directly access the __dict__ of both an instance and of the class of that instance. You can monkey-patch the class extensively or directly into it's __dict__. You can even replace the __class__ reference on instance to make it a subtype of different class (which is insanely flexible). Then there's the stuff about metaclasses, which is fairly advanced and collides with all of the other flexibility.

Basically pretty much anything not from __builtin__ or from a C extension is entirely mutable at any time. Consider one of the problems PyPy had with some packages. PyPy didn't support `locals()[42] = value`, which some packages actually depended upon. Nor does PyPy support `instance.__dict__[42] = value` which even more depended upon. Generally Python used a lot of simple concepts such as mutable dictionaries with heterogeneously-typed keys as the implementation of how classes, modules, etc works, which is flexible but very hard to optimize in any way (especially since they are mutable).

Re:Lua: the world's most infuriating language? by Demiurge on Friday October 18, 2013 @12:56PM (#6572414)
I think understand the complex reality that dynamic features arising from 'everything is a nested dictionary', and I used monkey patching once to save my life, but that seems a lot like Luas use of metatables. Is Lua less mutable?
Re:Lua: the world's most infuriating language? by kazagistar on Friday October 18, 2013 @11:30AM (#6571918)
Just use the dir() function on the repl and start digging.
Re:Lua: the world's most infuriating language? by Touche on Friday October 18, 2013 @09:43AM (#6571292)
if __name__ == "__main__"
Re:Lua: the world's most infuriating language? by justincormack on Friday October 18, 2013 @09:03AM (#6571109)
There is some discussion in this thread http://lambda-the-ultimate.org/node/3851 - Python is much more complex than Lua.
Re:Lua: the world's most infuriating language? by snarfy on Friday October 18, 2013 @09:38AM (#6571262)
Lua uses a register based virtual machine. Python is stack based. That is the primary difference.
Re:Lua: the world's most infuriating language? by copx on Friday October 18, 2013 @11:38AM (#6571956)
Here is one major reason: I have read that Guido van Rossum rejects all CPython patches which simply improve performance, because he thinks Python is "fast enough" and is unwilling to make the code more complex / risk the introduction of new bugs just to make Python faster.

In contrast, the Lua developers always cared a lot about efficiency, not just speed, also memory use, and even GC pause times. They simply have different priorities than the CPython developers.

Re:Lua: the world's most infuriating language? by oscargrouch on Friday October 18, 2013 @09:38AM (#6571265)
Mike Pall is behind Luajit.. Get him or Lars Bak to work in a jit compiler and you language will be fast as it can be..

Of course, bad designed language in terms of performance will suffer more to get into the state-of-the-art

Re:Lua: the world's most infuriating language? by masklinn on Friday October 18, 2013 @01:44PM (#6572742)
Mike Pall has noted design decisions of Python which make it much harder to optimize than Lua in the past: http://lua-users.org/lists/lua-l/2004-11/msg00083.html
Re:Lua: the world's most infuriating language? by Demiurge on Friday October 18, 2013 @06:34PM (#6574435)
Thank you, that's the kind of stuff I was looking for.
Re:Lua: the world's most infuriating language? by fdr_cs on Friday October 18, 2013 @10:57AM (#6571706)
But , even the standard lua interpreter is faster then python