Subject: | Overloading results in progressively degraded performance while adding rows to a table in a loop |
Date: | Wed, 27 Jul 2016 08:44:26 -0400 |
To: | bug-text-table [...] rt.cpan.org |
From: | Zac Bentley <zbbentley [...] gmail.com> |
This is a reference to Github issue #3:
https://github.com/shlomif/Text-Table/issues/3
If I loop and add one row at a time to a table that will eventually contain
thousands of rows, while checking (via if ($table)) if a table exists
before adding data, I see performance of add or loaddegrade as a function
of the square of the number of rows (perl 5.16, strict/warnings, x86-64
linux).
The table I'm working with has a handful of columns and pretty ordinary
data (plus some ASCII colors) in the rows; cells are at most 20chr wide.
This appears to be because too many caller contexts get overloaded to call
$table->stringify . . . *even contexts where stringification is not
necessary*. As a result, code that calls my $data = get_data(); if ( $table
&& $data ) { $table->load($data); } in a long loop is actually calling the
stringification function for the table each time the loop spins.
This results (at row 1) in iterations being fast, and later (at row 1000)
in iterations sometimes taking more than a second.
This seems undesirable.