What is overhead of fork()
in Perl in regard to Perl's own data structures? Does 1) size of code (syntax tree) and 2) amount of data in variables/references affect amount of time spent on forking?
Not a Perl question, since fork
is a system call. It does not matter whether that process is Perl or not, it always does the same things. It does not care about the partical internals of a process, only the total memory size has an effect.
Modern operating systems such as Linux implement COW, so fork
usually returns very quickly, nearly the same for each process.
The short answer is, as others have said, that the amount of code/data has no bearing on fork()
performance beyond what is generically implied by your system's implementation.
However, perl itself will flush open filehandles before calling fork, per the documentation. So, yes, the number of open perl filehandles has some bearing on fork() performance.
(Threaded perl builds will also throw an internal mutex protecting memory allocation, at least under 5.16 on my system. Small, internal synchronization like that will likely vary from system to system and from perl version to perl version.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With