Skip to content

perf: find the versions directory without inspect.stack() - #54

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/jd/perf/discover-without-inspect-stack/find-versions-dir-without-inspect-stack--893407ec
Sep 23, 2026
Merged

mergify[bot] merged 1 commit into
mainfrom
devs/jd/perf/discover-without-inspect-stack/find-versions-dir-without-inspect-stack--893407ec

Conversation

@jd

@jd jd commented Sep 23, 2026

Copy link
Copy Markdown
Member

get_down_revision(revision) locates the versions directory by walking
the call stack, and it did so with inspect.stack(), which also reads
the source context of every frame. It runs once per migration, so on a
long chain it dominated building the revision map: in the Mergify
engine's test suite, collecting the tree spent most of its time here,
because the collection stack is deep and 400 migration loads each paid
for it.

Walk the frame objects with f_back instead and read only
f_code.co_filename, which is all the lookup uses. Collecting the
engine's 15,680 tests goes from 20.8-31.8s to 6.2-9.0s. A new test
executes a real migration file from a versions/ directory, since the
existing one mocks the lookup out.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) noreply@anthropic.com

`get_down_revision(revision)` locates the versions directory by walking
the call stack, and it did so with `inspect.stack()`, which also reads
the source context of every frame. It runs once per migration, so on a
long chain it dominated building the revision map: in the Mergify
engine's test suite, collecting the tree spent most of its time here,
because the collection stack is deep and 400 migration loads each paid
for it.

Walk the frame objects with `f_back` instead and read only
`f_code.co_filename`, which is all the lookup uses. Collecting the
engine's 15,680 tests goes from 20.8-31.8s to 6.2-9.0s. A new test
executes a real migration file from a `versions/` directory, since the
existing one mocks the lookup out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Change-Id: I893407ec8055a6f18b083fef182070a13d531705
Copilot AI lite review requested due to automatic review settings September 23, 2026 17:14
@mergify
mergify Bot deployed to Mergify Merge Protections September 23, 2026 17:14 Active
@mergify

mergify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 6 merge protections satisfied — ready to merge.

Show 6 satisfied protections

🟢 🤖 Continuous Integration

  • all of:
    • check-success=all-greens

🟢 👀 Review Requirements

  • any of:
    • #approved-reviews-by>=1
    • author = dependabot[bot]
    • author = mergify-ci-bot

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|internal|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?!?:

🟢 🔎 Reviews

  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

  • body ~= (?ms:.{48,})

🟢 🚦 Auto-queue

When all merge protections are satisfied, this pull request will be queued automatically.

@mergify
mergify Bot requested a review from a team September 23, 2026 17:15

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Improves migration version-directory discovery performance by replacing inspect.stack() with direct frame traversal and adds real migration coverage.

Changes:

  • Walks caller frames via f_back and co_filename.
  • Cleans up frame references.
  • Adds an integration-style migration test.
File Description
tests/​test_chain.py Tests discovery from an executed migration file.
alembic_git_revisions/​_chain.py Optimizes caller-frame traversal.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jd
jd marked this pull request as ready for review September 23, 2026 17:21
@mergify

mergify Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-23 17:56 UTC · Rule: default · triggered by merge protections
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-23 17:56 UTC · at 0da7d43fe15f490e73a7597cf155fa6455d95261 · squash

This pull request spent 10 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify
mergify Bot merged commit 0da7d43 into main Sep 23, 2026
9 checks passed
@mergify
mergify Bot deleted the devs/jd/perf/discover-without-inspect-stack/find-versions-dir-without-inspect-stack--893407ec branch September 23, 2026 17:56
@mergify mergify Bot added queued and removed queued labels Sep 23, 2026

This branch was successfully deployed

1 active deployment
Mergify Merge Protections — 28a1e8f0 Deployed Sep 23, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants