Noticed when we want to prevent input mutation we typically do the following:
geojson = JSON.parse(JSON.stringify(geojson));
However, most of the times we only need to clone the coordinates since that's the only thing that might be mutated.
Using coordinates.slice() vs. the JSON parse & stringify combo is about 8x times faster which can increase the performance of a "mutating" module/operation from 50,000 ops/sec to 400,000 ops/sec.
Expected Example
var clone = require('@turf/clone');
geojson = clone(geojson);
New module proposal
@turf/clone
Noticed when we want to prevent input mutation we typically do the following:
However, most of the times we only need to clone the coordinates since that's the only thing that might be mutated.
Using
coordinates.slice()
vs. the JSON parse & stringify combo is about 8x times faster which can increase the performance of a "mutating" module/operation from 50,000 ops/sec to 400,000 ops/sec.Expected Example
Ref: https://developers.google.com/web/updates/2017/06/object-rest-spread