Skip to content

Commit

Permalink
Load several modules at runtime instead of compile time
Browse files Browse the repository at this point in the history
Profiling shows they take about a second or
more in total on Windows, and this adds up
across >60 tests.
  • Loading branch information
shawnlaffan committed Dec 16, 2023
1 parent c7e5108 commit f9cc027
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
8 changes: 0 additions & 8 deletions lib/Biodiverse/BaseData.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ use Data::Compare ();

use Ref::Util qw { :all };
use Sort::Key::Natural qw /natkeysort/;
use Spreadsheet::Read 0.60;


use experimental qw /refaliasing declared_refs/;

use Geo::GDAL::FFI 0.07;
# silence a used-once warning - clunky
{
my $xx_frob_temp_zort = $FFI::Platypus::TypeParser::ffi_type;
my $xx_frob_temp_zert = $FFI::Platypus::keep;
}
#require Spreadsheet::XLSX; latest version does not install

use English qw { -no_match_vars };

Expand Down
9 changes: 8 additions & 1 deletion lib/Biodiverse/BaseData/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ use Data::Compare ();

use Ref::Util qw { :all };
use Sort::Key::Natural qw /natkeysort/;
use Spreadsheet::Read 0.82;

use Geo::GDAL::FFI 0.07;
{
my $xx_frob_temp_zort = $FFI::Platypus::TypeParser::ffi_type;
my $xx_frob_temp_zert = $FFI::Platypus::keep;
}

use experimental 'declared_refs';

Expand Down Expand Up @@ -1682,6 +1685,10 @@ sub import_data_spreadsheet {
my $self = shift;
my %args = @_;

# load at run time as it takes a while
require Spreadsheet::Read;
Spreadsheet::Read->VERSION('0.80');

my $orig_group_count = $self->get_group_count;
my $orig_label_count = $self->get_label_count;
my $data_in_matrix_form = $args{data_in_matrix_form};
Expand Down
5 changes: 3 additions & 2 deletions lib/Biodiverse/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use HTML::QuickTable;
use Class::Inspector;
use Ref::Util qw { :all };
use File::BOM qw / :subs /;
use Spreadsheet::Read;

# Need to avoid an OIO destroyed twice warning due
# to HTTP::Tiny, which is used in Biodiverse::GUI::Help
Expand Down Expand Up @@ -1812,7 +1811,9 @@ sub unlink_file {
sub get_book_struct_from_spreadsheet_file {
my ($self, %args) = @_;

#use SpreadSheet::Read;
require Spreadsheet::Read;
Spreadsheet::Read->import('ReadData');

my $book;
my $file = $args{file_name}
// croak 'file_name argument not passed';
Expand Down
2 changes: 1 addition & 1 deletion lib/Biodiverse/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ sub get_calculation_metadata {
my $self = shift;

if (!blessed $self) {
use Biodiverse::BaseData;
require Biodiverse::BaseData;
state $default_bd = Biodiverse::BaseData->new (
NAME => 'for indices',
CELL_SIZES => [1,1],
Expand Down
5 changes: 3 additions & 2 deletions lib/Biodiverse/Indices/PhyloCom.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use List::Util qw /sum min max/;
use List::MoreUtils qw /any minmax pairwise/;
use Scalar::Util qw /blessed/;
use Sort::Key qw /nkeysort/;
use Math::BigInt ();

use feature 'refaliasing';
no warnings 'experimental::refaliasing';
Expand Down Expand Up @@ -1121,7 +1120,9 @@ sub _calc_nri_nti_expected_values {
sub get_nri_nti_expected_values {
my $self = shift;
my %args = @_;


require Math::BigInt;

my $tree = $args{tree_ref};
my $label_count = $args{label_count};
my $iterations = $args{nri_nti_iterations} || 4999;
Expand Down
2 changes: 1 addition & 1 deletion t/lib/Biodiverse/TestHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ sub print_indices_result_set_to_fh {

return if !$fh;

use Perl::Tidy;
require Perl::Tidy;
use Data::Dumper;

local $Data::Dumper::Purity = 1;
Expand Down

0 comments on commit f9cc027

Please sign in to comment.