Skip to content

Change from v6 to v7: schema object itself used as a key for compiled schema function, not serialization #1413

@supersolid-AitorDB

Description

@supersolid-AitorDB

Hi! I have noticed that after updating from v6 to v7, if you pass the same schema but with a different reference there's an increment on the memory used leading this to a potential memory leak. I understand that this is not the recommended way to use the library, but because there's not explicit mention about this change (that I have found) and I think other people could have not noticed this, adding a warning to the changelog or reviewing this if it was not an intentional change would be helpful.

Here is an example where the difference in memory can be observed between 6.12.6 and 7.0.2

const Ajv = require('ajv').default
const ajvInstance = new Ajv()

const sleep = (time) => new Promise((resolve) => setTimeout(() => resolve(), time))

async function start () {
	while (true) {
		const schema = {
			type: 'object',
			properties: {
				test: {type: 'number'}
			}	
		}
		
		const data = {
			test: Math.random()
		}

		ajvInstance.validate(schema, data)
		await sleep(10)
	}
}

start()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions