Closed P0lip closed 4 years ago
@philsturgeon @XVincentX any of you eager to review this one?
Can you do one example of a clone deep that is not required for our usages? I can't really think of one at the moment
Technically we're doing deep cloning here - we copy each object we visit before mutating it. The PR title as well as the description might be a bit slightly misleading. What we're doing here is performing a shallow copy of the object we visit. This has a number of benefits:
If the sole aim is to avoid clone deep, maybe we can use lodash.clone? That'd make me feel more comfortable instead of our own implementation.
I'm strongly against using any of lodash clones in this particular case. They are great and take care of different object types such as Date, Maps, Sets, etc., but we do not need to clone any of them.
@philsturgeon could you merge this one assuming you are fine with the changes?
:tada: This PR is included in version 3.0.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
cloneDeep is fairly expensive in certain cases and does not need to be implement in the way it is now, since we visit each object, and hence can simply shallow copy it before modyfing. Using shallow copy of each object before visiting it significantly (by around 25-35%) improves the perfomance of
@stoplight/http-spec#transformOas3Operations
. Tested against various specs, such as Stripe, Whatsapp, etc. Obviously, the results will vary - if a given document does not have schemas or has a handful of small schemas, the difference is likely to be less notable.