Kind of a poorly-named deck. It's really about why programs use features of these languages that end up causing poor performance relative to C, rather than why the individual VMs themselves are slow. It's no surprise that trading the byte-precision of C for the convenience of a garbage collector and heap-allocated data structures results in a performance decrease. Dynamically-typed languages are often easier to progr…
Did you read the deck? The GC isn't the problem; it's layout and management of allocations that's the problem, whether you use a garbage collector or explicit deallocation to clean up the resulting mess. I think the idea that GC is what slows down dynamic languages has to be the most prevalent misconception about language performance.
Why Python, Ruby, and Javascript are Slow
151–160 of 203 posts
Re: Why Python, Ruby, and Javascript are Slow
#152Speaking as a compiler guy, and having a hand in a few successful commercial JITs: The only reason he thinks they aren't slow is because they haven't yet reached the limits of making the JIT faster vs the program faster. Yes, it's true that the languages are not slow in the sense of being able to take care of most situations through better optimization strategies. As a compiler author, one can do things like profile…
Re: Why Python, Ruby, and Javascript are Slow
#153Earlier quoted context omitted.
Did you read the deck? The GC isn't the problem; it's layout and management of allocations that's the problem, whether you use a garbage collector or explicit deallocation to clean up the resulting mess. I think the idea that GC is what slows down dynamic languages has to be the most prevalent misconception about language performance.
Yeah. I dunno about "most prevalent", though. TFA contained two "lame excuses", both of which are things I believed to be causes of slowness in dynamic languages, and now I have to reconsider. dynamic typing prevents type-based optimization monkey patching prevents optimization I think the most common complaint I hear about GC is not that it affects computational throughput, but that it affects _predictability_ of co…
Re: Why Python, Ruby, and Javascript are Slow
#154Earlier quoted context omitted.
Good to hear it's gotten better. Admittedly, I wasn't thinking about browser based JITs when I said that :) I'm actually curious if you have any stats on how much of the time this is being done on actual busy machines where it's going to compete for L1/etc resources vs how often it's able to be offloaded onto an otherwise empty core. IE i expect their to be a significant difference in the use cases for JIT's like PyP…
> Admittedly, I wasn't thinking about browser based JITs when I said that :) Don't HotSpot and JRockit also do background (de)compilation & swapping of generated code?
Re: Why Python, Ruby, and Javascript are Slow
#155Earlier quoted context omitted.
Well, my usual answer there is to change the file extension to .pyx and see what Cython can do with a few type annotations. Usually the results are pretty good, and sometimes they're very good.
Does Cython give you much better results than PyPy? I would have thought that if just a few type annotations make a big difference tracing in PyPy could figure them out.
Re: Why Python, Ruby, and Javascript are Slow
#156I have a few comments about some of the slides, feel free to correct any misunderstandings. Dictionary vs Object: Lookups in both data structures is O(1), the difference being the hashing cost (and an additional memory lookup for heap) vs a single memory lookup on the stack (1 line of assembly). Squares list: > ... so every iteration through the list we have the potential need to size the list and copy all the data.…
Re: Why Python, Ruby, and Javascript are Slow
#157Great presentation, thank you for making me aware of an aspect of Python performance. One slide struck me as odd - the "basically pythonic" squares() function. I understand it's a chosen example to illustrate a point, I just hope people aren't writing loops like that. You inspired me to measure it $ cat squares.py def squares_append(n): sq = [] for i in xrange(n): sq.append(i*i) return sq def squares_comprehension(n)…
from numpy import arange
def squares_numpy(n):
a = arange(n)
return a * a
$ python -m timeit -s "from squares import squares_append" "squares_append(1000)"
10000 loops, best of 3: 130 usec per loop
$ python -m timeit -s "from squares import squares_comprehension" "squares_comprehension(1000)"
10000 loops, best of 3: 95.4 usec per loop
$ python -m timeit -s "from squares import squares_numpy" "squares_numpy(1000)"
100000 loops, best of 3: 5.31 usec per loopRe: Why Python, Ruby, and Javascript are Slow
#158Earlier quoted context omitted.
It's not an unresolved question whether idiomatic Python is slower than idiomatic C/C++ for solving comparable problems. Python is much, much slower than C.
> It's not an unresolved question whether idiomatic Python is slower than idiomatic C/C++ for solving comparable problems. Python is much, much slower than C. The real question is does it matter for a particular project. If it is a desktop GUI. Does it matter if you write it in C++ and the time from button click to status update is 5usec or 1msec? If you are receiving 10 messages per second, parsing out json and send…
Re: Why Python, Ruby, and Javascript are Slow
#159Speaking as a compiler guy, and having a hand in a few successful commercial JITs: The only reason he thinks they aren't slow is because they haven't yet reached the limits of making the JIT faster vs the program faster. Yes, it's true that the languages are not slow in the sense of being able to take care of most situations through better optimization strategies. As a compiler author, one can do things like profile…
Interesting point of view, the problem in compiler construction is well known ("Proebsting's law", though it says it's more like 18 years instead of 10.) The issue with benchmarks is surely well known, also by the PyPy authors; I wonder what the biggest application is that they have benchmarked or that runs on PyPy. Your point on the JIT compiler interrupting program execution is certainly valid, too, but not necessa…
speed.pypy.org has benchmark info on Django, Twisted and some other large, non-trivial codebases.
Re: Why Python, Ruby, and Javascript are Slow
#160One main thought on this topic -- languages like Haskell and lisp also have very poor support for direct memory control, but tend to be viewed (perhaps untruthfully?) as much closer in performance to C than Python/Ruby.
Haskell and languages in the ML family have a lot of opportunities for elaborate static analysis, which often allows the resulting programs to be quite clever about optimizing the resulting programs. As one example, the GHC Haskell compiler uses loop fusion to combine multiple passes over a list into a single pass with no intermediate copies of the list produced. Consequently, Haskell code like map f (map g (map h so…
from itertools import imap
map(f, imap(g, imap(h, someList)))
I think Python 3's map built-in is a generator so you no longer have to use the itertools module.Unfortunately we don't have . or currying in Python so no pointfree python :(.
from itertools import ifilter
# ugly python function with a "Maybe dict" return type
def query(data, date):
"""Return the first dict where date is > x['date'] or None"""
is_greater = lambda x: date > x['date']
return next(
ifilter(
is_greater,
data
),
None
)