by joshhart · 15y ago · 0 comments
1. If garbage collection was that damaging to the cache, Haskell wouldn't be nearly as fast as C. 2. Copy-on-write data structures are nice because the immutability allows for concurrent access without locking.
Granted, this was from 2002 and Linus may no longer feel so strongly about the topic.
Dense matrix kernels should get better than 90% of FPU peak. Unlike sparse kernels, dense kernels are no longer bandwidth limited, but cache reuse in both L1 and L2, as well as friendly TLB behavior is important to good performance.
It would be interesting to see any Haskell implementations that are competitive. I suspect that the very first thing you will do when trying to get performance is to ditch the functional paradigm and start writing code in an assembly-level monad.
It's an interesting question though. I'm a Haskell beginner, but I'm pretty experienced with Scala. Let me try to see how using sliding compares with a tight Java loop on statically allocated data for convolutions/filters.
Or teach the compiler about the algebra of arrays and matrices, so it can do the things to the code, that we'd write by hand.
E.g.
* http://www.cse.unsw.edu.au/~benl/papers/stencil/stencil-icfp...
* http://www.cse.unsw.edu.au/~benl/papers/repa/repa-icfp2010.p...
* http://www.cse.unsw.edu.au/~dons/papers/stream-fusion.pdf
* http://www.cse.unsw.edu.au/~chak/papers/acc-cuda.pdf
In all these cases arrays codes are written in a function style, accompanied with special purpose optimizations and/or code generators (in the case of GPU code), layered over an imperative arrays primitive layer, using a memory effects monad.
The single threaded Handwritten C version is about 45% faster than our best Haskell result, which is achieved with 3 threads.
Meanwhile, there is no performance model so we don't know how good the C version is. The paper doesn't even report a simple fraction of FPU or bandwidth peak. It is not using SSE instructions so it cannot possibly be better than 50% of FPU peak (the limit is actually lower because this kernel is/should be bandwidth limited). As for parallelism, I'll quote Bill Gropp [1]
The easiest way to make software scalable is to make it sequentially inefficient.
[1] http://books.google.com/books?id=2Da5OcnjPSgC&lpg=PA21&#...
Haskell isn't a good example, since it's a lazy functional language, but if something like Java isn't just as fast for your case it isn't the GC, it's the code generation. Much harder to do all those fancy loop optimizations in 100 ms in a JIT than in 10s in an offline compiler.
Of course not every problem is going to fit well into an imperative model either. E.g. a problem with a large variety of pointer-y data structures and interit-y objects, like say, a compiler.
If your problem is with pauses during GC, well guess what computers pause all the times. Whenever you move your mouse or type on the keyboard, they generate interrupts that pause the whole CPU and it has to handle them. Those pauses don't seem to be a problem. If the small pauses in GC are acceptable in general usage, why not use them?
If you want hard guarantee, that's what realtime system is for.
The most efficient scheme probably is a "stop the world" system. The regular program might mutate concurrently and the GC could indeed be concurrent, but making them run at the same time is a real challenge.
Of course, people don't like it when their app pauses.
I think it's noteworthy that there never was a big office suite or even a web browser written primarily in a GC system, despite many years of promises.