Skip to content

Redundant "Clear" in many buffer allocations #241

@mgravell

Description

@mgravell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions