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

Use new .NET Core 3.0 API to get the total number of allocated bytes for all threads #1155

Merged
merged 3 commits into from May 17, 2019

Conversation

Projects
None yet
3 participants
@adamsitnik
Copy link
Member

commented May 16, 2019

preview6 of .NET Core 3.0 exposes a new method that allows to get the number of allocated bytes for all threads. By using it we can fix #1153 and #723

Sample:

public class MultiThreadedAllocation
{
    public const int Size = 1_000_000;
    public const int ThreadsCount = 10;

    private Thread[] threads;

    [IterationSetup]
    public void SetupIteration()
    {
        threads = Enumerable.Range(0, ThreadsCount)
            .Select(_ => new Thread(() => GC.KeepAlive(new byte[Size])))
            .ToArray();
    }

    [Benchmark]
    public void Allocate()
    {
        foreach (var thread in threads)
        {
            thread.Start();
            thread.Join();
        }
    }
}
dotnet run -c Release -f netcoreapp2.1 --filter *MultiThreadedAllocation* --runtimes netcoreapp3.0 netcoreapp2.1 net461 --memory 
Method Runtime Toolchain Gen 0 Gen 1 Gen 2 Allocated
Allocate Clr net461 2000.0000 2000.0000 2000.0000 10024816 B
Allocate Core netcoreapp2.1 2000.0000 2000.0000 2000.0000 -
Allocate Core netcoreapp3.0 2000.0000 2000.0000 2000.0000 10001360 B
@adamsitnik

This comment has been minimized.

Copy link
Member Author

commented May 16, 2019

@stephentoub
Copy link
Member

left a comment

Thanks!

@adamsitnik adamsitnik merged commit f54055a into master May 17, 2019

9 checks passed

BenchmarkDotNet - Ubuntu Build #2019.5.17.1 succeeded
Details
BenchmarkDotNet - Windows Build #2019.5.17.1 succeeded
Details
BenchmarkDotNet - macOS Build #2019.5.17.1 succeeded
Details
WIP Ready for review
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
license/cla All CLA requirements met.
Details

@adamsitnik adamsitnik deleted the GC.GetTotalAllocatedBytes branch May 17, 2019

@AndreyAkinshin

This comment has been minimized.

Copy link
Member

commented May 24, 2019

@AndreyAkinshin AndreyAkinshin added this to the v0.11.6 milestone May 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.