cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
469 stars 89 forks source link

Added cache for base Spec object properties #168

Open Aribros opened 2 years ago

Aribros commented 2 years ago

Made little performance improvement by temporary caching some already resolved references.

NickSdot commented 1 year ago

@Aribros, thank you for that! I've been using your PR when working with a large spec. It makes things a whole order of magnitude faster. Resolving all the refs on my spec was impossible before applying this.

However, there is a pretty big downside, which only becomes apparent when working with larger specs.

The memory usage in my case ended up being ~330M. Also, the resulting size of the object - which I serialise and cache in the file system - is ~210M. I've tried to unset each context after resolving, but the size of the spec doesn't allow it in an acceptable time - or it just fails. It's just too many nested schemas in my case.

So I ended up combining your solution with a static cache property.

Result: Memory usage is down to ~70M. The resulting serialised object size is down to only ~20M. Also, it runs in under one second.

Probably something to consider before this potentially gets merged. Anyway, your PR pointed me in the right direction. Thanks again.