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

Overview

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 Rust
  • install wasm-pack
  • run one of the performance tests:
    • npm run test-js (F# to JS, Fable 3.x, Node.js)
    • npm run test-web (F# to Rust to webasm, Browser, localhost:8080)
    • npm run test-wasm (F# to Rust to webasm, Node.js)
    • npm run test-rust (F# to Rust, running native)
    • npm run test-dotnet (F# running on .NET 6.0)
Comments
  • [Proposal] Add some timings

    [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

    opened by delneg 10
  • [Proposal] Rust configuration for improved performance

    [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.

    opened by mike-barber 6
  • Improve build configuration for NativeAOT

    Improve build configuration for NativeAOT

    This produce EXE of 2.5Mb after strip executable from debug symbols. Without strip it's 9Mb size, still notably smaller then with reflection. Execution speed about same as .NET, but on Linux perception that startup time is faster even if I add --no-build.

    Slap <IlcOptimizationPreference>Size</IlcOptimizationPreference> and you get NativeAOT version run faster by ~10%. It will shave 150ms from 1312ms to 1168ms (-10%) (I do have very old laptop)

    This is just to make sure that NativeAOT is compiling in your repo without much friction.

    opened by kant2002 4
  • Add gif image to readme (wow-effect)

    Add gif image to readme (wow-effect)

    A lot of people tend to like visual demostration, so that's that (before merging will need to adjust url - change the repo name & branch name) You can view it working t https://github.com/delneg/fable-raytracer/tree/feat/readme-img

    opened by delneg 3
  • Use Fable 4 as dotnet tool

    Use Fable 4 as dotnet tool

    This downloads Fable as a dotnet tool instead of using a local build to make it easier for users.

    @ncave It seems that the npm run test-rust target can only be run after npm run test-web (or test-wasm). Apparently it need the files from fable-library-rust in fable_modules in the repo root, but the other files must be in out dir to avoid file name conflicts. Wasn't sure how to fix that.

    opened by alfonsogarciacaro 2
  • Additional npm run target with `target-cpu=native` for Rust

    Additional npm run target with `target-cpu=native` for Rust

    This small constribution adds a new run script: npm run test-rust-target-cpu. It does the same as npm run test-rust, but allows Rust to target the current host machine's CPU. I've updated README.md too. This relates to #6.

    It was a bit of a fiddle to get it working on Windows too, since the usual approach of setting an environment variable for RUSTFLAGS isn't quite as easy. Luckily Cargo has a --config argument we can use to achieve the same objective.

    opened by mike-barber 0
  • [Feat] Mention iOS version

    [Feat] Mention iOS version

    Hello again, I've ported it to iOS just for fun: https://github.com/delneg/fable-raytracer-ios-net6

    So now it's F# -> Rust -> static library -> F# DLL Import -> iOS Most interesting bits are in https://github.com/delneg/fable-raytracer-ios-net6/blob/master/FableRustRaytracerNet6iOS/AppDelegate.fs

    opened by delneg 0
  • Fable Python support

    Fable Python support

    • Yes, it's slow. But added for completeness (and to show that Python can be awfully slow for tight loops like this).

    PS: Needs a new Fable release to compile correctly, i.e 4.0.0-theta-019

    ❯ python main.py
    Raytracer running...
    Ray tracing done:
     - rendered image size: (1024x1024)
     - elapsed: 94554.139777 ms
    
    opened by dbrattli 1
Owner
RIP John Conway, you blazed the trail!
null
Rust-to-C++ transpiler

cxx A Rust-to-CXX compiler, written in 65 lines of Rust. What is this? I had an idea that should not work but it works. Usage $ cat hello.rs fn main()

Sasha Pourcelot 4 Mar 17, 2023
The first cesil transpiler/compiler in 50 years!

CesilC CESIL, or Computer Education in Schools Instruction Language, is a programming language designed to introduce pupils in British secondary schoo

null 5 Aug 6, 2022
Ray Tracing: The Next Week implementation in Rust

rttnw Ray Tracing: The Next Week implementation in Rust How to run Install Rust: Link here. Run project git clone https://github.com/luliic2/rttnw cd

null 20 Apr 26, 2022
Source code from Atlas, our 64k demo presented at Revision 2019 with Macau Exports

Atlas source code dump This is a dump of the source code for the engine, graphics tool and player for Atlas, our 64k demo released with Macau Exports

Monad 65 Jan 2, 2023
CSGO demo parser for Python

CSGO demo parser for Python Demo parser for Counter-Strike: Global Offensive. Parser is used to collect data from replay files (".dem" files). The goa

null 11 Dec 7, 2022
Small, clean, easy to use programming language

Thistle A modern, simplistic multi-paradigm language supporting object-oriented features Hello World! import IO object Main def main(): unit

null 7 Apr 13, 2022
A small, nutty dependently typed language.

pistachio I want to learn about how theorem provers and dependently typed languages are implemented. This is a little repo for experimentation. elabor

McCoy R. Becker 8 Nov 11, 2022
A repository for showcasing my knowledge of the Rust programming language, and continuing to learn the language.

Learning Rust I started learning the Rust programming language before using GitHub, but increased its usage afterwards. I have found it to be a fast a

Sean P. Myrick V19.1.7.2 2 Nov 8, 2022
:crab: Small exercises to get you used to reading and writing Rust code!

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

The Rust Programming Language 33.1k Jan 2, 2023
Fegeya Elitebuild, small, powerful build system. Written in Rust.

Fegeya Elitebuild Small, powerful, work-in-progress build system. Written in Rust. Features: No functions (all are built-ins) All variables are global

Ferhat Geçdoğan 25 Nov 9, 2022
This project contains small exercises to get you used to reading and writing Rust code

rustlings ?? ❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used to reading and writing Rust code. This inclu

Cynthia Tran 1 May 24, 2022
Small programs written in Rust. Warm up for the upcoming Selenium Manager

Rust Examples This repository contains several example programs written in Rust. Selenium Manager These examples are used as warm up for the upcoming

Boni García 5 Dec 30, 2022
A small in-memory key value database for rust

SmollDB Small in-memory key value database for rust This is a small in-memory key-value database, which can be easly backed up in a file or stream and

null 13 Dec 15, 2022
RcLite: small, fast, and memory-friendly reference counting for Rust

RcLite: small, fast, and memory-friendly reference counting RcLite is a lightweight reference-counting solution for Rust that serves as an alternative

Khashayar Fereidani 147 Apr 14, 2023
Nyah is a programming language runtime built for high performance and comes with a scripting language.

?? Nyah ( Unfinished ) Nyah is a programming language runtime built for high performance and comes with a scripting language. ??️ Status Nyah is not c

Stacker 3 Mar 6, 2022
Mewl, program in cats' language; A just-for-fun language

Mewl The programming language of cats' with the taste of lisp ?? What,Why? Well, 2 years ago in 2020, I created a esoteric programming language called

Palash Bauri 14 Oct 23, 2022
lelang programming language is a toy language based on LLVM.

lelang leang是一门使用Rust编写,基于LLVM(inkwell llvm safe binding library)实现的编程语言,起初作为课程实验项目,现在为个人长期维护项目。 Target Features 支持8至64位的整形类型和32/64位浮点 基本的函数定义,调用,声明外部

Aya0wind 5 Sep 4, 2022
The Devils' Programming Language (Quantum Programming Language)

devilslang has roots in Scheme and ML-flavored languages: it's the culmination of everything I expect from a programming language, including the desire to keep everything as minimalistic and concise as possible. At its core, devilslang is lambda-calculus with pattern-matching, structural types, fiber-based concurrency, and syntactic extension.

Devils' Language 2 Aug 26, 2022
A small utility for modifying ELF shared library loading order.

elfpromote A small utility for modifying ELF shared library loading order. Usage $ cargo install elfpromote $ ldd blueboat_server linux-vdso.s

Heyang Zhou 5 Jul 21, 2022