OpenAPITools / OpenAPITools/openapi-generator
[BUG][PYTHON] Import performance regression
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Using a generated python client can be very costly with regard to import performance. For the (quite large) API-spec linked below, importing the generated client module takes ~8s and ~500MB of memory on my M1 macbook.
This issue could not be observed for versions before v7.0.0 (I tested v6.0.0 in particular) and likely is related to the switch to the pydantic generator in v7.0.0 which does not perform lazy importing (previously introduced in https://github.com/OpenAPITools/openapi-generator/commit/ee0686e13f58f1c7029f76bef5c87d547b68f7d5) such that the (potentially quite large) module will be loaded in its entirety.
openapi-generator version
v7.8.0. Suspected to be a regression introduced in v7.0.0. Not an issue in v6.0.0.
OpenAPI declaration file content or url
kubernetes-release-1.31.swagger.json
Generation Details
openapi-generator-cli generate -i kubernetes-release-1.31.swagger.json -g python --skip-validate-spec
Steps to reproduce
import openapi_client
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/18144 also concerns import performance but points at __init__.py.
Suggest a fix
Reinstate some sort of lazy importing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the regression with kubernetes-release-1.31.swagger.json, the shown generate command, and import openapi_client. Compare v6.0.0 with v7.0.0 behavior, then inspect the generated __init__.py and issue #18144. Done means the large generated client imports with substantially lower time and memory while retaining the expected client API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api, performance, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100