Repository navigation
Conversation
|
Woohoo! This is awesome! It's indeed quite painful to eak out as much performance as possible using standard iteration protocols from Base. So in #42, I basically have to overload every custom array operation from Base to avoid iteration and sequential indexing. I am worried about the current dependency tree here; this package has become a "foundational" package of the data ecosystem, so it's a hard to allow adding such heavy dependencies. I love the idea of a FoldBase.jl though that would allow a lightweight "hook" into all the folds/transducers magic. |
|
[comment generated via AI] Closing this RFC. The dependency concern from the 2021 discussion still applies (SentinelArrays sits under most of the data ecosystem), and the lighter FoldsBase split never landed. ChainedVector now overloads the hot Base reductions and copies chunk by chunk directly. Thank you for the demonstration. |
This patch implements two JuliaFolds interfaces on
ChainedVector: the sequential iteration protocol (akafoldl) using FGenerators.jl syntax and SplittablesBase.jl interface for parallel reductions.Arguably, the dependency tree pulled via FGenerators.jl, especially Transducers.jl, is rather large. I'm not sure if you want to pull this in at this stage (i.e., probably you'd want to wait until I extract it out as FoldsBase.jl). But I thought it'd be interesting to demonstrate that using JuliaFolds' iteration facility can be beneficial for not only parallel reduction but also for sequential iterations. For example, maybe this can make some parts of the optimization like #42 easier.
This patch uses FGenerators.jl which is a syntax sugar of
Transducers.__foldl__. This is mainly because writing__foldl__is slightly tedious and also I may need to tweak the interface for solving some subtle problems in parallel reduction at some point. But I expect the syntax sugar provided by FGenerators.jl to be more stable.Microbenchmark
A simple summation of
ChainedVector{Int}is 4x faster with@floopthat usesfoldlas the iteration mechanism. Looking into LLVM,@floopversion is vectorized butiterateversion is not.Note: I'm using
Intas the element type so that vectorization can be triggered easily. Supporting@simdfor floats is possible but ATM it requires a rather ugly macro.I think it's a big win, also considering that the
@yield-based syntax is much simpler than the complexiterateimplementation:SentinelArrays.jl/src/folds.jl
Lines 4 to 10 in ec17e62