Bug 28416

Summary: Email::Sender::Transport::SMTP is using 10Mo of RAM
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Architecture, internals, and plumbingAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: enhancement    
Priority: P5 - low CC: dcook, kyle, m.de.rooy, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00
Bug Depends on:    
Bug Blocks: 28410    
Attachments: Bug 28416: Delay load of Email::Sender::Transport::SMTP
Bug 28416: Delay load of Email::Sender::Transport::SMTP
Bug 28416: Delay load of Email::Sender::Transport::SMTP

Description Jonathan Druart 2021-05-21 12:08:24 UTC
Well ok, it's not that much over the ~130Mo the usual library stack, but maybe we should replace the use with a require to load in only when needed?
Comment 1 Jonathan Druart 2021-05-21 12:11:46 UTC
Created attachment 121275 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM
Comment 2 Jonathan Druart 2021-05-21 12:12:59 UTC
Can be tested with

use Memory::Usage;
my $mu = Memory::Usage->new();
$mu->record('Loading');
require Koha::Libraries;
$mu->record('module loaded');
print $mu->report();

I don't think overall it's a good idea to use require, but maybe it's worth here?
Comment 3 David Cook 2021-05-24 01:17:30 UTC
This one is probably especially good to do, since it looks like transport() is often called within a try/catch block anyway.
Comment 4 Tomás Cohen Arazi 2021-11-08 12:39:17 UTC
(In reply to David Cook from comment #3)
> This one is probably especially good to do, since it looks like transport()
> is often called within a try/catch block anyway.

I agree with this assertion. I'd add that we probably don't want this lib loaded on user facing places, as we are leaning towards using the message_queue more often than we do now.
Comment 5 Jonathan Druart 2022-03-22 14:07:21 UTC
So, signoff?
Comment 6 Tomás Cohen Arazi 2022-03-22 15:31:51 UTC
Created attachment 132028 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 7 Tomás Cohen Arazi 2022-03-22 15:33:46 UTC
(In reply to Jonathan Druart from comment #2)
> Can be tested with
> 
> use Memory::Usage;
> my $mu = Memory::Usage->new();
> $mu->record('Loading');
> require Koha::Libraries;
> $mu->record('module loaded');
> print $mu->report();
> 
> I don't think overall it's a good idea to use require, but maybe it's worth
> here?

I tried moving the 'require' to the Koha::Library namespace. As we will probably load the Koha::SMTP::Server object only when we want the transport anyway. But it didn't help :-D

So signing this patch as it is correct passes the QA tests and does the job. For testers:

$ apt install libmemory-usage-perl
Comment 8 Marcel de Rooy 2022-03-25 10:26:39 UTC Comment hidden (obsolete)
Comment 9 Marcel de Rooy 2022-03-25 10:27:53 UTC Comment hidden (obsolete)
Comment 10 Marcel de Rooy 2022-03-25 10:33:43 UTC
Created attachment 132219 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 11 Marcel de Rooy 2022-03-25 10:34:36 UTC
(In reply to Jonathan Druart from comment #2)

> I don't think overall it's a good idea to use require, but maybe it's worth
> here?

Dangerous precedent created ;)
Comment 12 Fridolin Somers 2022-03-25 21:01:41 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄