sway icon indicating copy to clipboard operation
sway copied to clipboard

Z-Schema deep cloning

Open littlejedi opened this issue 5 years ago • 1 comments

Hi there, We've been using Sway in our project, and during memory profiling, we've found the following line that's taking a lot of time (in lib/helper.js)

module.exports.validateAgainstSchema = function (validator, schema, value, schemaPath, isResponse, options) { schema = _.cloneDeep(schema); // Clone the schema as z-schema alters the provided document

I'm curious as to why z-schema alters the provided schema, could you provide an example where schema is modified? We are looking for a way to either improve deep clone performance or get rid of it

Thank you very much

littlejedi avatar Nov 09 '19 04:11 littlejedi

The reason is z-schema modifies the input document to keep track of what it has processed and what it hasn't: https://github.com/zaggino/z-schema/issues/160#issuecomment-214901835 Not only does this cause problems as mentioned in the referenced issue, but I don't think it's right for anything sway does to modify inputs it's provided. Once I knew that z-schema modified the input document, I started cloning the input so that the original input was not modified in any form or fashion.

whitlockjc avatar Nov 11 '19 17:11 whitlockjc