Skip to content

Optimization of layer reading/saving - #65

Merged
aqpanaciy merged 2 commits into
developfrom
aqpanaciy-layer
Sep 27, 2026
Merged

aqpanaciy merged 2 commits into
developfrom
aqpanaciy-layer

Conversation

@aqpanaciy

Copy link
Copy Markdown
Collaborator
  • сalculate the hash of a layer data file without loading it into memory;
  • write the array with layer data directly, while simultaneously calculating its hash;
  • ReadLayer now opens the file and streams bytes directly into a T[] .

aqpanaciy and others added 2 commits September 23, 2026 11:54
- сalculate the hash of a layer data file without loading it into memory;
- write the array with layer data directly, while simultaneously calculating its hash.

Co-Authored-By: Google Gemini <gemini@google.com>
ReadLayer now opens the file and streams bytes directly into a T[] for blittable structs to avoid an extra intermediate byte[] allocation. It uses MemoryMarshal.AsBytes and RuntimeHelpers.IsReferenceOrContainsReferences to choose the fast path, handles zero-length files, and falls back to the original ReadAllBytes->ToArray<T>() logic when the file size isn't a sizeof(T) multiple, the type contains references, or a partial read occurs. Added necessary using directives. Keeps behavior compatible while reducing allocations for raw binary layer files.

Co-Authored-By: Copilot <198982749+Copilot@users.noreply.github.com>
@aqpanaciy
aqpanaciy merged commit acd9c3a into develop Sep 27, 2026
4 checks passed
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.

2 participants