Subject: | inefficient heap usage in Decrypt.xs |
Date: | Thu, 24 Apr 2014 17:50:09 -0400 |
To: | bug-Filter-Crypto [...] rt.cpan.org |
From: | Kevin Groeneveld <kgroeneveld [...] gmail.com> |
I have been trying to use Filter::Crypto with a few perl programs
recently. In general everything is working great but I noticed that the
memory usage of the perl process is often MUCH higher when using
Filter::Crypto. For example, I have one script where the perl process
would be almost 30M bigger. This is significant when running on an
embedded system with limited memory.
I tracked the issue down to the mortal SV buffers in
FilterCrypto_FilterDecrypt. This function gets called for each line of
source code that is being decrypted so a couple new SVs (totally 24k in my
test case) get allocated for each line. While the buffers eventually are
freed the way the heap grows and becomes fragmented the actual memory usage
of the stack can remain quite large.
Attached is a patch with one possible way of fixing the issue. The patch
allocates one set of buffers and reuses them for each call to
FilterCrypto_FilterDecrypt. I am not a perl or XS expert so this may not
be a good way to fix it but the patch is working for me.
Kevin
Message body is not shown because sender requested not to inline it.