> > My understanding is that Google Closure Compiler, which does the > optimization, relies on us using foo.prototype.bar with JSDoc. For some > reason they have not chosen to output structures. If you are certain it > is more efficient, you should see if has been suggested on their issues > list. I am hopeful we do not have to get into the JS optimization game. > I hope we can rely on Google.
I tried unsuccessfully to find discussions on assigning the prototype directly in GCC. I don’t know that I’m right. It’s something that might be worth exploring at some later point. >> >>> For just one occurrence, you probably won't notice, But after we >>> initialize 100 or 1000 properties to "" you might notice. >> >> No. I don’t buy this. You’d need tens of millions of initializations to >> have a measurable effect. If there are that many class initializations, >> it will still not be noticeable because there will be so many bigger >> performance bottlenecks, that it would still not be noticeable. Again, >> this is just class initialization, so there’s no cost for object >> instantiations. The solution of adding additional model classes is worse >> than the problem. > > In another thread, you pointed out that MaterialIconType added 77K to the > code. Don't all of these assignments add up to the same thing? Yes and no. There’s two issues: Runtime performance, and minified code size. In terms of runtime performance, initializing class values should not have a negative effect. They would (slightly) add to code size, but having to load two different models in your app would add even more. Static constants are particularly big in terms of how they are declared because the text values are not minimized at all. I’m not suggesting to willy-nilly add initialization to every variable, but if there’s a logical reason to initialize specific ones, I don’t see that as a problem. >> >> Additionally, initializing variables might actually *help* performance in >> javascript because it allows the runtime to infer the type.[1] >> >> [1]https://wildlyinaccurate.com/javascript-performance-variable-initializa >> <https://wildlyinaccurate.com/javascript-performance-variable-initializa> >> tion/ >> <https://wildlyinaccurate.com/javascript-performance-variable-initializati >> <https://wildlyinaccurate.com/javascript-performance-variable-initializati> >> on/> > > In this article it tests assigning a default value of null vs a default > value of a type. I am proposing not assigning any default value at all. > Then on the first actual assignment, the runtime will infer the correct > type. Maybe. I thought the point was that initializing it when it’s specifically declared helps, but you are likely right. Either way, here’s an interesting article on Javascript optimization which has some general tips: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers Harbs