ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.45k stars 86 forks source link

perf: zap library leaking into binaries #1242

Open ayuhito opened 6 months ago

ayuhito commented 6 months ago

What version of ogen are you using?

v1.1.0

Can this issue be reproduced with the latest version?

Yes

What did you do?

This is an extremely minor bug, but it's worth noting down if anyone wants to look into it.

I ran gsa on my API binaries when I noticed that zap was being imported into my project. I think it's leaking into the API binaries via the ogen/jsonschema library (not sure) and adding ~40kb to all binaries if you do not use zap.

https://github.com/ogen-go/ogen/blob/e147d5e6d100f056023a7ac3df012928e433bc04/jsonschema/external.go#L57

It's not high priority, but I think any optimizations like this will help in resource constrained environments.

What did you expect to see?

zap should not be present in the library.

What did you see instead?

image

tdakkota commented 6 months ago

It seems that generated code imports github.com/ogen-go/ogen/middleware https://github.com/ogen-go/ogen/blob/d1f597e7f71c980c19a7e4f221c1320ae00bcf74/examples/ex_petstore/oas_middleware_gen.go#L6

github.com/ogen-go/ogen/middleware imports github.com/ogen-go/ogen/openapi https://github.com/ogen-go/ogen/blob/d1f597e7f71c980c19a7e4f221c1320ae00bcf74/middleware/middleware.go#L8

github.com/ogen-go/ogen/openapi imports github.com/ogen-go/ogen/jsonschema https://github.com/ogen-go/ogen/blob/d1f597e7f71c980c19a7e4f221c1320ae00bcf74/openapi/api.go#L6

Not sure if we can fix it without breaking v1 compatibility.