GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Lazily create builtin bindings by charliermarsh · Pull Request #26510 · astral-sh/ruff

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jul 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

The linter previously inserted every version-specific builtin, magic global, notebook builtin, and configured custom builtin into the module scope before walking the AST, even when a file never referenced most of those names.

This moves builtin identification into SemanticModel and creates concrete builtin bindings only when a load or binding operation needs them.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
charliemarsh-oai and others added 2 commits July 1, 2026 19:13
@charliemarsh-oai
Lazily create builtin bindings
bd80f17
@charliermarsh
Preserve lazily created builtin bindings
63c07e5
@codspeed

codspeed Bot commented Jul 1, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Merging this PR will improve performance by 9.79%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 10 improved benchmarks
✅ 50 untouched benchmarks
⏩ 93 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation linter/default-rules[numpy/globals.py] 179.1 µs 148.7 µs +20.42%
⚡ Memory linter/default-rules[pydantic/types.py] 348.9 KB 306.7 KB +13.78%
⚡ Memory linter/default-rules[numpy/ctypeslib.py] 164.2 KB 146.2 KB +12.31%
⚡ Simulation linter/all-with-preview-rules[numpy/globals.py] 832.5 µs 749.1 µs +11.13%
⚡ Simulation linter/all-rules[numpy/globals.py] 717 µs 664.6 µs +7.88%
⚡ Memory linter/all-rules[pydantic/types.py] 648.8 KB 606.6 KB +6.97%
⚡ Simulation linter/default-rules[unicode/pypinyin.py] 370.1 µs 346.3 µs +6.87%
⚡ Memory linter/all-with-preview-rules[pydantic/types.py] 667.2 KB 625 KB +6.76%
⚡ Memory linter/all-rules[numpy/ctypeslib.py] 289.3 KB 271.3 KB +6.64%
⚡ Memory linter/all-with-preview-rules[numpy/ctypeslib.py] 317.3 KB 299.3 KB +6.01%

Tip

Curious why this is faster? Use the CodSpeed MCP and ask your agent.


Comparing charlie/codex-codspeed-speedup (634be4d) with main (71d151f)

Open in CodSpeed

Footnotes

  1. 93 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. ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charliermarsh
Clarify lazy builtin handling
8e9a3a6
@charliermarsh
charliermarsh force-pushed the charlie/codex-codspeed-speedup branch from 675a38b to 8e9a3a6 Compare July 1, 2026 20:53
@charliermarsh
charliermarsh requested a review from ntBre July 1, 2026 20:54
@charliermarsh charliermarsh added the performance Potential performance improvement label Jul 1, 2026
@charliermarsh
charliermarsh marked this pull request as ready for review July 1, 2026 20:55
@ntBre

ntBre commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Nice! The performance improvement looks great, but I'm a bit wary of the API. It seems like it would be easy to forget to call ensure_builtin_binding everywhere it's necessary. Is there any way to use a Cell or something to initialize the builtins automatically when we try to access them?

As one example, Codex claims that this snippet:

from airflow.operators.python import PythonOperator

task = PythonOperator(
    task_id="task",
    op_args="{{ ti.xcom_pull(task_ids='len') }}",
)
ruff check --preview --select AIR201 --unsafe-fixes repro.py

has no fix on this branch but offers a fix on main. The result of the fix actually looks like a bug on main (playground), but it's still an example of a behavior change that I think is accidental.

In general Codex claims "every caller must remember whether lookup_symbol alone is sufficient or whether it also needs has_builtin_binding," so it seems nicer if we could hide the builtin construction inside lookup_symbol somehow.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charliemarsh-oai
Make lazy builtin lookup explicit
634be4d
@charliermarsh
charliermarsh marked this pull request as draft July 7, 2026 11:50
@astral-sh-bot

astral-sh-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@charliermarsh
charliermarsh marked this pull request as ready for review July 7, 2026 12:18
@charliermarsh

charliermarsh commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Good feedback -- how does this look?

ntBre reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ntBre
ntBre approved these changes Jul 7, 2026
View reviewed changes

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great to me, thank you!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@charliermarsh
charliermarsh merged commit 2dff4da into main Jul 7, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@charliermarsh
charliermarsh deleted the charlie/codex-codspeed-speedup branch July 7, 2026 13:55
@BrewTestBot BrewTestBot mentioned this pull request Jul 9, 2026
ruff 0.15.21 Homebrew/homebrew-core#292272
Merged
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#978
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ntBre ntBre ntBre approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

performance Potential performance improvement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@charliermarsh @ntBre @charliemarsh-oai
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.