scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.4k stars 225 forks source link

Performance Improvment: Only import required function / file of swagger-ui-dist #352

Closed J12934 closed 1 year ago

J12934 commented 1 year ago

This PR updates the import of swagger-ui-dist to only load the individual file used to get the path for the static assets, not the code of the static assets themself. Before the entire dist lib was loaded which contains the entire code, a huge bundle.

I've noticed that in the project I'm working on (https://github.com/juice-shop/juice-shop/) the server takes about 150ms on startup loading the swagger-ui-dist packge.

Screenshot 2023-06-24 at 22 07 14

Chaning his import drastically reduces the amount of code which needs to be loaded on the server side. For us this means that swagger-ui becomes fast enough to be nearly unmeasurable, improving our total cpu load on start and total server start time by ~10% (~1.2s -> ~1.1s)

I've check briefly, from what I saw this should also work nicely with swagger-ui-dist v5.

Thank you for all the work you do here, much appreciated 🙌

J12934 commented 1 year ago

possibly related to #288