Escape Analysis: Elide an array allocation in BitConverter.GetBytes pattern
Nobody has claimed this yet.
Assessment
This issue has not been assessed yet.
Description
JIT should be able to eliminate GC allocation in this snippet:
void Test(int value, Span<byte> dest) =>
BitConverter.GetBytes(value).AsSpan(0, 3).CopyTo(dest);
This pattern could be used as a safe alternative to "write N-bytes of a primitive to a span of bytes". Alternative zero-alloc patterns don't look pretty/involve unsafe
Sub-tasks:
- Mark Memmove as non-escaping (https://github.com/dotnet/runtime/pull/113093)
- Make sure
BitConverter.GetBytesis inlineable (it is not currently) (https://github.com/dotnet/runtime/pull/114806) - Escape Analysis for non-captured Span (https://github.com/dotnet/runtime/pull/113977)
- Make this work in R2R as well
- Verify this works properly in Tier1+instr
cc @AndyAyersMS
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 589
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 75/100
sillsdev/languageforge-lexbox#2665 ·
-
bug documentation frontend
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
azurenoops/spin_agent#975 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·