rdio's alex gaynor at heroku's waza 2013: why python, ruby and javascript are slow
Post on 05-Dec-2014
1.419 Views
Preview:
DESCRIPTION
TRANSCRIPT
Why Python, Ruby, and Javascript are slow
Alex GaynorWaza 2013
You may know me from...
rdio.com
• CPython
• Django
• PyPy
Twitter rants about how computers are bad
Topaztopazruby.com
There is no benchmark but your benchmark
Lame Excuses about why they’re Slow
Dynamic Typing
“You can monkey patch anything”
Harder to Optimizevs.
Slow
The Truth
Let’s talk about C
struct Point { double x; double y; double z;};
class Point(object): def __init__(self, x, y, z): self.x = x self.y = y self.z = z
data = { "x" x, "y": y, "z": z,}
Dictionaryvs.
Object
std::hash_set<std::string, double> point;point["x"] = x;point["y"] = y;point["z"] = z;
And it would be slow
Why don’t people care?
Let’s talk about strings
Given a string matching: “\w+-\d+”
return the integral part of the value
int(s.split("-", 1)[1])
atoi(strchr(s, '-') + 1)
Things that take time
• Hash table lookups
• Allocations
• Copying
The C way:
BYOB
char *data = malloc(1024);while (true) { read(fd, data, 1024); char *start = data; while (start < data + 1024) { if (isspace(*start)) { break; } start++; } printf("%s\n", start);}
while True: data = os.read(fd, 1024) print data.lstrip()
long *squares(long n) { long *sq = malloc(sizeof(long) * n); for (long i = 0; i < n; i++) { sq[i] = i * i; } return sq;}
def squares(n): sq = [] for i in xrange(n): sq.append(i * i) return sq
Missing APIs
from __pypy__ import newlist_hintdef squares(n): sq = newlist_hint(n) for i in xrange(n): sq.append(i * i) return sq
Don’t make us add heuristics
Heuristics = WAG
Growing divide between optimizing and
not
Recap
• Line for line these languages are fast!
• Take care in data structures (data structure heuristics are the WORST)
• We need better no-copy/preallocate APIs
Don’t abandon beauty, simplicity, our values for
performance
Make performance beautiful.
Thank you!https://speakerdeck.com/alex
@alex_gaynor
If there’s time
• Java collections vs. Array and Hash. Need more choices.
• Stop writing C extensions, use something like cffi
• Teach good benchmarking practices
top related