Skip to content

ByteBuffer uses ArrayPool to prevent LOH allocations#11660

Merged
TIHan merged 17 commits into
dotnet:mainfrom
TIHan:byte-buffer-loh-fix
Jun 16, 2021
Merged

ByteBuffer uses ArrayPool to prevent LOH allocations#11660
TIHan merged 17 commits into
dotnet:mainfrom
TIHan:byte-buffer-loh-fix

Conversation

@TIHan

@TIHan TIHan commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

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

@cartermp cartermp left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/fsharp/utils/FileSystem.fs Outdated
@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
Comment thread eng/Versions.props Outdated
https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json;
</RestoreSources>
<!-- System.* packages -->
<SystemRuntimeCompilerServicesUnsafeVersion>4.7.1</SystemRuntimeCompilerServicesUnsafeVersion>

@TIHan TIHan Jun 14, 2021

Copy link
Copy Markdown
Contributor Author

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.

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/fsharp/QuotationPickler.fs Outdated
let phase2data = (stringTab, phase1bytes)

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
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.

Comment thread src/fsharp/absil/ilwrite.fs Outdated
requiredDataFixups= requiredDataFixups
requiredStringFixups = []
codeChunks=ByteBuffer.Create 40000
codeChunks=ByteBuffer.Create(40000, useArrayPool = true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps constant for 40000

Comment thread src/fsharp/absil/ilwrite.fs Outdated
codedBigness 2 TableNames.TypeRef

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

Copy link
Copy Markdown
Contributor

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

Comment thread src/fsharp/absil/ilwrite.fs Outdated

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

Copy link
Copy Markdown
Contributor

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

TIHan commented Jun 15, 2021

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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