From 9d7cbb6dcebf245b4507384c1299c687c6009bb3 Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Thu, 23 Jul 2020 14:49:46 +0800 Subject: [PATCH] Fix a perf issue caused by cloning schemaObj (#101) Co-authored-by: Ray Chen --- lib/helpers.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index cabca50..d832f55 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -25,7 +25,6 @@ 'use strict'; var _ = require('lodash'); -var cloneDeep = require('clone-deep'); var formatGenerators = require('./validation/format-generators'); var formatValidators = require('./validation/format-validators'); var customValidators = require('./validation/custom-zschema-validators'); @@ -471,10 +470,6 @@ module.exports.removeCirculars = function (obj) { * @returns {object} Object containing the errors and warnings of the validation */ module.exports.validateAgainstSchema = function (validator, schema, value, schemaPath, isResponse, options) { - // Clone the schema as z-schema alters the provided document (https://github.com/zaggino/z-schema/issues/160#issuecomment-214901835). - // Original lodash's deep clone was used but during memory profiling we've found lodash's deep clone takes a lot of CPU, according to this benchmark (https://github.com/ahmadnassri/benchmark-node-clone) and load testing, we've decided to replace lodash with this deep-clone library - schema = cloneDeep(schema); - var response = { errors: [], warnings: []