Skip to content

Comment on The fastest object diff library in JavaScript

Comments

Nice one. Have you tried replacing the for loops with forEach? It might be even more performant.

In Javascript, forEach, map, reduce and other similar array methods are considerably slower than a regular for loop. You can see [0] and the linked questions for more technical details.

[0] https://stackoverflow.com/q/22155280/1470607

Function callbacks are definitely slower. You could probably shave another 10% by changing the array.push() calls to direct assignments: array[array.length] = value. Same with the nested array.map, changing to a for loop.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.