Skip to content

Optimize analyze performance.#249

Merged
chinazhangchao merged 10 commits into
mainfrom
chao/perf
Apr 9, 2026
Merged

Optimize analyze performance.#249
chinazhangchao merged 10 commits into
mainfrom
chao/perf

Conversation

@chinazhangchao

@chinazhangchao chinazhangchao commented Apr 7, 2026

Copy link
Copy Markdown
Contributor
image
  1. pattern/utils.py — make_hashable fast-path for sequences of simple types (avoids 57M unnecessary recursive calls)
  2. analyze/core/runtime_checker_query.py — Replaced pandas .apply(make_hashable) with direct list comprehension over numpy array, bypassing pandas per-cell dispatch overhead (27s → ~2s)
  3. analyze/core/doc_constraint_checker.py — Added skip_shape_inference parameter to avoid redundant infer_shapes() call (~3.3s saved)
  4. analyze/core/information_engine.py + analyze/analyzer.py + analyze/core/runtime_checker.py — Pass shape-inferred model proto from RuntimeCheckerQuery to DocConstraintChecker
  5. export/init.py — Lazy-load io and pytorch submodules (avoids importing optimum.exporters.tasks + transformers at startup, ~29s)
  6. compiler/init.py — Lazy-load Compiler, stages (avoids importing session → torch, ~4s)
  7. core/init.py — Lazy-load generate_dummy_inputs_from_specs (avoids importing torch, ~3.6s)
  8. config/build.py — Lazy-import ONNXConfigNotFoundError (avoids importing export/io.py at module load)
  9. analyze/utils/json_utils.py — Lazy-import jsonschema (~3.5s saved)

@chinazhangchao chinazhangchao changed the title Chao/perf Optimize analyze performance. Apr 7, 2026
@chinazhangchao chinazhangchao marked this pull request as ready for review April 7, 2026 07:24
@chinazhangchao chinazhangchao requested a review from a team as a code owner April 7, 2026 07:24
Comment thread src/winml/modelkit/export/__init__.py
@DingmaomaoBJTU

Copy link
Copy Markdown
Collaborator

Code review

Found 1 issue:

  1. export/__init__.py's __getattr__ never caches loaded symbols back into the module's __dict__ via globals().update(...), so every subsequent attribute access re-triggers __getattr__ instead of hitting the module dict directly. The same PR's compiler/__init__.py and core/__init__.py both call globals().update(...) / globals()[name] = val after loading to avoid this, but export/__init__.py does not.

https://github.com/microsoft/ModelKit/blob/2a263478058c40d3ef4d0cc2494ea9787a5d9dda/src/winml/modelkit/export/__init__.py#L29-L46

For comparison, compiler/__init__.py (same PR) correctly caches:

https://github.com/microsoft/ModelKit/blob/2a263478058c40d3ef4d0cc2494ea9787a5d9dda/src/winml/modelkit/compiler/__init__.py#L35-L47

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@chinazhangchao chinazhangchao requested a review from timenick April 8, 2026 02:56
@chinazhangchao chinazhangchao merged commit 2b57389 into main Apr 9, 2026
9 checks passed
@chinazhangchao chinazhangchao deleted the chao/perf branch April 9, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants