Skip to content

Optimizing a runtime-generated constant value #84094

@sharwell

Description

@sharwell

This property always returns a constant value for a given T:
https://github.com/dotnet/roslyn/blob/6d527c3fb4b223f35bca50d364f46ac3732c4a76/src/Dependencies/Collections/SegmentedArray%601.cs#L33-L40

It relies on these helpers to produce the constant value:
https://github.com/dotnet/roslyn/blob/6d527c3fb4b223f35bca50d364f46ac3732c4a76/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs#L26-L37
https://github.com/dotnet/roslyn/blob/6d527c3fb4b223f35bca50d364f46ac3732c4a76/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs#L138
https://github.com/dotnet/roslyn/blob/6d527c3fb4b223f35bca50d364f46ac3732c4a76/src/Dependencies/Collections/Internal/SegmentedArrayHelper.cs#L145

I was hoping this implementation would produce an inline constant value at runtime via the JIT. However, I'm seeing calls to SegmentedArrayHelper.GetSegmentShift<T> in runtime profiling traces. I tried using SharpLab to find a better way to generate these, but my ideas so far rely on static constructors which are not supported by its assembly output feature.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions