shlomif / Text-Table

CPAN Distribution to render text / ASCII-art / Unicode tables
https://metacpan.org/release/Text-Table
ISC License
4 stars 6 forks source link

Overloading results in progressively degraded performance while adding rows to a table in a loop #3

Closed zbentley closed 8 years ago

zbentley commented 8 years ago

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 load degrade 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.

zbentley commented 8 years ago

Added context: this is due to a boolean operation performed on the table, e.g. if ( $table ) { $table->add(...); }.

Why is stringification happening in boolean pseudocontext?