24. Disclaimer No language is fast “per se” C is only as fast as the programmer is smart. ( )
25. Pointers are evil Pointers are Unbounded Weakly typed Aliased and it's bad for Safety Correctness Optimization Pointers are the 21 st century's “goto”
31. Array What is an array? Consecutive elements O(1) random access Fixed size or dynamic Why should arrays be built-in?
32. Array Array is a generic class Array: class [Elem] { size: Nat An array maps from indices to elements Index: cover from Nat { this < size } rule (i: Index) (e | get(i) = e) }
33. Array Remove operation (i: Index) removeAt(i) get(j) = match j { case j < i => get(j) case j < size - 1 => get(j + 1) }
34. Array Add operation (i: Nat, e: Elem) add(i, e) get(j) = match j { case j < i => get(j) case j == i => e case j < size => get(j - 1) }
35. Optimization What if we add(size, elem) ? (e: Elem) add(size, e) get(j) = match j { case j < size => get(j) case j == size => e }
Editor's Notes
Hi, my name is Amos Wenger, I gave a talk last year about the ooc programming language, and this year I'm going to talk about language implementations.
As programmers, there are many qualities we wish our programs had. For instance, we'd like our programs to give the correct result. We'd also like them to be performant, because we don't like to wait. And there are of course many design qualities that we wish every program had! Such as modularity, security, documentation, etc.
But I think two of these goals go hand in hand, and they will be the main focus of my speech: correctness and performance.
Performance has two components. Parallel performance means we can distribute the load so that many workers finish the work earlier than if there were fewer. Sequential performance means how to make a single task perform as fast as possible on a single worker.
Parallelism is very attractive because it basically promises you that if you throw more hardware at it, things will get faster. However, not all tasks are easily parallelized. As Amdahl's law shows, if 95% of your application can be parallelized, you have a maximum 20x speedup, because the remaining 5% still have to be executed sequentially.
So how do we get good enough sequential performance? I've heard often “If you want fast code, do it in C”. But people prefer higher-level languages such as Ruby, because development is a lot easier.
However, when they stumble upon performance problems, they often rewrite part of their application in C, because they know it will be faster. But why is it faster?
Before continuing I'd like to make something very clear: there is no such thing as a fast language. However, some languages allow the programmer to produce very fast programs, and others make it harder.
The very reason C allows programmers to write very fast programs is the reason why I don't believe it's the best solution. Once you have pointers and goto, you can pretty much build the rest of C from there. However not only do pointers make writing good C code hard, it also makes the compiler stupid! Because we can make so little assumptions about the behavior of pointers, optimizations are either very restrained (ie. -O2) or quite risky (ie. -O3)
But the main problem with pointers is that they specify “how” to do stuff. It tells the compiler where to read data, in which order, what computations to make and where to write it back. And it's one of the things programming language research has tried to avoid for a long time. Functional languages are a bit better at describing “what a program should do” instead of “how it should do it”, but it's still not enough for my taste.