4 ms·
https://github.com/mrdoob/texgen.js/blob/564c6efb5b5647ad44d98205c93bf59dc513a85c/src/texgen.js#L29-L38 https://github.com/mrdoob/texgen.js/blob/564c6efb5b5647a
by akerl_ 12y ago
https://github.com/mrdoob/texgen.js/blob/564c6efb5b5647ad44d98205c93bf59dc513a85c/src/texgen.js#L29-L38 https://github.com/mrdoob/texgen.js/blob/564c6efb5b5647ad44d...
I'll admit to being a bit concerned about programming practices like this. I'm mostly inept at Javascript, but surely the language has better mechanisms for accomplishing the goal here.
- mrdoob2 12y agoI did it like this because I wanted to create the drawing loop as efficient as possible, without switches or conditionals. That method gets executed per pixel so the less logic the better. If someone knows a better way I'm all ears!
- bgtnhz 12y agoI fail to see the logic behind optimizing around conditionals when you are running in an interpreted language.
- mrdoob2 12y agoI instrumented the code and using conditionals resulted in 2x the generation time per loop. These loops are executed only once so the VM doesn't have a chance to optimise them.
- gavanwoolery 12y agoI've done similar in the past and can concur that it does have large performance benefits, at least in Chrome where I tested it.
- SixSigma 12y agoTesting beats imagination.
- flohofwoe 12y agoStating the obvious, but I'm pretty sure that there are no longer any purely interpreting JS engines around, it's all JIT or AOT compiled, so optimizing for a compilation scenario definitely makes sense.