frenchtoast747 / webgl-obj-loader

A simple OBJ model loader to help facilitate the learning of WebGL.
http://frenchtoast747.github.io/webgl-obj-loader/
MIT License
281 stars 59 forks source link

Micro opts #8

Closed nickdesaulniers closed 9 years ago

nickdesaulniers commented 9 years ago

this depends on #7 . Not strictly necessary. No performance numbers to compare before/after. Should be tested with large working example, but looked good to me.

frenchtoast747 commented 9 years ago

I figured you were right about the new strings being made, but I decided to run some benchmarks on this anyway and the regex is actually slower. I ran Mesh() with a 100MB OBJ of a cube with 9 million faces and the suzanne.obj in development/models directory. The following is results:

Chrome startswith

Chrome Regex

Firefox startsWith

Firefox Regex

And with some of the other optimizations you've contributed:

Chrome

Firefox

frenchtoast747 commented 9 years ago

After playing around with your regex changes some more, it wasn't the regex that was slowing it down, it was the pre-indexing in the face section. The only thing I can think of is that a bunch of cache misses are occurring. I've added the regex back in as it still had a slight increase in speed: 556f0b5a.