juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.46k stars 191 forks source link

Utoipa-swagger-ui seems to be linking in Swagger UI to the build by default #1051

Open kanpov opened 1 month ago

kanpov commented 1 month ago

Version of utoipa-swagger-ui: 7.1.1-beta.0

Vendored feature is not enabled, including the package increases the release binary by ~12MB. Is this intended behavior?

juhaku commented 1 month ago

I guess it would be reasonable to investigate what gets included to the release binary. Yet no matter of using vendored feature flag or not the Swagger UI files will anyways be included to the final binary. Vendored will just use prepackaged Swagger UI. Without vendoring the Swagger UI will be downloaded build time and embedded to the binary.

It just might be that the Swagger UI is that big. It actually contains a bunch of files. If want something more lightweight you should try scalar or rapidoc or redoc (redoc does not allow executing those paths from the UI).

kanpov commented 1 month ago

I think it'd be reasonable to add a PSA about binary size to the doc page of utoipa-swagger-ui. I might give you exact figures on the binary size increase (but the ~12-13MB increase approximation is pretty accurate for my own project) later with an empty project.

JMLX42 commented 4 weeks ago

Uncompressed, Swagger UI is ~17MB. Compressed, it's ~4.5MB. So I guess something like UPX should do the job on the final binary.

But UPX does not work on my specific binary...

Update: my local build was linked with mold. Without mold, upx runs as expected and shrinks the binary by up to 75%. The compression is most likely very efficient on the Swagger UI assets.

juhaku commented 3 weeks ago

Sure, we could add heads up notification to README.md of utoipa-swagger-ui crate to inform potential users that Swagger UI needs some space.

JMLX42 commented 5 days ago

Sure, we could add heads up notification to README.md of utoipa-swagger-ui crate to inform potential users that Swagger UI needs some space.

Or we could compress the Swagger UI assets in the binary. There are some crates to do that.