Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of String.concat for seq of type array or list #9483

Merged
merged 8 commits into from
Jul 25, 2020

Conversation

abelbraaksma
Copy link
Contributor

@abelbraaksma abelbraaksma commented Jun 18, 2020

This follows the findings and timings shown in this comment: #9390 (comment)

Basically: special-casing the input seq for array gives 2x perf gain and less 2-3x less mem use, and special-casing for list gives 20% gain and 30% less mem and GC pressure.

@KevinRansom: this is the one we discussed that shows no improvement by using array-based manipulation if the input is a seq, and since String.Join uses buffered-SB internally, that may well be the reason it already performed so well.

It's also a showcase of the internal ArrayEnumerator of arrays-turned-into-sequences, however fast it is, still adding a lot of time for the indirection, hence the success of the special-casing of array. Try this new method with Array.toSeq x and with implicit x :> seq<_> and watch the difference (a factor 2).

This PR is dependent on #9481.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some conflicts and stylistic change, but otherwise this looks good!

src/fsharp/FSharp.Core/string.fs Outdated Show resolved Hide resolved
@abelbraaksma
Copy link
Contributor Author

abelbraaksma commented Jun 18, 2020

Since we now have three execution paths (for list, seq and array), I changed the tests to execute all three paths for the existing tests 9c6ba3f.

@abelbraaksma abelbraaksma requested a review from cartermp June 18, 2020 18:32
@abelbraaksma
Copy link
Contributor Author

Strange, it keeps saying "Changes requested" even though all requests have been resolved. Maybe I'm doing something wrong...

@KevinRansom
Copy link
Member

@abelbraaksma , the requester has to acknowledge that they have been handled I believe.

@abelbraaksma abelbraaksma requested a review from KevinRansom June 19, 2020 17:14
@abelbraaksma
Copy link
Contributor Author

abelbraaksma commented Jun 24, 2020

All requested changes have been implemented and build is green. @cartermp / @KevinRansom, is it ok like this?

@abelbraaksma
Copy link
Contributor Author

@cartermp, you merged master into this, I think this is now ready?

@cartermp
Copy link
Contributor

cartermp commented Jul 5, 2020

@abelbraaksma I think this is ready, but this will require one other review (preferably @KevinRansom since he previously requested changes)

@abelbraaksma
Copy link
Contributor Author

/cc @KevinRansom

@cartermp cartermp merged commit 62b0140 into dotnet:master Jul 25, 2020
@abelbraaksma
Copy link
Contributor Author

Thanks @KevinRansom!

@abelbraaksma abelbraaksma deleted the String.concat-perf branch July 25, 2020 20:33
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
…otnet#9483)

* Move `String.length` to the top of its module so that the `length` function is in scope

* Improve performance of String.concat for arrays and lists

* Make concatArray local to String.concat

* Testing String.concat, make sure the new three paths are covered

* Remove "foo", "bax", "bar" in tests, making them more readable

Co-authored-by: Phillip Carter <pcarter@fastmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants