Git Product home page Git Product logo

fable-raytracer's Introduction

fable-raytracer

Small ray tracer demo of the F# to Rust language transpiler in Fable 4.x

Online demo:

https://ncave.github.io/fable-raytracer/

Build and run:

  • install .NET and Node.js
  • install Rust and wasm-pack
  • run dotnet tool restore to get Fable installed locally
  • run one of the performance tests:
    • npm run test-js-node (F# to JavaScript, running in Node.js)
    • npm run test-wasm-web (F# to Rust to WebAssembly, in Browser, localhost:8080)
    • npm run test-wasm-node (F# to Rust to WebAssembly, running in Node.js)
    • npm run test-rust (F# to Rust, running as native binary)
      • npm run test-rust-target-cpu (as above, but allow Rust to target your CPU and use newer instructions)
    • npm run test-python (F# to Python, running as Python)
    • npm run test-dotnet (F# running on .NET as managed code)
    • npm run test-native (F# running on .NET as native binary)
    • npm run test-dotnet-wasm (F# .NET to WebAssembly AOT, running in Node.js)
      • (needs dotnet workload install wasm-tools, run with admin permissions)

fable-raytracer's People

Contributors

alfonsogarciacaro avatar dbrattli avatar kant2002 avatar mike-barber avatar ncave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

fable-raytracer's Issues

[Proposal] Rust configuration for improved performance

This is a really interesting project! Really nice work :)

I have some small suggestions to improve the Rust performance, and am willing to contribute by creating a PR if you like. I thought it better to post an issue for discussion before opening an unsolicited PR :)

Essentially, it's the following things:

  • LTO is not being applied to the release build that we're measuring in the mini benchmark. We have thin LTO enabled, but it's quite a bit faster with full fat LTO and codegen-units=1, possibly due to the code residing in two different modules. This bumps the performance of the WASM build a little too.
  • For the test-rust native target, there's a significant performance improvement if we allow LLVM to target more recent hardware; by default it's just doing the "generic" baseline x64 instruction set, i.e. SSE, but no AVX / AVX2 etc.
    • This may need some discussion -- it's debatable whether we should just set the target-cpu flag to native and compile for the exact machine, or whether it's more representative to target something more generic (but supporting AVX2) like the x86-64-v3 target.
    • The same applied to the ARM builds, although I don't know offhand what a good representative target would be there.
  • Benchmarks for the normal (JIT) dotnet are more representative if we run the benchmark a few times in a loop.

On the main branch, I'm getting results that look like this currently:

  • test-rust: 775 ms
  • test-wasm: 1060 ms
  • test-dotnet: 900 ms

With the above applied, and after a 10 iterations or so for the dotnet JIT to settle:

  • test-rust: 542 ms
  • test-wasm: 925 ms
  • test-dotnet: 720 ms

If this looks like a useful contribution, let me know and I'll open a little PR to add the required configs.

[Proposal] Add some timings

I've decided to try & run those on my machine (mbp, 16" 2019, 2,4 GHz 8-Core Intel Core i9, 32gb), and I've got the following times (couple runs each):

# test-js
Raytracer running...
Ray tracing:
 - rendered image size: (1024x1024)
 - elapsed: 1805.3647939562798 ms
 
 
# test-wasm
 Raytracer running...
Ray tracing done:
 - rendered image size: (1024x1024)
 - elapsed: 970.5676089525223 ms

# test-web
Ray tracing done:
 - image rendered at 2x for super-sampled anti-aliasing
 - rendered image size: (1024x1024)
 - elapsed: 1067 ms
 
 # test-rust (lto = false)
 Raytracer running...
Ray tracing:
 - rendered image size: (1024x1024)
 - elapsed: 2143.8712720000003 ms
 
 # test-dotnet
 Raytracer running...
Ray tracing:
 - rendered image size: (1024x1024)
 - elapsed: 915.9425 ms

# test-native (had to change vars to osx-x64)
Raytracer running...
Ray tracing:
 - rendered image size: (1024x1024)
 - elapsed: 949.2975 ms

Seems kinda interesting that dotnet is on par with nodejs, and rust is kinda the slowest. I guess JIT does it work quite well

P.S. the license file is dated 2017 lol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.