Subject: | outputting large classes with stringification overloads using the DDS plugin is quite slow |
The DDS plugin uses Freezer to take care of classes with stringification
overloads, but for whatever reason, this doesn't seem to keep the Data
method from parsing through the entire data structure before just
outputting the stringified version. This takes up to 30 seconds for some
classes I'm using (and interrupting the print leaves me with corrupted
objects, because of the way that DDS handles cycle detection). The
attached patch skips using DDS altogether for classes with stringify
overloads - it seems to work fine here (although it doesn't output the
'$My_Class_1 = ' part that DDS does, but that doesn't particularly
bother me).
Subject: | stringify-overload.patch |
Index: Plugin/DDS.pm
===================================================================
--- Plugin/DDS.pm (revision 5228)
+++ Plugin/DDS.pm (working copy)
@@ -2,15 +2,16 @@
use Devel::REPL::Plugin;
use Data::Dump::Streamer ();
+use Scalar::Util 'blessed';
around 'format_result' => sub {
my $orig = shift;
my $self = shift;
my $to_dump = (@_ > 1) ? [@_] : $_[0];
my $out;
- if (ref $to_dump) {
+ # don't call DDS at all if we're just going to take the stringify overload
+ if (ref $to_dump && !(blessed $to_dump && $to_dump->can('(""'))) {
my $dds = Data::Dump::Streamer->new;
- $dds->Freezer(sub { "$_[0]"; });
$dds->Data($to_dump);
$out = $dds->Out;
} else {