Skip to content

Replace sizeof(UIntPtr) with UIntPtr.Size in condition - #242

Closed
marek-safar wants to merge 1 commit into
dotnet:masterfrom
marek-safar:sizeof
Closed

marek-safar wants to merge 1 commit into
dotnet:masterfrom
marek-safar:sizeof

Conversation

@marek-safar

Copy link
Copy Markdown
Contributor

for easier ILLinker detection

(his is more stylistic change than noticeable size reduction)

for easier ILLinker detection

(his is more stylistic change than noticeable size reduction)
@jkotas

jkotas commented Nov 25, 2019

Copy link
Copy Markdown
Member

sizeof(UIntPtr) is slightly more efficient than UIntPtr.Size (it is not a call). Would it be better to teach the linker to recognize sizeof(UIntPtr) as equivalent to UIntPtr.Size ?

@jkotas

jkotas commented Nov 25, 2019

Copy link
Copy Markdown
Member

Since this is CoreLib, we can also just put this under #if BIT64 ifdef and make this stripped in 32-bit builds by default. No IL linker needed.

@marek-safar

Copy link
Copy Markdown
Contributor Author

Would it be better to teach the linker to recognize sizeof(UIntPtr)

That's a good idea and I cannot think of scenario where we'd need to differentiate them.

sizeof(UIntPtr) is slightly more efficient than UIntPtr.Size (it is not a call).

You mean it's slightly more efficient in terms of IL size of performance? IL size of the call seems smaller than sizeof so the call syntax should be prefered from this perspective. For the performance impact, we could add AggressiveInlining to Size property or it that not enough for RyuJIT?

Since this is CoreLib, we can also just put this under #if BIT64 ifdef

Sure but I'd prefer to have a pattern we recommend to library authors.

@jkotas

jkotas commented Nov 25, 2019

Copy link
Copy Markdown
Member

For the performance impact, we could add AggressiveInlining to Size property or it that not enough for RyuJIT?

The JIT is not always able to get rid of all clutter from inlining. For example, https://github.com/dotnet/coreclr/issues/27935

@jkotas

jkotas commented Nov 25, 2019

Copy link
Copy Markdown
Member

Sure but I'd prefer to have a pattern we recommend to library authors.

Some library authors may choose to do multiple builds, like we do for CoreLib.

@marek-safar

Copy link
Copy Markdown
Contributor Author

ok, closing

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants