Skip to content

Commit bdabb90

Browse files
committed
Fix documents
1 parent 72891ca commit bdabb90

File tree

2 files changed

+149
-1
lines changed

2 files changed

+149
-1
lines changed

peps/pep-0795.rst

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
PEP: 795
2+
Title: A dedicated ``profilers`` module for organizing python profiling tools
3+
Author: Pablo Galindo <pablogsal@python.org>,
4+
László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
5+
Status: Draft
6+
Type: Standards Track
7+
Created: 17-Jul-2025
8+
Python-Version: 3.15
9+
Post-History:
10+
11+
Abstract
12+
========
13+
14+
This PEP proposes the creation of a new standard library module named
15+
``profilers`` to organize Python's built-in profiling tools under a single,
16+
coherent namespace.
17+
18+
This PEP also proposes the deprecation of the ``profile`` module, a legacy
19+
pure-Python tracing profiler.
20+
21+
Motivation
22+
==========
23+
24+
Python currently ships with two tracing profilers: ``profile`` and ``cProfile``. The
25+
``profile`` module is implemented in pure Python and is largely educational or useful for
26+
subclassing, but too slow for realistic use. ``cProfile``, by contrast, is implemented
27+
in C and more suitable for practical profiling scenarios, although it is not a drop-in
28+
replacement for ``profile`` due to some behavioral differences.
29+
30+
Both of these are tracing profilers, meaning they instrument every function call and return.
31+
This methodology introduces significant runtime overhead and can disable certain interpreter
32+
optimizations, such as those introduced by :pep:`659`. Moreover, ``cProfile`` only observes the
33+
main thread, making it less useful in modern concurrent Python programs. Confusingly, the naming
34+
of these modules implies that ``profile`` is canonical, when in fact it is largely obsolete.
35+
36+
With Python 3.15, a new sampling profiler was introduced under ``profile.sample``. Named
37+
**tachyon**, this tool uses statistical sampling to infer performance characteristics, which
38+
introduces much lower overhead and works better with the modern Python interpreter. It also supports
39+
multiple threads, async functions, and attaching to running processes. Despite these strengths,
40+
the placement of tachyon under ``profile.sample`` is misleading and obscures its importance.
41+
42+
Currently, the organization of profiling tools lacks a consistent, discoverable structure.
43+
The proposed reorganization is meant to guide users more effectively toward appropriate tools,
44+
clarify methodological distinctions between profilers, and lay the groundwork for future extensions.
45+
46+
Rationale
47+
=========
48+
49+
This reorganization addresses several long-standing issues with Python’s profiling tools.
50+
51+
First, it improves **discoverability** by collecting all built-in profilers
52+
under a single, clearly named namespace. Currently, profiling tools are
53+
scattered across modules with inconsistent naming and unclear relationships. By
54+
introducing the ``profilers`` module, users will have a well-defined and
55+
intuitive location to explore and access profiling functionality.
56+
57+
Second, the proposal enhances **clarity** by naming the submodules according to
58+
their underlying methodology—``profilers.tracing`` for deterministic tracing
59+
profilers and ``profilers.sampling`` for statistical sampling profilers. This
60+
explicit categorization makes it easier to understand the behavior and
61+
limitations of each tool and aligns the API with the mental model users are
62+
encouraged to adopt.
63+
64+
Third, it provides **guidance** to developers by making the recommended tools
65+
easier to find and use. The current structure can mislead users into relying on
66+
outdated or less performant modules like ``profile``, simply because of naming
67+
precedence. With the ``profilers`` namespace and its clearer semantics, users
68+
are more likely to choose the appropriate profiler for their specific use case,
69+
whether it involves low-overhead sampling or detailed tracing.
70+
71+
Finally, this structure promotes **extensibility**. By consolidating profiling
72+
tools under a unified namespace, it becomes straightforward to introduce future
73+
profiling capabilities—such as memory profilers, I/O profilers, or hybrid
74+
tools—without overloading unrelated modules or adding redundant top-level names.
75+
The ``profilers`` module provides a natural home for the continued evolution of
76+
Pytho
77+
78+
Specification
79+
=============
80+
81+
New Module Structure
82+
--------------------
83+
84+
This PEP introduces a new ``profilers`` module containing:
85+
86+
- ``profilers.tracing``: an alias for ``cProfile``, providing deterministic function-call tracing.
87+
- ``profilers.sampling``: an alias for ``profilers.tachyon``, improving visibility and semantic clarity.
88+
89+
Additionally the **code** for the ``tachyon`` profiler will be also relocated to
90+
the module as ``profilers.tachyon``.
91+
92+
Deprecation of ``profile``
93+
--------------------------
94+
95+
The ``profile`` module will be deprecated starting in Python 3.16.
96+
97+
- In Python 3.15: importing ``profile`` emits a ``DeprecationWarning``.
98+
- In Python 3.16: all uses of ``profile`` emit a ``DeprecationWarning``.
99+
- In Python 3.17: the module will be removed from the standard library.
100+
101+
Users will be encouraged to use ``profilers.tracing`` instead of ``profile``, and
102+
``profilers.sampling`` instead of ``profile.sample``.
103+
104+
Documentation
105+
=============
106+
107+
The official Python documentation will reflect the new ``profilers`` module as the canonical
108+
entry point for profiling functionality. It will describe:
109+
110+
- The distinction between tracing and sampling profilers.
111+
- Guidance on when each is appropriate.
112+
113+
Documentation for ``cProfile`` and ``profile.sample`` will remain available but will link to
114+
the new ``profilers`` equivalents.
115+
116+
Backwards Compatibility
117+
=======================
118+
119+
The only backwards incompatible aspect of this PEP is the future removal of the ``profile`` module
120+
but this will be made following the :pep:`387 ` procedure.
121+
122+
Security Implications
123+
=====================
124+
125+
None.
126+
127+
Rejected Alternatives
128+
=====================
129+
130+
Renaming ``cProfile``
131+
---------------------
132+
133+
Renaming ``cProfile`` to ``profile.tracing`` was considered, but this change would impact a
134+
large amount of existing code. Maintaining the original name while aliasing it under
135+
``profilers.tracing`` strikes a balance between compatibility and clarity.
136+
137+
Top-Level ``tachyon`` Module
138+
----------------------------
139+
140+
Introducing ``import tachyon`` as a new top-level module was rejected. Grouping tachyon under
141+
``profilers`` helps establish a logical structure and prevents proliferation of top-level modules
142+
and also minimizes the usage of global namespace as requested by the Python Steering council
143+
144+
Copyright
145+
=========
146+
147+
This document is placed in the public domain or under the CC0-1.0-Universal
148+
license, whichever is more permissive.

peps/pep-0799.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PEP: 795
1+
PEP: 799
22
Title: A dedicated ``profilers`` package for organizing Python profiling tools
33
Author: Pablo Galindo <pablogsal@python.org>,
44
László Kiss Kollár <kiss.kollar.laszlo@gmail.com>,

0 commit comments

Comments
 (0)