Repository navigation
Use unaligned loads and stores in UnalignedCopy64/128 - #159
Merged
Merged
Conversation
UnalignedCopy64 and UnalignedCopy128 copied through Unsafe.As refs, which emit plain ldobj/stobj and let the JIT assume natural alignment. Callers pass arbitrary byte offsets, so on ARM32 the JIT could legally emit LDRD/STRD or LDM/STM, which trap on misaligned addresses. Switch both to Unsafe.ReadUnaligned/WriteUnaligned, which emit the unaligned. prefix. x64 codegen is unchanged (mov qword / vmovups xmm), and block compress/decompress benchmarks are within noise. Remove the readonly Unsafe.As extension from UnsafeReadonly, which has no remaining callers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the fixed-size copy helpers’ switch to explicit unaligned memory access.
No open issues 🎉
What changed in this PR
This PR addresses the ARM32 alignment limitation documented in #157 by making the fixed-size copy helpers explicitly use unaligned memory access.
Changes:
- Replace typed loads and stores with
Unsafe.ReadUnalignedandUnsafe.WriteUnaligned. - Update safety contracts to remove alignment restrictions and document overlap support.
- Remove the now-unused readonly
Unsafe.Ashelper.
| File | Description |
|---|---|
Snappier/Internal/UnsafeReadonly.cs |
Removes the unused readonly reinterpretation helper and its safety contract. |
Snappier/Internal/CopyHelpers.cs |
Uses explicit unaligned operations for 64-bit and 128-bit copies and updates safety comments. |
Review effort: Balanced
brantburnett
enabled auto-merge (squash)
November 14, 2026 17:44
This was referenced Nov 16, 2026
ogonna-ee
pushed a commit
to DEFRA/waste-organisations
that referenced
this pull request
Nov 16, 2026
Updated [Snappier](https://github.com/brantburnett/Snappier) from 1.3.1 to 1.3.2. <details> <summary>Release notes</summary> _Sourced from [Snappier's releases](https://github.com/brantburnett/Snappier/releases)._ ## 1.3.2 ## What's Changed * Support fork pull requests in build workflow by @brantburnett in brantburnett/Snappier#151 * Build with the .NET 11 SDK and C# 15 by @brantburnett in brantburnett/Snappier#153 * Migrate tests to xunit.v3 4.x on Microsoft Testing Platform v2 by @brantburnett in brantburnett/Snappier#154 * Fix literal overrun validation in Snappy decompression by @brantburnett in brantburnett/Snappier#156 * Enable C# 15 memory safety rules and annotate unsafe code by @brantburnett in brantburnett/Snappier#157 * Keep memory safety rules out of BenchmarkDotNet's generated project by @brantburnett in brantburnett/Snappier#160 * Use unaligned loads and stores in UnalignedCopy64/128 by @brantburnett in brantburnett/Snappier#159 * Move hot-path exception messages into NoInlining throw helpers by @brantburnett in brantburnett/Snappier#158 * Upgrade BenchmarkDotNet to 0.16.0-preview.2 and benchmark .NET 11 by @brantburnett in brantburnett/Snappier#161 * Compare buffer distances instead of forming out-of-range refs by @brantburnett in brantburnett/Snappier#162 * Reject undersized data chunks in framed stream decompression by @brantburnett in brantburnett/Snappier#163 * Use five launches for Default benchmark jobs by @brantburnett in brantburnett/Snappier#164 * Keep rare decompression paths out of the hot loop under Dynamic PGO by @brantburnett in brantburnett/Snappier#165 **Full Changelog**: brantburnett/Snappier@release/1.3.1...release/1.3.2 Commits viewable in [compare view](brantburnett/Snappier@release/1.3.1...release/1.3.2). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
ooples
pushed a commit
to ooples/AiDotNet
that referenced
this pull request
Nov 16, 2026
Updated [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 10.1.0 to 10.1.1. <details> <summary>Release notes</summary> _Sourced from [coverlet.collector's releases](https://github.com/coverlet-coverage/coverlet/releases)._ ## 10.1.1 ### Improvements - Add `IsReachable` to branch points, computed from the method's control-flow graph, and exclude unreachable branches from branch-coverage totals and from branch details in Cobertura, LCOV and OpenCover reports [#2056](coverlet-coverage/coverlet#2056) by @pcshrosbree - coverlet.MTP: Narrow Dynamic Exclude Filters for Loaded Assemblies [#2069](coverlet-coverage/coverlet#2069) ### Fixed - Fix Regression Prevent invalid IL from branch trampolines [#2067](coverlet-coverage/coverlet#2067) - Fix Regression coverlet.MTP does not instrument local functions [#2046](coverlet-coverage/coverlet#2046) ## Maintenance - Update NuGet package versions [#2050](coverlet-coverage/coverlet#2050) [Diff between 10.1.0 and 10.1.1](coverlet-coverage/coverlet@v10.1.0...v10.1.1) Commits viewable in [compare view](coverlet-coverage/coverlet@v10.1.0...v10.1.1). </details> Updated [Microsoft.CodeAnalysis.Analyzers](https://github.com/dotnet/roslyn) from 5.9.0 to 5.12.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.CodeAnalysis.Analyzers's releases](https://github.com/dotnet/roslyn/releases)._ No release notes found for this version range. Commits viewable in [compare view](https://github.com/dotnet/roslyn/commits). </details> Updated Microsoft.CodeAnalysis.CSharp from 4.14.0 to 5.12.0. Updated [Snappier](https://github.com/brantburnett/Snappier) from 1.3.1 to 1.3.2. <details> <summary>Release notes</summary> _Sourced from [Snappier's releases](https://github.com/brantburnett/Snappier/releases)._ ## 1.3.2 ## What's Changed * Support fork pull requests in build workflow by @brantburnett in brantburnett/Snappier#151 * Build with the .NET 11 SDK and C# 15 by @brantburnett in brantburnett/Snappier#153 * Migrate tests to xunit.v3 4.x on Microsoft Testing Platform v2 by @brantburnett in brantburnett/Snappier#154 * Fix literal overrun validation in Snappy decompression by @brantburnett in brantburnett/Snappier#156 * Enable C# 15 memory safety rules and annotate unsafe code by @brantburnett in brantburnett/Snappier#157 * Keep memory safety rules out of BenchmarkDotNet's generated project by @brantburnett in brantburnett/Snappier#160 * Use unaligned loads and stores in UnalignedCopy64/128 by @brantburnett in brantburnett/Snappier#159 * Move hot-path exception messages into NoInlining throw helpers by @brantburnett in brantburnett/Snappier#158 * Upgrade BenchmarkDotNet to 0.16.0-preview.2 and benchmark .NET 11 by @brantburnett in brantburnett/Snappier#161 * Compare buffer distances instead of forming out-of-range refs by @brantburnett in brantburnett/Snappier#162 * Reject undersized data chunks in framed stream decompression by @brantburnett in brantburnett/Snappier#163 * Use five launches for Default benchmark jobs by @brantburnett in brantburnett/Snappier#164 * Keep rare decompression paths out of the hot loop under Dynamic PGO by @brantburnett in brantburnett/Snappier#165 **Full Changelog**: brantburnett/Snappier@release/1.3.1...release/1.3.2 Commits viewable in [compare view](brantburnett/Snappier@release/1.3.1...release/1.3.2). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Nov 16, 2026
Open
This was referenced Nov 17, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UnalignedCopy64andUnalignedCopy128copied throughUnsafe.Asrefs. That emits plainldobj/stobjwith nounaligned.prefix, which lets the JIT assume the address is aligned forlongorGuid. Callers pass arbitrary byte offsets:op + 1, literal pointers and match sources. On ARM32 the JIT may therefore emitLDRD/STRDorLDM/STM, which trap on misaligned addresses. #157 documented this as a known limitation; this PR fixes it.Changes
UnalignedCopy64andUnalignedCopy128now useUnsafe.ReadUnalignedandUnsafe.WriteUnaligned, which emit theunaligned.prefix. Their<safety>comments drop the ARM32 caveat.Unsafe.Asextension is removed fromUnsafeReadonly. Nothing calls it any more, and it is the API that allowed the aligned-load pattern.CopyHelpers.cs:49still usesUnsafe.Asfor the SSSE3 shuffle-pattern table. That path runs only on x86, so it is left as is.Performance
DOTNET_JitDisasmoutput on net11.0 before and after:mov qwordfor the 64-bit copy andvmovups xmmfor the 128-bit copy. The only difference is one fewer inlinee, the removed wrapper.The
UnalignedCopy64/UnalignedCopy128micro-benchmarks measure under 1 ns, below resolution, so the disassembly comparison is the meaningful check for them.Notes for reviewers
--inProcess. Since Enable C# 15 memory safety rules and annotate unsafe code #157, BenchmarkDotNet's generated boilerplate fails to build under the memory-safety rules (CS9377), so the default out-of-process toolchain can't run. That is unrelated to this change and is being fixed separately.Testing
dotnet build -c Release: succeeded.dotnet test --project Snappier.Tests -c Release: 1,544 passed, 0 failed, across net8.0, net9.0, net10.0, net11.0 and net48.🤖 Generated with Claude Code