open-api: Initialize slow with large specs
I’m loading a very large schema. It has about 500 paths, and about 1200 external references. I’m calling initialize
like so:
openapi.initialize({
apiDoc: this.apiDoc,
app,
enableObjectCoercion: true,
externalSchemas: this.externalSchemas,
paths: this.paths,
promiseMode: true,
validateApiDoc: true
});
apiDoc
and externalSchemas
are loaded from yaml files and sent to initialize
as objects. One microservice uses about 34 paths. However it takes a consistent 26 seconds for initialize to finish.
Is there any way to speed this up on my end, in the library, etc?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 19 (12 by maintainers)
Sorry to revive an old issue thread - I’ll probably be opening a dedicated one for this once I’ve dug enough to come up with some concrete suggestions on how to improve, but I thought it’d be worth leaving here in case anyone sees in the meantime.
I’ve found that a lot of the startup time I see in large specs is specifically coupling high numbers of paths, with high numbers of components, and using response validation middleware.
I wrote a small sample project to profile memory utilization off the back of some issues we’ve been having with our larger services, and specifically combining all three of those things makes things massively slower to startup, and eats a huge chunk of memory (some sample findings in the README see heap usage grow by 5-10x depending on number of paths/components.)
So TL/DR if you’re seeing slow startup times for very large specs and currently use response validation middleware, probably worth considering disabling response validation middleware entirely in prod using
'x-express-openapi-disable-response-validation-middleware': true
.