-
-
Notifications
You must be signed in to change notification settings - Fork 116
Description
Context:
I am experiencing a significant performance regression in the validate() method of simpl-schema when validating large schemas (5000+ properties). This issue appeared between versions 1.12.2 and 1.12.3 and persists in the latest version (3.4.6).
Impact:
On my laptop, the validation time increased from ~50ms (v1.12.2) to >3 seconds (v1.12.3+).
This issue affects all subsequent versions, including 3.4.6.
Our use case involves validating thousands of documents in batch jobs, making this regression critical.
Steps to Reproduce:
Run the following script with simpl-schema versions 1.12.2 and 1.12.3+ to observe the performance difference:
const SimpleSchema = require('simpl-schema').default;
const cleanOptions = {
filter: false,
autoConvert: false,
removeEmptyStrings: false,
trimStrings: false,
removeNullsFromArrays: false,
};
// Build a large schema and matching object
const schema = {};
const object = {};
for (let i = 0; i < 5000; i++) {
schema[`prop${i}`] = { type: String, label: `Prop ${i}` };
object[`prop${i}`] = `Value ${i}`;
}
// Prepare schema and validation context
const simpleSchema = new SimpleSchema(schema, {
requiredByDefault: false,
clean: cleanOptions,
});
const valContext = simpleSchema.newContext();
// Validate and measure duration
const start = new Date().getTime();
const isValid = valContext.validate(object);
const end = new Date().getTime();
console.log(`Duration: ${end - start}ms (isValid: ${isValid})`);
Expected Behavior:
Validation time should remain consistent with v1.12.2 (~50ms for 5000 properties).
Environment:
Node.js: v22.18.0
OS: Ubuntu 22/04 LTS
simpl-schema versions tested: 1.12.2, 1.12.3, 3.4.6