Skip to content

Import cost: load hwpx.tools submodules on demand, defer importlib.metadata in ingest #386

Description

@airmang

Follow-up to #384. Once `import hwpx` stops loading `hwpx.tools` (separate PR, 117 → 97 modules), two smaller costs remain:

  1. First save loads every tool module. `to_bytes()` needs `hwpx.tools.package_validator`, but `hwpx/tools/init.py` eagerly imports all 12 tool modules (exporter, document viewer, layout preview, doc_diff, mail_merge, ...). That is about 9 ms on the first save. Resolving the package's names on first access (static imports inside a module `getattr`; `from hwpx.tools import X` and `all` must keep working) would let the save path load only the validator.
  2. `hwpx.ingest.hwpx_converter` imports `importlib.metadata` at module level, about 5 ms, reached eagerly through the stable `HwpxMarkdownConverter` name. Moving it into the function that uses it should be enough.

`hwpx.oxml` is about half of the remaining import time; it is needed by `HwpxDocument` and is out of scope here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions