Skip to content

Clarify get inlining #32071

@chucker

Description

@chucker

The page says:

The execution of the get accessor is equivalent to reading the value of the field. For example, when you're returning the private variable from the get accessor and optimizations are enabled, the call to the get accessor method is inlined by the compiler so there's no method-call overhead. However, a virtual get accessor method can't be inlined because the compiler doesn't know at compile-time which method may actually be called at run time.

My interpretation is this is correct but slightly confusing. Specifically, the emphasis is on "the call to", as in

  • the get accessor method does not get inlined, but
  • the call to it may get inlined

This is even more confusing by the "However" sentence afterwards, which is a non sequitor — the get accessor method itself doesn't get inlined regardless.

This is indeed the behavior I observe.

Can we expand this to make it clearer? For example:

For example, when you're returning the private variable from the get accessor and optimizations are enabled, the call to the get accessor method is inlined by the compiler so there's no method-call overhead. However, a get accessor does still get emitted. In addition, a call to a virtual get accessor method can't be inlined because the compiler doesn't know at compile-time which method may actually be called at run time.

[Enter feedback here]


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.


Associated WorkItem - 230267

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredIdentifies that an issue has been imported into Quest.dotnet-csharp/svcfundamentals/subsvcin-prThis issue will be closed (fixed) by an active pull request.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions