Hacker News new | past | comments | ask | show | jobs | submit login
C for speed: Techniques To Transform Your Turtle Code (atarimagazines.com)
16 points by helwr on Aug 6, 2010 | hide | past | favorite | 9 comments



From 1991. Compiler technology has moved on since then and almost all of these transformations are done automatically for you. Hence the guideline now is to write your code to be readable.

Having said that, it's interesting to see what people worried about in 1991, and worrying that people needed to be told these things.

I was there - I remember it well.


Exactly. I was thinking while reading this: "All of this makes the code harder to read and any modern compiler will catch most of this stuff anyway".

Then I realized this was from 1991.


Ironically, what really matters is limiting heap fragmentation and memory allocation. Not nearly that exciting or tricky.


Optimizing to improve cache behavior can still be fairly tricky / counter-intuitive.


I hope this was added as a peculiar historical artifact from 1991, not a statement of how to best write code today. These tricks don't work with GCC 4.1+ and i86_64.

For example, in the loop section, the good trick now is to make your code accessible by the GCC vectorizer. If you turn on -fdump-tree-vect-details in GCC, you will see - for every loop - the weighting factors applied and what might have blocked the vectorizer's operation. Vectorized computing existed in 1991 - heck, 1969 - but was not commodity like today.


I dunno...even being from 1991, I had actually assumed this was intended as humor. Those are all simple enough (if not entirely trivial) optimizations that it doesn't take a particularly heroic compiler to perform them, even twenty years ago I'd guess.

Frankly, I got a good laugh out of it (that I thought was intended by the author).


I was thinking something similar. I took a compiler course in college in 1990 and we were required to implement a couple of these optimizations (common sub-expressions, constant calculations). So I assume that they were considered easy.


You can still use many of these techniques if you're programming a dynamic language like Python and don't want to add the dependency of a C extension yet. I've unrolled loops, reordered assignments, etc., to good effect.


-1 for sloppy, unreadable code and poor presentation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: