php-openapi icon indicating copy to clipboard operation
php-openapi copied to clipboard

Added cache for base Spec object properties

Open Aribros opened this issue 1 year ago • 1 comments

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

Aribros avatar Sep 27 '22 13:09 Aribros

@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.

NickSdot avatar Aug 16 '23 15:08 NickSdot