4 ms·
Scala.js Ray Tracer
- adamlj 13y agoI find it interesting to compare this compiled JS to the tiny recursive Ray Tracer previously posted here on HN [0]. This Scala->JS compilation is 214k characters while the tiny Ray Tracer is at <1k characters. It should be noted that the tiny Ray Tracer is heavily optimized and minified. [0] http://www.gabrielgambetta.com/tiny_raytracer.html http://www.gabrielgambetta.com/tiny_raytracer.html
- virtualwhys 13y agoScalaJS is still in its infancy, I wouldn't expect miracles at this point, particularly in terms of generated JS file size. Note the _experimental_ disclaimer in ScalaJS' home page: http://www.scala-js.org http://www.scala-js.org Assume optimizations will come with time, for now it's pretty cool that one can work in a more or less completely type safe environment on both client and server with Scala. p.s. muddling along with Coffeescript + GruntJS for the time being, but look forward to working in pure Scala once the library stabilizes.
- sixbrx 13y agoYeah this is a great effort that will have a really big upside for developers like me using Play! framework. It means I can define my transfer types in Scala and share them between client and server in a typesafe way. Currently that takes lots of testing to keep the javascript side honest in what it's sending.
- bad_user 13y agoThe source-code linked is only 279 lines of Scala code, including blanks and comments and the code is very readable [1]. However, it is using Scala's standard library, which is somewhere at 16.5 MB - 18.5 MB, depending on version. That the minified code is 209 KB (50 KB gzipped), I find that awesome, as it means that the compression / tree shaking done is pretty aggressive, much better than what people can do by hand. Under the hood Scala.js does optimizations of its own, before passing the result to Google's Closure compiler in advanced mode. https://github.com/lihaoyi/workbench-example-app/blob/ray-tracer/src/main/scala/example/ScalaJSExample.scala https://github.com/lihaoyi/workbench-example-app/blob/ray-tr...
- Flow 13y agoI ran this in Chrome, Safari 7 and Firefox. Firefox was the slowest of them all by quite some margin. I guess asm.js specific code enables some drastic speedups with less effort from the JIT's point of view. Too bad this code did not utilize asm.js.
- camus2 13y ago> Too bad this code did not utilize asm.js. The goal of asm.js is to efficiently compile C/C++ into JavaScript using Enscriptem,it's not meant to be written by hand.
- kaoD 13y agoI doubt the Scala to JavaScript transpiling is done by hand.
- bad_user 13y agoCompiling a high-level level like Scala to asm.js does not make sense, as asm.js is meant for lower level languages (e.g. C++), not managed languages, although it might be in the future ... http://asmjs.org/faq.html http://asmjs.org/faq.html
- lihaoyi 13y agoI totally transcribed it by hand. The transcribed sources (http://lihaoyi.github.io/workbench-example-app/raytracer-opt.js http://lihaoyi.github.io/workbench-example-app/raytracer-opt...) are completely readable
- cromwellian 13y agoScala is a garbage collected language like Java, not really a good target for asm.js.
- pjmlp 13y agoI fail to see why. It is only a matter how good the GC would be.
- lihaoyi 13y agoHere's a high resolution pre-computed verison, in case anyone wants to see it but doesn't want to wait for it to render https://www.dropbox.com/s/pmg84wj0eufb3ur/Screenshot%202014-04-04%2001.24.26.png https://www.dropbox.com/s/pmg84wj0eufb3ur/Screenshot%202014-...
- imdhmd 13y agoyou might like to add your benchmark to this: https://github.com/kidoman/rays https://github.com/kidoman/rays
- deleted 13y ago[deleted]