Skip to content

Conversation

@T-Gro
Copy link
Member

@T-Gro T-Gro commented Mar 17, 2023

This is the last step of the RFC to expand the Array.Parallel module, based on approved suggestion .

This PR includes:

  • min
  • minBy
  • max
  • maxBy
  • sum
  • sumBy
  • average
  • averageBy

And two functions on which the implementation relies on:

  • reduce
  • reduceBy (= map & reduce in a single step)

The benchmarks used for the choice of implementation are here https://github.com/T-Gro/Array.Parallel.Aggs.Benchmark/tree/main/Results .

Among others, the following dimensions were already evaluated and lead to the choice of existing implemented solution:

  • Implement via reduce/reduceBy vs manual handcrafted impl for each
  • Usage of ref-tuple vs. struct-tuple for minBy/maxBy operations
  • Chunking the array vs. doing Parallel.For for each element of the array separately
  • And most importantly, the amount of inlining:
    • Naturally, the fastest solution was to inline (and InlineIfLambda) everything
    • However, finally chosen solution inlines all the "one liners", but leaves the workhorse ("reduceBy") non-inlined. This was the second fastest option, very close to manually handrolled functions. And, will have smaller footprint on resulting codesize, as the compiler will only inline the one-liners and calls to "reduceBy", without repeating the body of it.

@T-Gro T-Gro marked this pull request as ready for review March 20, 2023 18:54
@T-Gro T-Gro requested a review from a team as a code owner March 20, 2023 18:54
@T-Gro
Copy link
Member Author

T-Gro commented Apr 11, 2023

/run fantomas

@github-actions
Copy link
Contributor

@T-Gro T-Gro merged commit f69e2f5 into dotnet:main Apr 20, 2023
@T-Gro T-Gro deleted the array-parallel-aggregations branch April 20, 2023 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants