News for hackers. Stuff that matters.
Re:Why Python is Slow: Looking Under the Hood by stuki on Friday May 09, 2014 @12:47PM (#7721836)
That's pretty central to any OO language. "Everything's an object." Veering away from that, only serves to turn the language into a mess of boxing and unboxing.

That's not to say that OO is necessarily the ideal language paradigm, but it has certainly been the most dominant in the era Python has existed.

Re:Why Python is Slow: Looking Under the Hood by theseoafs on Friday May 09, 2014 @12:59PM (#7721896)
OO languages do not have to do this. Ruby doesn't, for instance (that is, it turns the language into a "mess of boxing and unboxing", but that's invisible to the programmer and makes working with integers so much more efficient). There's simply no reason to allocate integers on the heap -- it's a bad design desicion.
Re:Why Python is Slow: Looking Under the Hood by ForHackernews on Friday May 09, 2014 @04:15PM (#7723033)
Python statically allocates small integers (-5 to 256), so you're not actually creating a new object unless you're creating one outside that range.

http://www.laurentluce.com/posts/python-integer-objects-impl...

Re:Why Python is Slow: Looking Under the Hood by theseoafs on Saturday May 10, 2014 @01:42AM (#7724631)
Dynamic allocation isn't the only cost there -- a cost that's just as big when you're doing number crunching in Python is cache efficiency. If every number is on the heap, and every number in Python is ~20 bytes long, you're going to have caching problems, even if your numbers only ever range from -5 to 256.
Re:Why Python is Slow: Looking Under the Hood by icebraining on Friday May 09, 2014 @01:01PM (#7721921)
How does Ruby know that 'a' is an integer and not any other type? Java and C# can use the variable types to track this, but I don't see how would a dynamic language work without tagging the value.
Re:Why Python is Slow: Looking Under the Hood by gregwebs on Friday May 09, 2014 @01:10PM (#7721961)
My understanding from 5 years ago is that in MRI the leading bit is reserved to indicate whether something is an integer. This of course reduces the size of numbers that fit into a machine word but it seems like a pretty good tradeoff.
Re:Why Python is Slow: Looking Under the Hood by icebraining on Friday May 09, 2014 @01:34PM (#7722130)
Yeah, apparently they're called tagged pointers. The More You Know.

EDIT: And here's Guido explaining why he didn't want that in Python: https://mail.python.org/pipermail/python-dev/2004-July/04614...

Re:Why Python is Slow: Looking Under the Hood by lispm on Friday May 09, 2014 @01:33PM (#7722122)
Most Lisp systems use tags. Several data types will have tags included in the data word, like fixnums, characters. Other data types have an extra word.
Re:Why Python is Slow: Looking Under the Hood by dragonwriter on Friday May 09, 2014 @02:21PM (#7722468)
Ruby -- or more precisely, MRI, though some other interpretations may do something similar -- uses the a fixed set of object_ids (which is what is stored on the stack to locate an object on the heap) for small integers, so if the object_id is within that range, the interpreter uses it directly to calculate the value, and doesn't need to go to the heap to get a value. (MRI does a similar thing with the values nil, true, and false, as well.)
Re:Why Python is Slow: Looking Under the Hood by ForHackernews on Friday May 09, 2014 @04:16PM (#7723040)
Python does the same thing for integers in the range (-5, 256)
Re:Why Python is Slow: Looking Under the Hood by mantrax5 on Friday May 09, 2014 @02:00PM (#7722325)
One easy way to know is to run it a few times and observe the behavior.

This is why JIT runtimes need a "warm up time" to get really fast, say V8 for JavaScript.