Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

F# without the allocs #12

Merged
merged 3 commits into from
Apr 13, 2020
Merged

F# without the allocs #12

merged 3 commits into from
Apr 13, 2020

Conversation

cartermp
Copy link
Contributor

@cartermp cartermp commented Apr 13, 2020

  • Moves to .NET Core
  • Marks various functions inline
  • Value types instead of reference types, since most of the underlying data is just numeric primitives
  • Adds a lot more to the .gitignore

These are the comparative results on my machine, which is different but I'd expect a similar improvement in timings:

Creating a scene:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.720 (1909/November2018Update/19H2)
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=3.1.300-preview-015048
  [Host]     : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT DEBUG
  DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT

Method Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
Original 438.6 μs 7.10 μs 6.29 μs 1.00 329.1016 23.4375 - 1333.62 KB
Modified 178.0 μs 3.53 μs 5.06 μs 0.41 146.7285 0.4883 - 558.04 KB

Rendering:

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.720 (1909/November2018Update/19H2)
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=3.1.300-preview-015048
  [Host]     : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT DEBUG
  DefaultJob : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT

Method Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
Original 178.68 ms 3.550 ms 9.718 ms 1.00 0.00 275000.0000 46000.0000 1000.0000 1095.79 MB
Modified 63.01 ms 0.768 ms 0.681 ms 0.35 0.02 2555.5556 111.1111 111.1111 10.8 MB

Both seem to represent a nice improvement. However, there are likely more things to be explored:

  • Using IsByRefLike structs and the Span<T> type to elide bounds checking
  • Fiddling with more advanced .NET perf stuff

@athas
Copy link
Owner

athas commented Apr 13, 2020

Neat! Thanks!

@athas athas merged commit b6655e7 into athas:master Apr 13, 2020
@athas
Copy link
Owner

athas commented Apr 13, 2020

I don't have .NET Core 3.1 on this machine, but 2.1 seems to also run this pretty fast.

athas added a commit that referenced this pull request Apr 13, 2020
@cartermp
Copy link
Contributor Author

cartermp commented Apr 13, 2020

If you upgrade to 3.1 there should be some improvements as well. Lots of little fixes in the standard library for .NET that make things run transparently faster. But I wouldn't expect a dramatic improvement 🙂

@battlebottle
Copy link

@cartermp you bet me to it ;). I believe changing the Pixel tuple to a struct also improves performance, though I did not test this thoroughly.

@cartermp
Copy link
Contributor Author

@battlebottle The pixel tuple should be a struct here as well, unless I'm missing something: https://github.com/athas/raytracers/blob/master/fsharp/ray.fs#L281

@battlebottle
Copy link

@cartermp Ah you're right, my mistake. I misread the commit somehow 😩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants