Skip to content

System.Memory - #94

Merged
adamsitnik merged 22 commits into
dotnet:masterfrom
adamsitnik:memory
Sep 18, 2018
Merged

System.Memory#94
adamsitnik merged 22 commits into
dotnet:masterfrom
adamsitnik:memory

Conversation

@adamsitnik

@adamsitnik adamsitnik commented Jul 20, 2018

Copy link
Copy Markdown
Member

No description provided.

@adamsitnik

Copy link
Copy Markdown
Member Author

Why is this manually unrolled? Can we use a loop instead?

It's due to the nature of Span - it's stack only, so I can't store it in the field of a class. So I need to create it as part of every benchmark. It's not a problem when it comes to time consuming benchmarks like span.CopyTo or span.Fill but span.Slice is super fast and if I write benchmark like this:

[Benchmark]
public Span<T> Slice() => new Span<T>(_arrayField).Slice(0, 1)

the Span constructor will be a huge part of the benchmark itself (up to 50%)

this is why I called the ctor once and used OperationsPerInvoke to amortize the cost of span creation. (the result is (1x span ctor + 16x slice) / 16) not 1x span ctor + 1x slice

Can we use a loop instead?

No, because the loop would be an overhead for this particular nano-benchmark

@adamsitnik

Copy link
Copy Markdown
Member Author

result is a local variable and loop independent. Does the loop get optimized?

No, our compiler is not there yet.

@adamsitnik adamsitnik changed the title [WIP] Memory System.Memory Aug 1, 2018
@adamsitnik

Copy link
Copy Markdown
Member Author

ok, I have covered entire Span, ReadOnlySpan, Memory, ReadOnlyMemory and MemoryMarshaller API with some good benchmarks. I believe the PR is ready for final review

@adamsitnik
adamsitnik requested a review from jorive August 29, 2018 08:27
@adamsitnik

Copy link
Copy Markdown
Member Author

@jorive this is the last one ;D

@jorive

jorive commented Sep 18, 2018

Copy link
Copy Markdown
        return result;;

nit: ;;


Refers to: src/benchmarks/corefx/System.Collections/Iterate/IterateFor.cs:75 in 68587cd. [](commit_id = 68587cd, deletion_comment = False)

@jorive jorive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

:shipit:

@adamsitnik
adamsitnik merged commit 4b34c30 into dotnet:master Sep 18, 2018
@adamsitnik

Copy link
Copy Markdown
Member Author

the port is complete now!

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.

2 participants