Skip to content

Slightly improve performance and maintainability in SequentialGuidValueGenerator #35981

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rameel
Copy link

@rameel rameel commented Apr 22, 2025

Replace unnecessary byte copying with direct in-place modification.

Guid uses a sequential layout where the first 8 bytes require endianness handling on big-endian systems when reading from or writing to a byte array (e.g., via MemoryMarshal or Guid constructors). The remaining 8 bytes are interpreted as-is, regardless of endianness.

Since we only modify the last 8 bytes of the Guid, byte order does not affect the result, so we can:

  • Eliminate intermediate copies
  • Skip unnecessary byte order conversions
  • Safely use MemoryMarshal.AsBytes for direct access

The optimization maintains identical behavior while being more efficient.

@rameel rameel requested a review from a team as a code owner April 22, 2025 19:24
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.

1 participant