You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Chad Dombrova <ch...@gmail.com> on 2022/02/12 02:34:54 UTC

GSoC idea: mypyc as an alternative to cython

Hi all,
At work, I recently started playing around with mypyc[1] as a means to
compile our python code to C extensions, and I'm pretty impressed so far.

Pros

   - write normal python code with annotations:  we're already doing this!
   - no need for cython-specific header files that can get out of sync with
   the pure python version
   - support for dataclasses and Generics
   - one less tool in the toolchain: mypyc is part of mypy
   - opens the door to more easily converting additional modules in the
   future

Cons

   - less mature than Cython
   - build errors are not very informative

Neural

   - requires more detailed annotations.  for example, you must annotate
   class attributes with ClassVar

I thought it would be an interesting and relatively accessible project to
try to convert the current modules that use cython over to mypyc and see
how it goes.  Just a thought: take it or leave it!

-chad

[1] https://mypyc.readthedocs.io/en/latest/introduction.html

Re: GSoC idea: mypyc as an alternative to cython

Posted by Chad Dombrova <ch...@gmail.com>.
>
> - What does the new prototype code look like (hopefully much cleaner)?
>

Instead of a separate pxd file, you just have the existing .py file with
standard typing annotations.


> - How does performance compare to the Cython approach?
>

Good question.  I've not been able to find any posts with comparisons.
mypyc maintains a benchmark repo with results compared to standard
cpython:
https://github.com/mypyc/mypyc-benchmark-results/blob/master/reports/summary-main.md

Running these benchmarks against cython could be a good first task.

Unlike Cython, mypyc doesn’t natively support numpy, but IIRC beam is not
using that in its cythonized modules.

-chad

Re: GSoC idea: mypyc as an alternative to cython

Posted by Brian Hulette <bh...@google.com>.
I agree this could be an interesting project/experiment. At the end I would
hope to see two things:
- What does the new prototype code look like (hopefully much cleaner)?
- How does performance compare to the Cython approach?

If we already have the benchmarks to measure the latter (this is a question
for the community, I don't know if we do), then this would be a nice
self-contained project.

Brian

On Wed, May 25, 2022 at 11:27 AM Sam Bourne <sa...@gmail.com> wrote:

> Is there any interest in this? There is a lot of promise in only needing
> to maintain a single well typed implementation.
>
> On Fri, Feb 11, 2022 at 6:35 PM Chad Dombrova <ch...@gmail.com> wrote:
>
>> Hi all,
>> At work, I recently started playing around with mypyc[1] as a means to
>> compile our python code to C extensions, and I'm pretty impressed so far.
>>
>> Pros
>>
>>    - write normal python code with annotations:  we're already doing
>>    this!
>>    - no need for cython-specific header files that can get out of sync
>>    with the pure python version
>>    - support for dataclasses and Generics
>>    - one less tool in the toolchain: mypyc is part of mypy
>>    - opens the door to more easily converting additional modules in the
>>    future
>>
>> Cons
>>
>>    - less mature than Cython
>>    - build errors are not very informative
>>
>> Neural
>>
>>    - requires more detailed annotations.  for example, you must annotate
>>    class attributes with ClassVar
>>
>> I thought it would be an interesting and relatively accessible project to
>> try to convert the current modules that use cython over to mypyc and see
>> how it goes.  Just a thought: take it or leave it!
>>
>> -chad
>>
>> [1] https://mypyc.readthedocs.io/en/latest/introduction.html
>>
>>

Re: GSoC idea: mypyc as an alternative to cython

Posted by Sam Bourne <sa...@gmail.com>.
Is there any interest in this? There is a lot of promise in only needing to
maintain a single well typed implementation.

On Fri, Feb 11, 2022 at 6:35 PM Chad Dombrova <ch...@gmail.com> wrote:

> Hi all,
> At work, I recently started playing around with mypyc[1] as a means to
> compile our python code to C extensions, and I'm pretty impressed so far.
>
> Pros
>
>    - write normal python code with annotations:  we're already doing this!
>    - no need for cython-specific header files that can get out of sync
>    with the pure python version
>    - support for dataclasses and Generics
>    - one less tool in the toolchain: mypyc is part of mypy
>    - opens the door to more easily converting additional modules in the
>    future
>
> Cons
>
>    - less mature than Cython
>    - build errors are not very informative
>
> Neural
>
>    - requires more detailed annotations.  for example, you must annotate
>    class attributes with ClassVar
>
> I thought it would be an interesting and relatively accessible project to
> try to convert the current modules that use cython over to mypyc and see
> how it goes.  Just a thought: take it or leave it!
>
> -chad
>
> [1] https://mypyc.readthedocs.io/en/latest/introduction.html
>
>