Does Deleting Object Keys Still Kill Performance? I Tested It
I tested the old advice that deleting object keys wrecks lookup speed, on Node 22, with 100,000 entries A plain object stayed faster than a Map before, during and after five delete-and-rebuild cycles Map lookups ran 30 to 50 percent slower than object lookups across all three test phases The dictionary-mode slowdown the old advice warns about never showed up in any test phase Years of JavaScript…
A recent test comparing plain objects and Maps for key deletion performance on Node 22 revealed that the old advice against deleting keys from objects has no basis in current JavaScript engine behavior. The test involved a 100,000 entry plain object and a Map, with 200,000 random lookups performed each of the three phases. Phase one showed the plain object performing faster than the Map.
Phase two, after deleting half the keys, saw both structures get slightly faster, with the object maintaining its lead. The crucial phase three, which tested the "dictionary-mode" slowdown claim by deleting the same keys five times and adding them back, demonstrated that the object actually became faster during this churn, while the Map slowed to 15.8 milliseconds from 16.2 milliseconds.
The results contradicted the well-established advice, showing that the slowdown only appeared in the old recommendation, not in actual engine behavior.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to