Skip to content

Commit d52169d

Browse files
authored
Optimization: make State final and avoid construction via cls() (#20838)
Construction via cls() was pretty slow, possibly due to the large number of keyword arguments, as this used a generic calling convention because of mypyc limitations. This might improve performance of mostly cached, huge incremental builds by 1-2% perhaps, if the CPU profiles I looked at are to be trusted.
1 parent a79b100 commit d52169d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mypy/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
TypeAlias as _TypeAlias,
4040
TypedDict,
4141
cast,
42+
final,
4243
)
4344

4445
from librt.base64 import b64encode
@@ -2186,6 +2187,7 @@ def __init__(self, reason: int = SuppressionReason.NOT_FOUND) -> None:
21862187
self.reason = reason
21872188

21882189

2190+
@final
21892191
class State:
21902192
"""The state for a module.
21912193
@@ -2272,9 +2274,8 @@ class State:
22722274
# Mapping from line number to type ignore codes on this line (for imports only).
22732275
imports_ignored: dict[int, list[str]]
22742276

2275-
@classmethod
2277+
@staticmethod
22762278
def new_state(
2277-
cls,
22782279
id: str | None,
22792280
path: str | None,
22802281
source: str | None,
@@ -2364,7 +2365,7 @@ def new_state(
23642365
error_lines = []
23652366
imports_ignored = {}
23662367

2367-
state = cls(
2368+
state = State(
23682369
manager=manager,
23692370
order=State.order_counter,
23702371
id=id,

0 commit comments

Comments
 (0)