Title: `_colorize` module is slow to import, affecting `traceback` and `logging` modules · Issue #144384 · python/cpython · GitHub
Open Graph Title: `_colorize` module is slow to import, affecting `traceback` and `logging` modules · Issue #144384 · python/cpython
X Title: `_colorize` module is slow to import, affecting `traceback` and `logging` modules · Issue #144384 · python/cpython
Description: “It is a truth universally acknowledged, that a module in possession of great colors, suffers import time slowdown. _colorize module is slow to import due to its use of dataclasses python -Ximporttime -c "import _colorize" Visualization ...
Open Graph Description: “It is a truth universally acknowledged, that a module in possession of great colors, suffers import time slowdown. _colorize module is slow to import due to its use of dataclasses python -Ximportt...
X Description: “It is a truth universally acknowledged, that a module in possession of great colors, suffers import time slowdown. _colorize module is slow to import due to its use of dataclasses python -Ximportt...
Opengraph URL: https://github.com/python/cpython/issues/144384
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`_colorize` module is slow to import, affecting `traceback` and `logging` modules","articleBody":"> “It is a truth universally acknowledged, that a module in possession of great colors, suffers import time slowdown.\n\n`_colorize` module is slow to import due to its use of dataclasses \n\n```console\npython -Ximporttime -c \"import _colorize\"\n```\n\nVisualization in tuna\n\n\u003cimg width=\"1831\" height=\"1017\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/f2f0dfbf-0270-4aae-8dfa-43e00ca378dc\" />\n\nNotice that significant time is also spent *executing* the `_colorize`, due to the creation of its dataclasses\n\n```console\n❯ uvx python@3.15 -m cProfile -m _colorize | head -15\n 5609 function calls (5489 primitive calls) in 0.006 seconds\n\n Ordered by: cumulative time\n\n ncalls tottime percall cumtime percall filename:lineno(function)\n 9/1 0.003 0.000 0.006 0.006 {built-in method builtins.exec}\n 1 0.000 0.000 0.006 0.006 \u003cstring>:1(\u003cmodule>)\n 1 0.000 0.000 0.006 0.006 \u003cfrozen runpy>:199(run_module)\n 1 0.000 0.000 0.006 0.006 \u003cfrozen runpy>:65(_run_code)\n 1 0.000 0.000 0.006 0.006 _colorize.py:1(\u003cmodule>)\n 7 0.000 0.000 0.005 0.001 dataclasses.py:1432(wrap)\n 7 0.000 0.000 0.005 0.001 dataclasses.py:986(_process_class)\n 7 0.000 0.000 0.003 0.000 dataclasses.py:478(add_fns_to_class)\n 4 0.000 0.000 0.001 0.000 inspect.py:3342(signature)\n 4 0.000 0.000 0.001 0.000 inspect.py:3055(from_callable)\n```\n\nThe slow import time directly affects (among others) the `traceback` module which in turn affects `logging`, which is 40% slower in 3.14 and 3.15 compared to 3.13. That is quite unfortunate since in applications that care about import time, `logging` module is typically hard to avoid (I originally discovered this when looking at pip's startup time)\n\n```console\n hyperfine -w 10 \"python3.13 -c 'import logging'\" \"python3.15 -c 'import logging'\" \nBenchmark 1: python3.13 -c 'import logging'\n Time (mean ± σ): 21.0 ms ± 3.4 ms [User: 14.8 ms, System: 5.9 ms]\n Range (min … max): 16.2 ms … 28.2 ms 155 runs\n \nBenchmark 2: python3.15 -c 'import logging'\n Time (mean ± σ): 29.6 ms ± 2.1 ms [User: 22.2 ms, System: 7.0 ms]\n Range (min … max): 26.4 ms … 35.1 ms 100 runs\n \nSummary\n python3.13 -c 'import logging' ran\n 1.40 ± 0.25 times faster than /home/hollas/.local/share/uv/python/cpython-3.15.0a5-linux-x86_64-gnu/bin/python3.15 -c 'import logging'\n\n```\n\nIt's not very clear how to make this better (besides not using dataclasses). We tried to make traceback lazy in logging, but failed. #112995\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-144879\n* gh-149318\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/danielhollas","@type":"Person","name":"danielhollas"},"datePublished":"2026-02-02T00:18:02Z","url":"https://github.com/python/cpython/issues/144384"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:78a5389b-77c9-e3fd-f37d-242a1c5a4f6b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD10:3CBB3E:2DEB7B8:3AA3DD1:6B02013A |
| html-safe-nonce | cec68c084b71de651c1796899806503a60ff0b5ac4219617cabeb311922c83d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDEwOjNDQkIzRToyREVCN0I4OjNBQTNERDE6NkIwMjAxM0EiLCJ2aXNpdG9yX2lkIjoiODgzMTkyMzIxNzQzOTUyMzEzMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 45831836b57376fd302bf4e5a5325c8fea971712f7f324b14f34f5e2323fece1 |
| hovercard-subject-tag | issue:3883386667 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/144384/issue_layout |
| twitter:image | https://opengraph.githubassets.com/19d5536b2ca43a9e1864d1580c1def6d750c517c147924afef64f7f762413850/python/cpython/issues/144384 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/19d5536b2ca43a9e1864d1580c1def6d750c517c147924afef64f7f762413850/python/cpython/issues/144384 |
| og:image:alt | “It is a truth universally acknowledged, that a module in possession of great colors, suffers import time slowdown. _colorize module is slow to import due to its use of dataclasses python -Ximportt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danielhollas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width