Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z-Schema deep cloning #213

Open
littlejedi opened this issue Nov 9, 2019 · 1 comment
Open

Z-Schema deep cloning #213

littlejedi opened this issue Nov 9, 2019 · 1 comment

Comments

@littlejedi
Copy link

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

@whitlockjc
Copy link
Member

The reason is z-schema modifies the input document to keep track of what it has processed and what it hasn't: zaggino/z-schema#160 (comment) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants