From 495a2009a1addad341f92052150662ecbb4692a3 Mon Sep 17 00:00:00 2001 From: Blou Date: Wed, 25 Oct 2023 16:54:08 -0400 Subject: [PATCH] Bug 28411: Use lazy loading to reduce memory footprint of C4/Context.pm This simply removes some 'use' declarations at the top of the file to instead use 'require' later on. The effect can be validated with a simple one-liner (provided KOHA_CONF and PERL5LIB being set) perl -e "use C4::Context; while(1){sleep(1);}" And monitoring the memoring usage in tools like 'top' --- C4/Context.pm | 8 ++++---- C4/Search.pm | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 091e4783a4..0d8bce7458 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -36,12 +36,8 @@ BEGIN { }; use Carp qw( carp ); -use DateTime::TimeZone; use Encode; use File::Spec; -use POSIX; -use YAML::XS; -use ZOOM; use List::MoreUtils qw(any); use Koha::Caches; @@ -342,6 +338,7 @@ the value cannot be properly decoded as YAML. sub yaml_preference { my ( $self, $preference ) = @_; + require YAML::XS; my $yaml = eval { YAML::XS::Load( Encode::encode_utf8( $self->preference( $preference ) ) ); }; if ($@) { warn "Unable to parse $preference syspref : $@"; @@ -607,6 +604,7 @@ sub _new_Zconn { my $user = $serverinfo->{user}; my $password = $serverinfo->{password}; eval { + require ZOOM; # set options my $o = ZOOM::Options->new(); $o->option(user => $user) if $user && $password; @@ -873,6 +871,7 @@ sub get_versions { my ( %versions, $mysqlVersion ); $versions{kohaVersion} = Koha::version(); $versions{kohaDbVersion} = C4::Context->preference('version'); + require POSIX; $versions{osVersion} = join(" ", POSIX::uname()); $versions{perlVersion} = $]; @@ -904,6 +903,7 @@ sub tz { my $self = shift; if (!defined $context->{tz}) { my $timezone = $context->{config}->timezone; + require DateTime::TimeZone; $context->{tz} = DateTime::TimeZone->new(name => $timezone); } return $context->{tz}; diff --git a/C4/Search.pm b/C4/Search.pm index e2de36571e..6423caa60b 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -39,6 +39,7 @@ use URI::Escape; use Business::ISBN; use MARC::Record; use MARC::Field; +use ZOOM; our (@ISA, @EXPORT_OK); BEGIN { -- 2.34.1