TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

WebAssembly Raytracer

215 pointsby omn1over 7 years ago

14 comments

jandemover 7 years ago
The JS version is slow in Firefox because of a silly perf cliff, I filed a bug [0]. A quick fix for that improves the JS version from ~400 ms to ~180 ms for me locally. ~140 ms if I disable the Nightly-only GC poisoning.<p>edit: the JS code is a bit buggy: it does |if (Math.abs(dblDiscriminant) &lt; 0.01)| in the |intersection| function, but dblDiscriminant is a var set in the next loop! Math.abs(undefined) is something we can easily optimize in the JIT, but really the JS code is broken. Folding this in our JIT [1] improves this to &lt; 130 ms for me.<p>Please let us know if you run into JS perf problems, these bugs are usually easy to fix.<p>[0] <a href="https:&#x2F;&#x2F;bugzilla.mozilla.org&#x2F;show_bug.cgi?id=1425687" rel="nofollow">https:&#x2F;&#x2F;bugzilla.mozilla.org&#x2F;show_bug.cgi?id=1425687</a><p>[1] <a href="https:&#x2F;&#x2F;pastebin.com&#x2F;CzfP5vQj" rel="nofollow">https:&#x2F;&#x2F;pastebin.com&#x2F;CzfP5vQj</a>
评论 #15942078 未加载
IvanK_netover 7 years ago
I made a Path-tracer (photorealistic algorithm) in pure JS four years ago: <a href="http:&#x2F;&#x2F;renderer.ivank.net&#x2F;" rel="nofollow">http:&#x2F;&#x2F;renderer.ivank.net&#x2F;</a><p>It rendered this image: <a href="http:&#x2F;&#x2F;renderer.ivank.net&#x2F;balls.jpg" rel="nofollow">http:&#x2F;&#x2F;renderer.ivank.net&#x2F;balls.jpg</a> :)<p>I also made the &quot;full&quot; 3D game: <a href="http:&#x2F;&#x2F;powerstones.ivank.net&#x2F;" rel="nofollow">http:&#x2F;&#x2F;powerstones.ivank.net&#x2F;</a> (uses a GLSL shader).
评论 #15940517 未加载
评论 #15939800 未加载
评论 #15940129 未加载
Sharlinover 7 years ago
Firefox really benefits from WebASM: the time per frame is ~90ms on my machine whereas the JS version is close to 400ms or so.<p>On the other hand, on Chrome the WebASM performance is ~100ms and JS is just a tiny bit slower at around 120ms!
评论 #15939170 未加载
评论 #15939207 未加载
评论 #15940713 未加载
评论 #15940061 未加载
评论 #15939628 未加载
评论 #15939167 未加载
评论 #15939163 未加载
Francuteover 7 years ago
On my desktop:<p>Firefox: JavaScript ~372ms, asm ~121ms, WebAssembly ~91ms, Shader ~0.1ms<p>Chrome: JavaScript ~115ms, asm ~150ms, WebAssembly ~105ms, Shader ~0.1ms<p>Edge: JavaScript ~3340ms , asm ~(230-240)ms, WebAssembly ~(160-180)ms, Shader: Broken<p>IE11: Broken.<p>Interesting values.....
评论 #15947352 未加载
bufferoverflowover 7 years ago
Shader is broken on both android chrome and ff.<p>These work fine:<p><a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4tyXDR" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4tyXDR</a><p><a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4sXGDs" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4sXGDs</a><p><a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4dsGRn" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4dsGRn</a><p><a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4lB3D1" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;view&#x2F;4lB3D1</a>
评论 #15939639 未加载
zurnover 7 years ago
Interesting that there is a 1000x speed difference (0.1 vs 100 ms, in Chrome) between the shader and the JS&#x2F;WebASM versions even with just Intel integrated graphics.
评论 #15939397 未加载
评论 #15939398 未加载
评论 #15941769 未加载
TekMolover 7 years ago
Is there a resource to learn WebAssembly?<p>I don&#x27;t mean how to use a tool chain to compile higher level languages to WASM. I mean how to write the linear assembly bytecode as seen here on Wikipedia:<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;WebAssembly#Representation" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;WebAssembly#Representation</a>
评论 #15939322 未加载
评论 #15939261 未加载
k__over 7 years ago
the shader version is the fastest, but looks like modern art on my smartphone.<p>Like someone scribbled the colors over the circles instead of filling them.
评论 #15939399 未加载
评论 #15939307 未加载
z3t4over 7 years ago
When WASM only give&#x27;s a 10% increase in performance, is it really worth it ? While at the same time using &quot;hardware&quot; shaders gives 1000% increase in performance. If the goal of WASM is not performance, what is the reasoning behind it ? That you would be able to compile any!? program to be run in the browser !?
评论 #15949788 未加载
igraviousover 7 years ago
Wow, Chrome is able to run the Shader on my Intel integrated graphics on Wayland in Ubuntu 17.10<p>Colo(u)r me impressed.<p>I&#x27;m getting 0.1 versus 125 for WebAsm versus ASM.js&#x2F;JS of ~210 – kind of crazy that Chrome can run plain JS as fast as ASM.js (or is it?)<p>Firefox (57) can&#x27;t run Shader unless there&#x27;s some under the hood option I have to turn on …
评论 #15940054 未加载
radarsat1over 7 years ago
A little beside the point, but I <i>love</i> the real-time distribution visualisation with the boxplot.
评论 #15943068 未加载
based2over 7 years ago
a raytracer in JS: ~407.3 ms and in WASM: ~87.4 ms and in GLSL: ~0.17 ms<p><a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;7k4v5t&#x2F;a_raytracer_in_js_4073_ms_and_in_wasm_874_ms_and&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;programming&#x2F;comments&#x2F;7k4v5t&#x2F;a_raytr...</a>
评论 #15942108 未加载
singularity2001over 7 years ago
I had no idea ray tracers can be written with such concise and clean code. the results are amazing too. lesson learnt: JavaScript is extremely fast on chrome, 6 times slower than WASM in Firefox and GPU shaders are still faster by a factor of 1000!!
评论 #15943099 未加载
kowdermeisterover 7 years ago
Hmmm:<p>JavaScript 106.8<p>asm.js 140.0<p>WebAssembly 88.4<p>Shader 0.1<p>Just a Dell 13 inspiron laptop with latest Chrome 63.
评论 #15939370 未加载
评论 #15944237 未加载