FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-144384: Improve `_colorize` performance by replacing `dataclass` with regular class by hugovk · Pull Request #144879 · python/cpython · GitHub

/ cpython Public

gh-144384: Improve _colorize performance by replacing dataclass with regular class - #144879

Closed
hugovk wants to merge 2 commits into
python:mainfrom
hugovk:3.15-colorize-performance
Closed

gh-144384: Improve _colorize performance by replacing dataclass with regular class#144879
hugovk wants to merge 2 commits into
python:mainfrom
hugovk:3.15-colorize-performance

Conversation

hugovk commented Feb 16, 2026
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

_colorize constructs six different theme classes (and I expect more in the future), which are slow to build because they use dataclasses.

This makes the module as a whole slow to import, even the importer doesn't use a theme or doesn't use colour in the end.

If we switch to regular classes, the construction time is much faster. This PR also avoid the collections.abc import.

traceback

Below are import times for a macOS build with optimisations.

before: 15 ms

after: 6 ms

_colorize

before: 13 ms

after: ~0 ms

ambv commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Marked with DO-NOT-MERGE as this approach isn't agreed upon at this point.

hugovk commented Mar 21, 2026

Copy link
Copy Markdown
Member Author

Closing. We can make the diff smaller by keeping the Mapping, but the better approach is to make dataclasses faster. Let's continue in the isssue.

hugovk closed this Mar 21, 2026
hugovk deleted the 3.15-colorize-performance branch March 21, 2026 14:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL