Skip to content

Conversation

Eideren
Copy link
Collaborator

@Eideren Eideren commented Sep 11, 2025

PR Details

Calls to Utilities.CopyMemory mapping to System.Buffer.MemoryCopy were swapped for Unsafe.CopyBlockUnaligned in #1469 without clarification.
Those two methods are not equivalent, CopyBlockUnaligned is safer but significantly slower compared to MemoryCopy as it does not have any fast path based on the allocation sizes.

As for the safety of the unaligned version, under x86/64 and recent ARM, reading or writing data outside of their natural alignment do not cause any issues besides slowdown. I've ensured that other platforms, like ARM7 and connected devices' memory, keep using the unaligned version.

The vast majority of our codebase ensures that fields and allocations are aligned, so using operations that expect to operate on aligned memory provides a significant performance improvement.

Scenes with a significant amount of draw calls rely on memcopy to fill in graphics commands and shader parameters.
In one of the heavier sections I have at my disposal, frames can take up to 23 millisecond to prepare on the CPU side, introducing this change cuts it down to 14 millisecond.
Here's the Profiler sessions.zip

More information in
dotnet/runtime#1650 (comment)
dotnet/runtime#80068 (comment)

Related Issue

N/A

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant