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

Redundant "Clear" in many buffer allocations #241

Closed
mgravell opened this issue Apr 5, 2024 · 0 comments · Fixed by #242
Closed

Redundant "Clear" in many buffer allocations #241

mgravell opened this issue Apr 5, 2024 · 0 comments · Fixed by #242

Comments

@mgravell
Copy link
Contributor

mgravell commented Apr 5, 2024

In a number of places in the storage layer, GC.AllocateArray is used to allocate an array on the pinned heap, followed shortly by an Array.Clear. This is redundant, since GC.AllocateArray pre-initializes the data to zero. I'm guessing this might be a hangover from a previous unmanaged allocator, or from migration from a C/C++ implementation.

If the intent is to use unitialized data in the oversized portion: GC.AllocateUnitializedArray exists (but only works for blittable types); otherwise and probably simpler to grok (and easier to validate correctness): just remove the Array.Clear calls, leaving the default/inbuilt zero initialize (i.e. do not switch to GC.AllocateUninitializedArray).

impact: performance

examples:

  • BlittableFrame.Allocate
  • MallocFixedPageSize.InternalAllocate (2 of)
  • SpanByteAllocator.AllocatePage

similar with simple array creation (no GC alloc):

  • GenericAllocator<,>.AllocatePage
  • GenericFrame<,>.Allocate
badrishc pushed a commit that referenced this issue Apr 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant