Writing Fast, Memory-Efficient JavaScript
coding.smashingmagazine.com
Writing Fast, Memory-Efficient JavaScript
1–10 of 32 posts
Re: Writing Fast, Memory-Efficient JavaScript
#2Re: Writing Fast, Memory-Efficient JavaScript
#3...
This is horrible advice. There are plenty of things you want to delete, like references to elements when you don't need them anymore. A quick search of the Closure Library, jQuery, Backbone, Knockout, Angular.js, and ember.js found many uses of delete. Burn this article in a fire.
As for the supposed performance difference, let's see a jsperf on that.
Edit found one:
http://jsperf.com/delete-vs-undefined-vs-null/6
Delete is a little slower, certainly not enough to warrant the 'never' emphasis.
Re: Writing Fast, Memory-Efficient JavaScript
#4Re: Writing Fast, Memory-Efficient JavaScript
#5> Never use delete. Ever. ... This is horrible advice. There are plenty of things you want to delete, like references to elements when you don't need them anymore. A quick search of the Closure Library, jQuery, Backbone, Knockout, Angular.js, and ember.js found many uses of delete. Burn this article in a fire. As for the supposed performance difference, let's see a jsperf on that. Edit found one: http://jsperf.com/de…
Re: Writing Fast, Memory-Efficient JavaScript
#6> Never use delete. Ever. ... This is horrible advice. There are plenty of things you want to delete, like references to elements when you don't need them anymore. A quick search of the Closure Library, jQuery, Backbone, Knockout, Angular.js, and ember.js found many uses of delete. Burn this article in a fire. As for the supposed performance difference, let's see a jsperf on that. Edit found one: http://jsperf.com/de…
Certainly delete can be useful, but nulling a property has almost the same effect (apart from hasOwnProperty still returning true) - if you're looking at optimising at the level this article is talking about avoiding delete might well be sensible.
https://gist.github.com/4018282
Edit: I found a jsperf: http://jsperf.com/delete-vs-undefined-vs-null/6
Delete is a little slower, but setting null can be too, and setting undefined is the fastest for me in stable chrome.
Re: Writing Fast, Memory-Efficient JavaScript
#7> Never use delete. Ever. ... This is horrible advice. There are plenty of things you want to delete, like references to elements when you don't need them anymore. A quick search of the Closure Library, jQuery, Backbone, Knockout, Angular.js, and ember.js found many uses of delete. Burn this article in a fire. As for the supposed performance difference, let's see a jsperf on that. Edit found one: http://jsperf.com/de…
JS engines will zero-in on these 'hot' objects and attempt to optimize access to it, a task which will be helped if object doesn't change in structure over its life-time. 'delete' will trigger such a structure change.
By structure in context of JS, one should think inferrable structure like always setting .a to a Number then .b to a String after instantiating an object.
Re: Writing Fast, Memory-Efficient JavaScript
#8When discussing the efficiency of a language, especially an interpreted language, one must always take into account the peculiarities of the used VM. And be sure that today's optimisations may be "pessimizations" in the future (see the many Linux optimisations that are being removed in the last years).