Skip to content

mypy-protobuf 3.7.0 causes enormous mypy processing time #707

@subnix

Description

@subnix

After upgrading mypy-protobuf to version 3.7.0, we observed enormous memory consumption and processing time by mypy. Upon further analysis, we discovered that this issue is primarily caused by a _pb2_grpc.pyi file. It appears that each RPC method within a single service contributes to the increased processing time, and this becomes noticeable when there are 11 RPC methods.

Here's a simple example to illustrate this: mypy takes more than 5 minutes to process stubs of this proto file.

test.proto:

syntax = "proto3";

package test;

message Simple {
  string a_string = 1;
}

service Test {
  rpc Test1(Simple) returns (Simple);
  rpc Test2(Simple) returns (Simple);
  rpc Test3(Simple) returns (Simple);
  rpc Test4(Simple) returns (Simple);
  rpc Test5(Simple) returns (Simple);
  rpc Test6(Simple) returns (Simple);
  rpc Test7(Simple) returns (Simple);
  rpc Test8(Simple) returns (Simple);
  rpc Test9(Simple) returns (Simple);
  rpc Test10(Simple) returns (Simple);
  rpc Test11(Simple) returns (Simple);
  rpc Test12(Simple) returns (Simple);
  rpc Test13(Simple) returns (Simple);
  //rpc Test14(Simple) returns (Simple);
  //rpc Test15(Simple) returns (Simple);
}
$ pip install mypy 'mypy-protobuf==3.7.0' grpcio-tools types-grpcio
$ python3 -m grpc_tools.protoc --python_out=test --mypy_out=test --grpc_python_out=test --mypy_grpc_out=test --proto_path=test test/test.proto
$ mypy -v --no-incremental test

Apparently, this issue arises because of the introduction of generics in 3.7.0. Some combination of generics and typevars with constraints significantly impacts the processing of __init__ methods. Therefore, removing __init__ methods restores normal processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions