-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Try some aliases speed-up #19810
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
Try some aliases speed-up #19810
Conversation
|
Hm, looking at primer this makes a bunch of projects visibly slower actually, at least with interpreted mypy. And one of them (https://github.com/vega/altair) is still running after 30 minutes. Not sure what is going on there, will look into it. |
This comment has been minimized.
This comment has been minimized.
|
Interesting, it looks like New errors in |
|
OK, here is take two, I still see ~same 2% boost for self-check, let's see how this will work for other projects. |
This comment has been minimized.
This comment has been minimized.
|
Hm, |
|
Btw the |
|
Diff from mypy_primer, showing the effect of this PR on open source code: altair (https://github.com/vega/altair)
+ altair/datasets/_reader.py:153: error: Type argument "IntoFrameT" of "BaseImpl" must be a subtype of "NativeDataFrame | DataFrameLike | NativeLazyFrame" [type-var]
core (https://github.com/home-assistant/core)
- homeassistant/components/openai_conversation/__init__.py:105: error: Returning Any from function declared to return "JsonObjectType | None" [no-any-return]
+ homeassistant/components/openai_conversation/__init__.py:105: error: Returning Any from function declared to return "dict[str, JsonValueType] | None" [no-any-return]
- homeassistant/components/habitica/services.py:835: error: Returning Any from function declared to return "JsonObjectType | None" [no-any-return]
+ homeassistant/components/habitica/services.py:835: error: Returning Any from function declared to return "dict[str, JsonValueType] | None" [no-any-return]
- homeassistant/components/webostv/media_player.py:406: error: Returning Any from function declared to return "JsonObjectType | None" [no-any-return]
+ homeassistant/components/webostv/media_player.py:406: error: Returning Any from function declared to return "dict[str, JsonValueType] | None" [no-any-return]
- homeassistant/components/webostv/media_player.py:511: error: Returning Any from function declared to return "JsonObjectType | None" [no-any-return]
+ homeassistant/components/webostv/media_player.py:511: error: Returning Any from function declared to return "dict[str, JsonValueType] | None" [no-any-return]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/commands/slash.py:1543: error: Type argument "_SlashCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/slash.py:1543: error: Type argument "_SlashCallbackSigT" of "MessageCommand" must be a subtype of "Callable[[MessageContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:162: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:162: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:209: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:209: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:406: error: Type argument "_MessageCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:406: error: Type argument "_MessageCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:516: error: Type argument "_OtherCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:516: error: Type argument "_OtherCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:543: error: Type argument "_OtherCallbackSigT" of "MenuCommand" must be a subtype of "Callable[[MenuContext, Any, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
+ tanjun/commands/message.py:543: error: Type argument "_OtherCallbackSigT" of "SlashCommand" must be a subtype of "Callable[[SlashContext, VarArg(Any), KwArg(Any)], Coroutine[Any, Any, None]]" [type-var]
static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/node_re.py:59: error: Invalid type argument value for "ToContainerType" [type-var]
+ static_frame/core/node_dt.py:124: error: Invalid type argument value for "ToContainerType" [type-var]
+ static_frame/core/node_str.py:98: error: Invalid type argument value for "ToContainerType" [type-var]
|
|
OK, I double-checked again with the latest version of this PR:
It looks like this is a clear overall win: most projects will likely get few percent speed-up, and only few projects may get few percent slower. |
|
Also opened #19812 for the fine-grained issue. |
This makes self-check almost 2% faster on my desktop (Python 3.12, compiled -O2). Inspired by a slight regression in #19798 I decided to re-think how we detect/label the recursive types.
The new algorithm is not 100% equivalent to old one, but should be much faster. The main semantic difference is this:
previously all three aliases where labeled as recursive, now only last two are. Which is kind of correct if you think about it for some time, there is nothing genuinely recursive in
Aby itself. As a result:reveal_type()for recursive types after fine-grained increments. Excessive use ofget_proper_type()in the daemon code is a known issue. I will take a look at it when I will have a chance.If there are no comments/objections, I will merge it later today. Then I will merge #19798, and then maybe an equivalent optimization for recursive instances like
class str(Sequence[str]): ...