Skip to content

Revisiting fast mapslices #28431

Open
Open
@bramtayl

Description

@bramtayl

I was working on updating JuliennedArrays for 0.7 and I had some thoughts. Once we're over the 1.0 hill, it might be worth considering the (mostly, I think?) non-breaking infrastructure improvements that could lead to a fast mapslices.

  1. There's been a ton of great work on constant propagation, but I think we still need Constant propogation through slurping #26050?

  2. We need a cutoff to distinguish "large" tuples from "small tuples". It's usually faster to iterate over large tuples and unroll over small tuples. I think Tim Holy had a PR for this.

  3. Type stable boolean indexing on small tuples with mixed type, e.g. (1, 2.0, "three")[(true, false, true]). This is only one of many operations that could become type-stable by unrolling small tuples (other examples include reduce, find, flatten, product, filter). This could all be done with lispy tuple iteration. If I understand correctly, creating a unified interface could unify lispy tuple iteration that is scattered across Base.

  4. Formalized reduction functions. This would look something like

struct Reduce{F}
       f::F
end
(r::Reduce)(x) = reduce(r.f, x)
const sum = Reduce(+)

etc. Knowing whether some function is an reduction of another function would enable some crucial optimizations; compare the performance of mapslices and mapreducedims.

None of this is critical but none of it is too breaking (I don't think). Just worth thinking about.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions