Skip to content

[BUG][PYTHON] Import performance regression #19635

@bachorp

Description

@bachorp

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 ee0686e) 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

#18144 also concerns import performance but points at __init__.py.

Suggest a fix

Reinstate some sort of lazy importing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions