senchalabs / philogl

A WebGL Framework for Data Visualization, Creative Coding and Game Development
http://senchalabs.github.com/philogl/
MIT License
806 stars 154 forks source link

Optimizing $.type() #1

Closed willmoffat closed 13 years ago

willmoffat commented 13 years ago

Hi,

I tried profiling scene.render() with 400 cubes. It looks like 20% of the time is spent inside $.type() This commit reduces it to 2%.

Not exhaustively tested, but it does pass the unit tests ;-)

Nice work on PhiloGL! --Will

philogb commented 13 years ago

Thanks a lot for your fix :)

type looks like a much faster implementation now, but it does rely on constructor which is a writable property in any object. The previous check was checking directly for the [[Class]] value. (More info here) I'm not sure though I should be that strict; I'll try profiling different approaches on jsperf. I'll get back when the fix is pushed, thanks a lot again :)

philogb commented 13 years ago

Thanks again for the report. This commit:

https://github.com/senchalabs/philogl/commit/e992b9ce70bc219e077e8face7ad3a5e95c08008

Increases $.type performance of about 30-50% and still has a robust check based on [[Class]]. You can compare the implementations here. I hope this makes it useful :)

Thanks!