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

ByteBuffer uses ArrayPool to prevent LOH allocations #11660

Merged
merged 17 commits into from
Jun 16, 2021

Conversation

TIHan
Copy link
Contributor

@TIHan TIHan commented Jun 9, 2021

loh
We allocate a lot on the LOH when serializing FSharp metadata. This PR should help.

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.

I like the approach, and it seems great to not constantly reallocate those large buffers.

@TIHan TIHan changed the title [WIP] Byte buffer uses ArrayPool to prevent LOH allocations Byte buffer uses ArrayPool to prevent LOH allocations Jun 9, 2021
@TIHan TIHan changed the title Byte buffer uses ArrayPool to prevent LOH allocations ByteBuffer uses ArrayPool to prevent LOH allocations Jun 10, 2021
@TIHan TIHan changed the title ByteBuffer uses ArrayPool to prevent LOH allocations ByteBuffer uses ArrayPool to prevent LOH allocations Jun 10, 2021
@@ -75,6 +75,7 @@
https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json;
</RestoreSources>
<!-- System.* packages -->
<SystemRuntimeCompilerServicesUnsafeVersion>4.7.1</SystemRuntimeCompilerServicesUnsafeVersion>
Copy link
Contributor Author

@TIHan TIHan Jun 14, 2021

Choose a reason for hiding this comment

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

@KevinRansom you may not like this, but the changes I made with the ByteBuffer, is calling something from System.Runtime.CompilerServices.Unsafe, which has problems with binding redirects. Best way to resolve this is including the specific version.

Copy link
Member

@KevinRansom KevinRansom left a comment

Choose a reason for hiding this comment

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

This looks goods, I wonder why we have so many different sizes for allocation buffers, 100000, 50000, 20000 and 10000. Meaningful names might help me understand why each size was chosen, Of course it might not too.

let phase2data = (stringTab, phase1bytes)

let st2 =
{ os = ByteBuffer.Create(100000, useArrayPool = true)
Copy link
Member

Choose a reason for hiding this comment

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

possibly a constant for 100000, it's used several places in this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have no idea why these values were chosen. This was here before.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, just give it a name. pickle_object_buffersize or somesuch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the literals.

{ emitTailcalls=emitTailcalls
deterministic = deterministic
showTimes=showTimes
ilg = ilg
desiredMetadataVersion=desiredMetadataVersion
requiredDataFixups= requiredDataFixups
requiredStringFixups = []
codeChunks=ByteBuffer.Create 40000
codeChunks=ByteBuffer.Create(40000, useArrayPool = true)
Copy link
Member

Choose a reason for hiding this comment

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

perhaps constant for 40000

@@ -3230,7 +3241,7 @@ let writeILMetadataAndCode (generatePdb, desiredMetadataVersion, ilg, emitTailca
codedBigness 2 TableNames.AssemblyRef ||
codedBigness 2 TableNames.TypeRef

let tablesBuf = ByteBuffer.Create 20000
use tablesBuf = ByteBuffer.Create(20000, useArrayPool = true)
Copy link
Member

Choose a reason for hiding this comment

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

perhaps a name and a constant for 20000

@@ -3309,7 +3320,7 @@ let writeILMetadataAndCode (generatePdb, desiredMetadataVersion, ilg, emitTailca
reportTime showTimes "Layout Metadata"

let metadata, guidStart =
let mdbuf = ByteBuffer.Create 500000
use mdbuf = ByteBuffer.Create(500000, useArrayPool = true)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps a name and a constant for 50000?

@TIHan
Copy link
Contributor Author

TIHan commented Jun 15, 2021

Addresses this issue: #7982
Only took a year and a half...

@TIHan TIHan closed this Jun 15, 2021
@TIHan TIHan reopened this Jun 15, 2021
@TIHan TIHan closed this Jun 16, 2021
@TIHan TIHan reopened this Jun 16, 2021
@TIHan TIHan closed this Jun 16, 2021
@TIHan TIHan reopened this Jun 16, 2021
@TIHan TIHan closed this Jun 16, 2021
@TIHan TIHan reopened this Jun 16, 2021
@cartermp
Copy link
Contributor

note that azdo is down for us, so there's no point in trying to re-trigger CI

@TIHan TIHan merged commit f13b4ff into dotnet:main Jun 16, 2021
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.

4 participants