4 ms·
I think the better take away might be: avoid changing the structure of 'hot' objects at runtime. JS engines will zero-in on these 'hot' objects and attempt to
by donpark 14y ago
I think the better take away might be: avoid changing the structure of 'hot' objects at runtime.
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.
- btipling 14y agoAgreed. But I'd worry about something like this once I notice I want to improve performance. In the book Beautiful Code one of the authors urged programmers to write beautiful code first then optimize when needed later. It's easier to optimize beautiful code than it is to beautify optimized code. Using delete is a very readable statement of intent.