Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy performance fix #435

Merged
merged 3 commits into from
May 30, 2022
Merged

Mypy performance fix #435

merged 3 commits into from
May 30, 2022

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented May 29, 2022

Using a Union TypeAlias with lots of members can significantly slow down mypy, especially the uncompiled version. Noticed it while testing a mypy dev build with Home Assistant. The CI run took significantly longer, 30+ min compared to 7-8min normally.

The slowdown in HA only happened after the 0.37.0 update, since that's when py.typed was added. Previously mypy just ignored the dependency.

--
Specifically, the MultilevelSensorScaleType alias with 30+ members is a problem. The fix here is relatively simple. We can create a common enum base class and use that instead of the union TypeAlias. The only thing to remember is that no members can be added to the base class directly. Otherwise subclassing enums wouldn't work.

Copy link
Contributor

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks!

@MartinHjelmare MartinHjelmare merged commit d1b4b4f into home-assistant-libs:master May 30, 2022
@cdce8p cdce8p deleted the mypy-performance-fix branch May 30, 2022 06:11
@cdce8p
Copy link
Contributor Author

cdce8p commented May 31, 2022

Small followup now that Home Assistant has been updated to use 0.37.1, even the normal mypy runs are significantly faster. Around 1:45min for a full mypy CI run, compared to 2:30-3min previously. Wasn't expecting it, but obviously great to see 🚀

@raman325
Copy link
Contributor

excellent, thanks for your help with this!

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