Skip to content

Single-pass class method indexing in pyrefly coverage#3770

Closed
jorenham wants to merge 1 commit into
facebook:mainfrom
jorenham:coverage/parse-classes-single-pass
Closed

Single-pass class method indexing in pyrefly coverage#3770
jorenham wants to merge 1 commit into
facebook:mainfrom
jorenham:coverage/parse-classes-single-pass

Conversation

@jorenham

@jorenham jorenham commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

The parse_classes function was re-iterating every binding key in the module for each class, just to find the methods of that class. This changes the code (not the behavior) so that this now only requires a single pass.

Here's a quick little benchmark:

Corpus before after speedup
synthetic, 1 module, 2,000 classes 0.457s 0.274s 1.67x
synthetic, 1 module, 6,000 classes 4.182s 0.803s 5.2x
scipy-stubs, 589 modules (and 1 maintainer 😅 ) 1.766s 1.783s ~1.0x

So it looks a bit like this could be a quadratic speedup (in the #classes/module sense)

Test Plan

Tests still pass

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@NathanTempest

Copy link
Copy Markdown
Contributor

Thanks @jorenham for your continued efforts in refactoring and improving pyrefly coverage !!

Replacing the per-class O(classes × bindings) rescan with a single grouping pass is the right fix, and the benchmark makes the improvement clear. Importing and merging.

@meta-codesync

meta-codesync Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D108442250.

@yangdanny97 yangdanny97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in e5e8e89 Jun 15, 2026
@meta-codesync

meta-codesync Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@NathanTempest merged this pull request in e5e8e89.

@meta-codesync meta-codesync Bot added the Merged label Jun 15, 2026
@jorenham jorenham deleted the coverage/parse-classes-single-pass branch June 15, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants