3 ms·
Do you think adding type annotations or using typed js (typescript/flow), the optimisations could be improved? Since the types are providing more metadata about
by tejinderss 9y ago
Do you think adding type annotations or using typed js (typescript/flow), the optimisations could be improved? Since the types are providing more metadata about the code?
- jcranmer 9y agoNo (with an asterisk). The state-of-the-art for JS optimization already computes shape information (roughly equivalent to typing) and feeds that into optimizations. The asterisk comes from the costs of having multiple shapes for a given variable. V8 (to my recollection, it could very well be out of date) generally has a performance cliff between monomorphic and polymorphic functions: if the added strictures of typechecking is giving you monomorphic functions, it could see a performance improvement. Other JITs (again, to my recollection) are generally happier to have polymorphic functions where the degree of divergence is still small (say, two or three shapes), although having 1000 shapes is going to be unhappy for everybody. Note that this discussion is effectively microoptimization-level discussion: don't rearchitect your code to enforce monomorphism at the expense of clarity unless you have profiling evidence that the performance is necessary.