Speed-up compilation time

886 views
Skip to first unread message

claudio...@gmail.com

unread,
Jan 20, 2019, 7:08:41 AM1/20/19
to cython-users
Hi.

I'm writing a Cython module and it becoming bigger; compilation time is now really long. There's something I could do to get a faster compilation? Something like splitting my module in multiple source files, recompile only what's needed to a .o file and let the linker assemble the final .so shared library, just like C with makefile?

Thanks for any suggestion.


Stefan Behnel

unread,
Jan 20, 2019, 7:44:25 AM1/20/19
to Cython-users
claudio.cilloni schrieb am 20.01.19 um 11:38:
Since this is a common question, I took the opportunity to write a FAQ
entry about it:

https://github.com/cython/cython/wiki/FAQ#how-can-i-speed-up-the-c-compilation

Stefan

claudio...@gmail.com

unread,
Jan 20, 2019, 7:53:31 AM1/20/19
to cython-users
Down to 11 seconds from 41. That's a good compromise.

Thanks a lot.

Bye

Jérôme Kieffer

unread,
Jan 21, 2019, 2:04:50 AM1/21/19
to cython...@googlegroups.com
On Sun, 20 Jan 2019 04:51:43 -0800 (PST)
claudio...@gmail.com wrote:

> Down to 11 seconds from 41. That's a good compromise.

ccache works also (great) for cython & gcc !

Cheers,

Jérôme

René Dudfield

unread,
Jan 21, 2019, 7:53:21 AM1/21/19
to cython...@googlegroups.com
From python 3.5:
* The ``build`` and ``build_ext`` commands now accept a ``-j``  +  option to enable parallel building of extension modules.

python3 setup.py build -j4 install

This improves compilation of pygame(with 36 modules) from 20 seconds to 8.3 seconds with optimization enabled on a 4 core laptop.
If you have 64 cores, and 64 separate modules... :)


There are some distutils hacks around for cythonize with multiprocessing as well.

claudio...@gmail.com

unread,
Jan 21, 2019, 12:24:07 PM1/21/19
to cython-users
Unfortunately the the longest part of the process is the compilation of the single big .c file generated by Cython, and it cannot be parallelized. Unless I split my code into separated cython modules, I cannot take advantage of -j.
Thank you, anyway.

René Dudfield

unread,
Jan 22, 2019, 11:32:18 AM1/22/19
to cython...@googlegroups.com
Yeah, splitting your code up into separate modules will give you big improvements.

Because if you only change one part, then only that part is recompiled.

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brock Mendel

unread,
Oct 31, 2019, 9:16:20 PM10/31/19
to cython-users
> ccache works also (great) for cython & gcc !

I've just learned about ccache and have installed it, but it isn't getting used.  Do I have to do anything cython-specific to tell cython to use it?

René Dudfield

unread,
Nov 1, 2019, 4:39:36 AM11/1/19
to cython...@googlegroups.com

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.

Robert Bradshaw

unread,
Nov 3, 2019, 1:13:22 AM11/3/19
to cython...@googlegroups.com
On Thu, Oct 31, 2019 at 6:16 PM Brock Mendel <jbrock...@gmail.com> wrote:
>
> > ccache works also (great) for cython & gcc !
>
> I've just learned about ccache and have installed it, but it isn't getting used. Do I have to do anything cython-specific to tell cython to use it?

It should just work, but if it doesn't compare the sources and file a
bug (we try to weed out any non-determinism in what we produce, but
it's possible something slipped through).

For pip installs, be aware of
https://ccache.dev/manual/latest.html#_compiling_in_different_directories
as it compiles things in ephemeral temporary directories.

> On Sunday, January 20, 2019 at 11:04:50 PM UTC-8, Jerome Kieffer wrote:
>>
>> On Sun, 20 Jan 2019 04:51:43 -0800 (PST)
>> claudio...@gmail.com wrote:
>>
>> > Down to 11 seconds from 41. That's a good compromise.
>>
>> ccache works also (great) for cython & gcc !
>>
>> Cheers,
>>
>> Jérôme
>
Reply all
Reply to author
Forward
0 new messages