Why Python, Ruby, and Javascript are slow       Alex Gaynor       Waza 2013
You may know me     from...
rdio.com
• CPython• Django• PyPy
Twitter rants abouthow 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 Optimize        vs.       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,}
Dictionary    vs. 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) { ...
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;   ...
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)   ...
Don’t make us add   heuristics
Heuristics = WAG
Growing dividebetween optimizing and         not
Recap• Line for line these languages are fast!• Take care in data structures (data structure  heuristics are the WORST)• W...
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 ...
Upcoming SlideShare
Loading in …5
×

Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are Slow

1,594 views
1,432 views

Published on

Rdio Software Engineer Alex Gaynor (@alex_gaynor) took to the #Waza 2013 stage (Heroku's Developer Conference) to talk about "Why Python, Ruby and Javascript are Slow". Gaynor argues that developers should aim to make performance beautiful. For more from Gaynor or to contact him, ping him at @Alex_Gaynor.

For more on Waza visit http://waza.heroku.com/2013.

For Waza videos stay tuned at http://blog.heroku.com or visit http://vimeo.com/herokuwaza

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,594
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
18
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Rdio's Alex Gaynor at Heroku's Waza 2013: Why Python, Ruby and Javascript are Slow

  1. 1. Why Python, Ruby, and Javascript are slow Alex Gaynor Waza 2013
  2. 2. You may know me from...
  3. 3. rdio.com
  4. 4. • CPython• Django• PyPy
  5. 5. Twitter rants abouthow computers are bad
  6. 6. Topaztopazruby.com
  7. 7. There is no benchmark but your benchmark
  8. 8. Lame Excuses about why they’re Slow
  9. 9. Dynamic Typing
  10. 10. “You can monkey patch anything”
  11. 11. Harder to Optimize vs. Slow
  12. 12. The Truth
  13. 13. Let’s talk about C
  14. 14. struct Point { double x; double y; double z;};
  15. 15. class Point(object): def __init__(self, x, y, z): self.x = x self.y = y self.z = z
  16. 16. data = { "x" x, "y": y, "z": z,}
  17. 17. Dictionary vs. Object
  18. 18. std::hash_set<std::string, double> point;point["x"] = x;point["y"] = y;point["z"] = z;
  19. 19. And it would be slow
  20. 20. Why don’t people care?
  21. 21. Let’s talk about strings
  22. 22. Given a string matching: “w+-d+”return the integral part of the value
  23. 23. int(s.split("-", 1)[1])
  24. 24. atoi(strchr(s, -) + 1)
  25. 25. Things that take time• Hash table lookups• Allocations• Copying
  26. 26. The C way: BYOB
  27. 27. char *data = malloc(1024);while (true) { read(fd, data, 1024); char *start = data; while (start < data + 1024) { if (isspace(*start)) { break; } start++; } printf("%sn", start);}
  28. 28. while True: data = os.read(fd, 1024) print data.lstrip()
  29. 29. long *squares(long n) { long *sq = malloc(sizeof(long) * n); for (long i = 0; i < n; i++) { sq[i] = i * i; } return sq;}
  30. 30. def squares(n): sq = [] for i in xrange(n): sq.append(i * i) return sq
  31. 31. Missing APIs
  32. 32. from __pypy__ import newlist_hintdef squares(n): sq = newlist_hint(n) for i in xrange(n): sq.append(i * i) return sq
  33. 33. Don’t make us add heuristics
  34. 34. Heuristics = WAG
  35. 35. Growing dividebetween optimizing and not
  36. 36. 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
  37. 37. Don’t abandon beauty,simplicity, our values for performance Make performance beautiful.
  38. 38. Thank you!https://speakerdeck.com/alex @alex_gaynor
  39. 39. 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

×