Is it at all realistic / beneficial? can anyone approximate how long
it would take to compile such a file?
300000 times as long as compiling a single file at best, probably a
lot longer (one heuristic is that C compilers are somewhere between
linear and quadratic in the time they take to compile code, and many a
C compiler would have trouble compiling such a large .c output file.
So, not realistic or beneficial--why would you want to do this rather
than write modular code in several .so files?
- Robert
It will also take a non-trivial amount of time to load multi-GB .so
files, not to mention that you can't load only part of it if you only
need part of it.
> Hence, I thought it might be beneficial to 'unite' many '.so' files
> together into one BIG '.so' (or perhaps, several BIG '.so' files) --
> this way, python will only have 3-4 '.so' files to load.
>
> Do you have any advice on how to go about it in the best way? thanks.
Premature optimization is the root of all evil. I'd write whatever
you're trying to write naturally and then worry about something like
this only if it becomes a problem. Unless your modules are absolutely
trivial, I'd imagine you'll spend much less time importing each one
than executing each one. Either you actually use all of them in one
sitting (in which case the total runtime will be huge compared to the
importing (seconds?), or you could only import the one(s) you need
right before you use them (with the obvious runtime and memory
benefits).
- Robert
So, to clarify, each module has one function that's only called once?
Atypical, but in that case, maybe it does make sense to consolidate
them into fewer .pyx files (if it makes sense to statically compile so
many different functions rather than have runtime variation). You
haven't really stated what you're trying to accomplish, that would
help.
> Instead of doing so, is there a way to take existing cython-generated
> '.so' files and simply 'unite' them together in some way?
In theory you can compile them as static libraries (.a files) and then
link them in one big .so. But it seems to me that you are addressing the
problem backwards.
Maybe you should describe why you have such a weird collection of
functions in the first place and what you want to achieve, then it could
turn out that a totally different approach is more practical.
--
Sincerely yours,
Yury V. Zaytsev
But then why isn't using pure Python faster, since that skips Cython and
gcc compilation time? Do you mean the Python process is started
thousands of times, each which call each function once?
> Instead of doing so, is there a way to take existing cython-generated
> '.so' files and simply 'unite' them together in some way?
This is not very well supported. It is not technically impossible, but
involves some ugly hacks etc., since Cython doesn't directly support it.
Keep in mind that compilation has a large constant-time overhead.
Depending on your code, perhaps recompiling 1000 pyx files each time one
changes isn't too bad *shrug*.
To get sensible answers I really think you need to provide more
information about what you attempt to do. Your use case appears very
strange to most of us.
Dag Sverre