dotnet / dotnet/fsharp

Performance of Array.collect with empty inputs

Open
#20,382 1 comment 0 reactions 1 assignee Claimed by @T-Gro View on GitHub
Area-Library
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Hi,

Not sure if this is of interest or not, but given all the current work with optimisations I'll query it:

I was recently doing some profiling on FSharpLint, and found that there were massive amounts of allocations of zero length arrays occurring when calling Array.collect with empty arrays as inputs - see https://github.com/fsprojects/FSharpLint/pull/873 where FSharpLints own benchmark project was showing ~1.3 million allocations of each of a one dimensional and two dimensional arrays of warnings.

This seems particularly noticeable in collect() as it creates two zero length arrays per call - the intermediate one for collecting results and the final one that's returned to callers - so I wonder if it'd be worth doing something to avoid at least one of those? (I'm not sure if returning Array.empty would be permitted or not, but maybe the intermediate one can be improved).

There's a similar situation with Array.map creating a zero length array for empty inputs, though the documentation fort that does say ```Builds a new array``` so maybe that's technically expeted

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.