Skip to content

Support import timing and cached import diagnostics - #9190

Merged
youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:python315-import-timing
Oct 18, 2026
Merged

youknowone merged 3 commits into
RustPython:mainfrom
youknowdot:python315-import-timing

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Extract import-time diagnostics from the Python 3.15 upgrade work (#8954):

  • Support -X importtime / PYTHONPROFILEIMPORTTIME, including mode 2 cached-import reporting, first -X occurrence, environment override, and invalid numeric-value diagnostics.
  • Track nested self/cumulative timings per VM thread, with one output header per interpreter and backslash-replaced surrogate names.
  • Match CPython's distinct measured-import indentation and cached-import minimum encoded-byte width.
  • Remove only the now-obsolete CmdLineTest.test_import_time expected-failure marker through scripts/update_lib; canonical assertions and all other markers are unchanged.

This stays independent of frozen-module selection, startup initialization, and unrelated import exception changes.

Reference

CPython d220409a13b77de7a6c30abe16ea90db01528edc: Python/import.c (import_ensure_initialized and import_find_and_load_with_name) and Python/initconfig.c (config_init_import_time).

Validation

Final source 4fae3992 validated on Linux:

  • Locked/offline release build.
  • Six selected canonical tests pass: test_import_time, test_xoptions, circular import/from-import, repeated failed import, and thread creation. These are focused regression checks, not full test_cmd_line/test_import/test_thread suite passes.
  • Standard workspace tests (excluding wasm, venvlauncher, and CAPI) and separate cargo test from crates/capi, including doc tests.
  • Strict cargo clippy --all-targets -- -D warnings for the same workspace and separate CAPI scopes.
  • 34 external option observations compared with pinned CPython: modes 0/1/2, empty/text values, sign/ASCII whitespace, overflow/trailing text, repeated options, environment precedence, -E/-I, and nested cached imports. The one known difference is documented below. All four invalid-range fatal diagnostics match exactly, as does nested cached UTF-8/surrogate output.

Normal commit hooks passed. No new Python behavioral snippets or replacement tests were added.

Known boundary

CPython's wide-character -X numeric parser inherits its startup locale. Under C.UTF-8, leading U+2003 whitespace selects mode 2 there, while this parser falls back to mode 1. Byte-based environment parsing agrees. This PR does not change process locale initialization or claim complete locale-sensitive numeric parsing parity. The existing unencodable-module-name expected-failure remains: its combined missing-module/surrogate case still reports expected failure on this independent Linux runtime, while pinned CPython passes. Cached UTF-8 and escaped-surrogate formatting matches the pinned oracle.

Assisted-by: OpenAI Codex:model version unavailable

Support -X importtime and PYTHONPROFILEIMPORTTIME, including mode 2 cached imports. Track nested timing separately in each VM thread and share the output header per interpreter.

Assisted-by: OpenAI Codex:model version unavailable
Retire only test_import_time expectedFailure after the independent runtime passes its canonical assertions. Preserve other cmd-line markers and align environment range errors with CPython.

Assisted-by: OpenAI Codex:model version unavailable
Keep CPython cached-import minimum width semantics for UTF-8 and backslash-replaced surrogate names. Scope the diagnostic blank line to importtime without changing CPU-count errors.

Assisted-by: OpenAI Codex:model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: deef2665-16b8-4329-b18f-c1c89acecb9c
📥 Commits

Reviewing files that changed from the base of the PR and between 3f55cf4 and 4fae399.

⛔ Files ignored due to path filters: 1
  • Lib/test/test_cmd_line.py is excluded by !Lib/**
📒 Files selected for processing: 6
  • crates/vm/src/import.rs
  • crates/vm/src/vm/interpreter.rs
  • crates/vm/src/vm/mod.rs
  • crates/vm/src/vm/setting.rs
  • crates/vm/src/vm/thread.rs
  • src/settings.rs
+------------------------------------------------+
| Squeezing intelligence out of LLMs since 2023. |
+------------------------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[ ] test: cpython/Lib/test/test_cmd_line.py (TODO: 20)

dependencies:

dependent tests: (no tests depend on cmd_line)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@codspeed

codspeed Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:python315-import-timing (4fae399) with main (3f55cf4)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 18, 2026 13:38
@youknowone
youknowone merged commit 6e064e5 into RustPython:main Oct 18, 2026
32 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T13:45:48.592954Z 4fae399 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4fae3992c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vm/src/import.rs
Some(Self {
state: &vm.import_timing,
parent,
start: Instant::now(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate import timing's clock on wasm32-unknown-unknown

When an embedder builds rustpython_vm for wasm32-unknown-unknown and sets the new public Settings::import_time field to 1 or 2, interpreter startup reaches Instant::now() on the first uncached import; Rust's standard-library implementation panics on that target because no monotonic clock is available. This makes enabling the diagnostic abort execution instead of reporting timings, so this path needs a wasm clock implementation or a target-specific graceful fallback.

AGENTS.md reference: AGENTS.md:L11-L12

Useful? React with 👍 / 👎.

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.

2 participants