Cache-Efficient Functional Algorithms (2014) [pdf]
cs.cmu.edu
cs.cmu.edu
But to be honest I think just malloc is a decent abstraction. You control memory layout and the rest is having algorithms with good access patterns.
I'm a huge fan of separating the business specifications from talking about the execution.
-------
Some runtimes will do this under the hood.
RDBMS execution plans are a good example. Plan costs are calculated using data-dependent statistics. And cache-friendliness is taken into account: in postgres, hash joins are made to fit L1 (tuples per bucket = 10) and L3 caches (work_mem default to 4MB, after which batches are introduced) [1]
Some JITs will also monitor performance and behavior, and try to speculatively prune unused paths.
But this is all letting the runtime deal with it.
-------
Execution should be treated as an orthogonal but tweakable concern. And be exposed in some way to the user.
Halide [2] is one very interesting approach, is letting user choose:
* between materialization and compute-again
* parallelism levels
* chunk sizes
* scheduling, etc.
However the storage is implied by the execution chosen. Which to me is a constraint that is automatically enforced, and not exposed.
-------
All knobs, and their consequences, should be readily available to both users and compilers.
To me, typed languages could, should contain so much more information about performance (or anything!).
The perfect abstraction should be the seamless integration of 4 languages:
* Logical business requirements (what you want done). Should be user friendly
* Business properties requirements (constraints like liveness, performance envelope, security, or business ones). Declarative
* A language to help in proofs. Think TLA+[3] or the checker framework [4].
* A language to express which implementations are chosen, knobs to configure, how the layout is done (array of structs, struct of arrays?). Think Halide or JAI [5].
Such a combination of languages should be built on extremely typed primitives; the combination of which should propagate type information, and provide hooks to provide more type information.
An implementation of a sum of a value over a range should make emerge information about:
* which business properties it offers
* which items will benefit from fitting in cache
* which parts can be stopped without lock contention
* different options for the memory layout coming into and out of this algorithm
In the internals, something as simple as a + b would look like:
@Associative
@Commutative
@MapsTo(Algebra.addition)
@Inlineable
@CanSafePointBefore
@WillNotContend
@NonBlocking
@CacheSizefunction(argumentsSize + returnSize)
@BatchingStrategies(Single,Batch.L1Size,Batch.L1Size)
@WaitOnIOStrategy(Unscheduleable)
@ArgumentPassing(ref,value,ArrayOfStruct,StructOfArrays)
@ReturnPassing(ref,value,Array)
@Properties(case unsigned: ret >= a and ret >= b)
def plus(
a @NumberType(uint16, int, IEEEfloat, double, @CustomizeableNumber)
,
b @NumberType(uint16, int, IEEEfloat, double, @CustomizeableNumber)
) {
return @
a
+ @Impl(asm_x86_add,simd_x86_add,cuda_add)
@NumberTypeInference
b
}
-------In short: a language into which anyone can commit type information, with type information that could inform performance.
[1] http://patshaughnessy.net/2016/1/22/is-your-postgres-query-s...
[3] http://cseweb.ucsd.edu/~daricket/papers/fm2012.pdf
[4] http://types.cs.washington.edu/checker-framework/current/che...
One opportunity I do find in this article is real-world performance tests and determining the importance of constants in performance tuning. Prakop et al. did some really interesting work in 1999 on cache-oblivious algorithms, with applications to kernels such as the FFT and matrix multiplication. The work is theoretically extremely interesting, but in practice, hand-written or machine-generated algorithms continue to dominate. The most famous example of this is probably Kazushige Goto, whose hand-optimized GotoBLAS (now under open source license as OpenBLAS) still provides some of the fastest linear algebra kernels in the world.
If you're interested in learning more about how the differences between the two approaches shake out in linear algebra, I recommend "Is Cache-Oblivious DGEMM Viable?" by Gunnels et al.
Ocaml is functional but allows arbitrary state mutations. On the other hand it is typically very straightforward to implement persistent data structures in a non-functional language with GC support.
Personally I see this as unfortunate as the persistence as a term IMO is much more precise. It also remains that one also needs GC and properly accounts its cost which this paper discuss a lot.
So my assumption (which could be wrong) is that by using the word "functional" that article unnecessary restricts its auditory. For example, a Java programmer would not even bother to open it assuming this is something relevant at best to Haskell or F#. I definitely had such expectation.