Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Hi!
Today I was doing some dependency updates for my fastify apps, when I noticed a bigger InitDuration for my AWS Lambdas.
To have an idea my await app.ready() call went from approx. 400ms to approx. 1600ms (on AWS Lambda this went up to 18000ms and also caused some timeouts) by updating from fastify v4.1.0 to v4.2.0.
After some testing I'm assuming that probably fast-json-stringify is causing this because of this commit.
I'm not so familiar with the internals, but this simple test, helped me to compare a bit more.
For example by wrapping the refFinder(schema.$ref, location)
call here: https://github.com/fastify/fast-json-stringify/blob/v4.2.0/index.js#L108 in v4.2.0
i.e. like this:
const d = Date.now()
location = refFinder(schema.$ref, location)
console.log('refFinder', Date.now() - d)
I basically get always 0 ms for the time measurements for all invocations, but compared to the newer ajvInstance.getSchema(schemaRef)
call here: https://github.com/fastify/fast-json-stringify/blob/v5.0.0/index.js#L64 in v5.0.0
i.e. like this:
const d = Date.now()
ajvSchema = ajvInstance.getSchema(schemaRef)
console.log('ajvInstance.getSchema', Date.now() - d)
I'm now getting 2-20ms for the time measurements for the different invocations.
Like said, I'm not familiar with these internals, but I assume ajv.getSchema is getting the fastify.ready() call much slower.
I'm sorry for my unprofessional reproduction steps, but I hope this information may help to understand the issue.