Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[corefoundation] Cache kCFNull to avoid native calls #15146

Merged
merged 1 commit into from
May 30, 2022

Conversation

spouliot
Copy link
Contributor

@spouliot spouliot commented May 27, 2022

Calling Dlfcn.GetIntPtr is quite slow and doing for each element of
an native array slows them down.

Before

BenchmarkDotNet=v0.12.1, OS=macOS 12.3.1 (21E258) [Darwin 21.4.0]
Apple M1, 1 CPU, 8 logical and 8 physical cores
.NET Core SDK=        6.0.100 [/usr/local/share/dotnet/sdk]
  [Host] : .NET Core 6.0 (CoreCLR 6.0.522.21309, CoreFX 6.0.522.21309), Arm64 RyuJIT

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=3
LaunchCount=1  WarmupCount=3
Method Length Mean Error StdDev
ArrayFromHandleFunc 0 102.93 ns 10.035 ns 0.550 ns
ArrayFromHandleFunc 1 559.07 ns 0.533 ns 0.029 ns
ArrayFromHandleFunc 16 6,524.67 ns 8.773 ns 0.481 ns
ArrayFromHandleFunc 256 102,833.36 ns 22,060.169 ns 1,209.192 ns
ArrayFromHandleFunc 4096 1,635,076.63 ns 9,698.879 ns 531.628 ns

After

BenchmarkDotNet=v0.12.1, OS=macOS 12.3.1 (21E258) [Darwin 21.4.0]
Apple M1, 1 CPU, 8 logical and 8 physical cores
.NET Core SDK=        6.0.100 [/usr/local/share/dotnet/sdk]
  [Host] : .NET Core 6.0 (CoreCLR 6.0.522.21309, CoreFX 6.0.522.21309), Arm64 RyuJIT

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=3
LaunchCount=1  WarmupCount=3
Method Length Mean Error StdDev
ArrayFromHandleFunc 0 102.70 ns 4.991 ns 0.274 ns
ArrayFromHandleFunc 1 207.97 ns 2.064 ns 0.113 ns
ArrayFromHandleFunc 16 984.68 ns 7.795 ns 0.427 ns
ArrayFromHandleFunc 256 13,555.05 ns 147.095 ns 8.063 ns
ArrayFromHandleFunc 4096 216,002.44 ns 617.544 ns 33.850 ns

Calling `Dlfcn.GetIntPtr` is quite slow and doing for each element of
an native array slows them down.

**Before**

```
BenchmarkDotNet=v0.12.1, OS=macOS 12.3.1 (21E258) [Darwin 21.4.0]
Apple M1 2.40GHz, 1 CPU, 8 logical and 8 physical cores
.NET Core SDK=        6.0.100 [/usr/local/share/dotnet/sdk]
  [Host] : .NET Core 6.0 (CoreCLR 6.0.522.21309, CoreFX 6.0.522.21309), X64 RyuJIT

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=3
LaunchCount=1  WarmupCount=3
```

|              Method | Length |            Mean |         Error |       StdDev |
|-------------------- |------- |----------------:|--------------:|-------------:|
| ArrayFromHandleFunc |      0 |       140.98 ns |     10.995 ns |     0.603 ns |
| ArrayFromHandleFunc |      1 |       650.99 ns |     34.037 ns |     1.866 ns |
| ArrayFromHandleFunc |     16 |     6,884.68 ns |    284.458 ns |    15.592 ns |
| ArrayFromHandleFunc |    256 |   101,171.27 ns |    675.731 ns |    37.039 ns |
| ArrayFromHandleFunc |   4096 | 1,634,001.93 ns | 55,113.362 ns | 3,020.949 ns |

**After**

```
BenchmarkDotNet=v0.12.1, OS=macOS 12.3.1 (21E258) [Darwin 21.4.0]
Apple M1 2.40GHz, 1 CPU, 8 logical and 8 physical cores
.NET Core SDK=        6.0.100 [/usr/local/share/dotnet/sdk]
  [Host] : .NET Core 6.0 (CoreCLR 6.0.522.21309, CoreFX 6.0.522.21309), X64 RyuJIT

Job=InProcess  Toolchain=InProcessEmitToolchain  IterationCount=3
LaunchCount=1  WarmupCount=3
```

|              Method | Length |          Mean |        Error |     StdDev |
|-------------------- |------- |--------------:|-------------:|-----------:|
| ArrayFromHandleFunc |      0 |     141.48 ns |     3.905 ns |   0.214 ns |
| ArrayFromHandleFunc |      1 |     307.06 ns |     9.457 ns |   0.518 ns |
| ArrayFromHandleFunc |     16 |   1,227.28 ns |    13.334 ns |   0.731 ns |
| ArrayFromHandleFunc |    256 |  14,076.72 ns |   418.940 ns |  22.963 ns |
| ArrayFromHandleFunc |   4096 | 251,251.85 ns | 7,341.339 ns | 402.404 ns |
Copy link
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ it! Thanks a lot @spouliot!

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dalexsoto dalexsoto added community Community contribution ❤ notes-mention Deserves a mention in release notes labels May 27, 2022
@spouliot
Copy link
Contributor Author

spouliot commented May 27, 2022

Noticed the X64 RyuJIT in the logs :( even if the project was changed to osx-arm64. Turns out the pre-test process is Intel not Apple
Not that I expect the ratio of being very different...

UPDATE: Original description updated with Arm64 RyuJIT numbers :)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 5bcfb8ded7a762567e2a824aacf1686a05382a41

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📋 [PR Build] API Diff 📋

API diff (for current PR)

ℹ️ API Diff (from PR only) (please review changes)

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

API diff (vs stable)

✅ API Diff from stable

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

Generator diff

ℹ️ Generator Diff (please review changes)

Pipeline on Agent XAMBOT-1023.Monterey
Hash: 5bcfb8ded7a762567e2a824aacf1686a05382a41

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1105.Monterey
Hash: 5bcfb8ded7a762567e2a824aacf1686a05382a41

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
Hash: 5bcfb8ded7a762567e2a824aacf1686a05382a41

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

4 tests failed, 144 tests passed.

Failed tests

  • interdependent-binding-projects/watchOS 32-bits - simulator/Debug: Crashed
  • introspection/watchOS 32-bits - simulator/Debug: Crashed
  • dont link/watchOS 32-bits - simulator/Debug: Crashed
  • mono-native-compat/watchOS 32-bits - simulator/Debug: Crashed

Pipeline on Agent XAMBOT-1043.Monterey'
Merge 5bcfb8d into 6676f81

@rolfbjarne
Copy link
Member

rolfbjarne commented May 30, 2022

Test failures are unrelated (https://github.com/xamarin/maccore/issues/2558).

@rolfbjarne rolfbjarne merged commit d869a68 into dotnet:main May 30, 2022
@spouliot spouliot deleted the cache-kCFNull branch May 30, 2022 13:38
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
community Community contribution ❤ notes-mention Deserves a mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants