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

Large extra-CPU usage and extra delay when validating, after upgrading from Ajv6 to Ajv8 #2542

Open
ezraf-wix opened this issue Apr 2, 2025 · 0 comments

Comments

@ezraf-wix
Copy link

ezraf-wix commented Apr 2, 2025

Hi everyone,

After upgrading Ajv from 6.12.13 Ajv 8.17.1, our system started to crash on validation. We were able to narrow down and isolate the issue, and it looks like Ajv8 is using a lot more CPU/memory than Ajv6 in this specific use case. We wish to have your opinion on it (it could also indicate a leak).

Here are the reproduction steps:

  • We started a virtual machine with "low" memory and cpu (16Gb, 2cpus, running Fedora)

  • We have a large schema (see schema.json) schema.json

  • We attached a piece of data to be validated (see data.json) data.json

  • We ran a simple script, that just registers the schema and performs 40.000 validations with the validation function (close to our use case):

const ajvInstance = new Ajv({strict: false})
ajvInstance.addSchema(schema, 'some-key')
const validate = ajvInstance.getSchema('some-key')
for (let i = 0; i < 40_000; i++) {
    validate(data)
}

Results:

  • When using Ajv6 it takes about 1 second
  • When using Ajv8 it takes about 5 seconds
  • When looking at the CPU and memory usage, we also see a large extra usage of the CPU (which seems to be causing the crash in production)
  • We also noticed it does not matter if the data we pass is valid or not (the sample attached is valid)

We are working on reducing our schemas, but still we think your opinion on this could be interesting, and it may indicate an issue.

Thank you in advance!

@ezraf-wix ezraf-wix changed the title Large extra-CPU usage and delay when upgrading from Ajv6 to Ajv8 Large extra-CPU usage and extra delay when validating, after upgrading from Ajv6 to Ajv8 Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant