slact / nchan.js

NPM package for the Javasript client for Nchan
Other
91 stars 25 forks source link

Avoid using delete which can cause the backing JIT class to mutate #17

Closed Xon closed 6 years ago

Xon commented 6 years ago

Mostly minor, as the flags aren't mutated that often.

slact commented 6 years ago

Can you link me to a reference for this optimization?

Xon commented 6 years ago

In a loop, there is a noticeable performance difference; https://jsperf.com/delete-vs-undefined-vs-null/16

A V8 developer mentions using delete will likely be slow; https://stackoverflow.com/questions/43594092/slow-delete-of-object-properties-in-js-in-v8 https://groups.google.com/forum/#!topic/v8-users/zE4cOHBkAnY

slact commented 6 years ago

Well, none of these deletes are in any loops, so this won't affect performance. But you're right, it does appear to be best practice to avoid delete if possible. Merge approved.