| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/KiokuDB/Collapser/Buffer.pm |
| Statements | Executed 23 statements in 5.68ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 13.6ms | 17.4ms | KiokuDB::Collapser::Buffer::BEGIN@5 |
| 1 | 1 | 1 | 124µs | 338µs | KiokuDB::Collapser::Buffer::BEGIN@4 |
| 1 | 1 | 1 | 76µs | 21.4ms | KiokuDB::Collapser::Buffer::BEGIN@2 |
| 1 | 1 | 1 | 44µs | 1.61ms | KiokuDB::Collapser::Buffer::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:100] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:106] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:18] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:37] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:43] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:60] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:75] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::__ANON__[:92] |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::commit |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::compact_data |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::compact_entries |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::compact_entry |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::id_to_entry |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::id_to_object |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::imply_root |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::insert |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::insert_entry |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::insert_intrinsic |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::insert_to_backend |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::intrinsic_entry |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::merged_objects_to_ids |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::object_to_id |
| 0 | 0 | 0 | 0s | 0s | KiokuDB::Collapser::Buffer::update_entries |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package KiokuDB::Collapser::Buffer; | ||||
| 2 | 3 | 224µs | 2 | 42.8ms | # spent 21.4ms (76µs+21.3) within KiokuDB::Collapser::Buffer::BEGIN@2 which was called:
# once (76µs+21.3ms) by KiokuDB::Collapser::BEGIN@15 at line 2 # spent 21.4ms making 1 call to KiokuDB::Collapser::Buffer::BEGIN@2
# spent 21.3ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:456] |
| 3 | |||||
| 4 | 3 | 118µs | 2 | 393µs | # spent 338µs (124+214) within KiokuDB::Collapser::Buffer::BEGIN@4 which was called:
# once (124µs+214µs) by KiokuDB::Collapser::BEGIN@15 at line 4 # spent 338µs making 1 call to KiokuDB::Collapser::Buffer::BEGIN@4
# spent 55µs making 1 call to Hash::Util::FieldHash::Compat::import |
| 5 | 3 | 778µs | 2 | 17.5ms | # spent 17.4ms (13.6+3.81) within KiokuDB::Collapser::Buffer::BEGIN@5 which was called:
# once (13.6ms+3.81ms) by KiokuDB::Collapser::BEGIN@15 at line 5 # spent 17.4ms making 1 call to KiokuDB::Collapser::Buffer::BEGIN@5
# spent 106µs making 1 call to Exporter::import |
| 6 | |||||
| 7 | 3 | 4.18ms | 2 | 3.18ms | # spent 1.61ms (44µs+1.57) within KiokuDB::Collapser::Buffer::BEGIN@7 which was called:
# once (44µs+1.57ms) by KiokuDB::Collapser::BEGIN@15 at line 7 # spent 1.61ms making 1 call to KiokuDB::Collapser::Buffer::BEGIN@7
# spent 1.57ms making 1 call to namespace::clean::import |
| 8 | |||||
| 9 | 1 | 14µs | 1 | 10.1ms | has live_objects => ( # spent 10.1ms making 1 call to Moose::has |
| 10 | isa => "KiokuDB::LiveObjects", | ||||
| 11 | is => "ro", | ||||
| 12 | required => 1, | ||||
| 13 | ); | ||||
| 14 | |||||
| 15 | has _objects => ( | ||||
| 16 | isa => "HashRef", | ||||
| 17 | is => "ro", | ||||
| 18 | default => sub { idhash my %hash }, | ||||
| 19 | 1 | 21µs | 1 | 8.08ms | ); # spent 8.08ms making 1 call to Moose::has |
| 20 | |||||
| 21 | sub object_to_id { | ||||
| 22 | my ( $self, $object ) = @_; | ||||
| 23 | $self->_objects->{$object}; | ||||
| 24 | } | ||||
| 25 | |||||
| 26 | sub merged_objects_to_ids { | ||||
| 27 | my ( $self, @objects ) = @_; | ||||
| 28 | |||||
| 29 | my $l = $self->live_objects; | ||||
| 30 | |||||
| 31 | map { $self->object_to_id($_) || $l->object_to_id($_) } @objects; | ||||
| 32 | } | ||||
| 33 | |||||
| 34 | has _ids => ( | ||||
| 35 | isa => "HashRef", | ||||
| 36 | is => "ro", | ||||
| 37 | default => sub { return {} }, | ||||
| 38 | 1 | 21µs | 1 | 7.74ms | ); # spent 7.74ms making 1 call to Moose::has |
| 39 | |||||
| 40 | has _entry_args => ( | ||||
| 41 | isa => "HashRef", | ||||
| 42 | is => "ro", | ||||
| 43 | default => sub { return {} }, | ||||
| 44 | 1 | 20µs | 1 | 7.92ms | ); # spent 7.92ms making 1 call to Moose::has |
| 45 | |||||
| 46 | sub id_to_object { | ||||
| 47 | my ( $self, $id ) = @_; | ||||
| 48 | |||||
| 49 | if ( defined ( my $obj = $self->_ids->{$id} ) ) { | ||||
| 50 | return $obj; | ||||
| 51 | } else { | ||||
| 52 | return $self->live_objects->id_to_object($id); | ||||
| 53 | } | ||||
| 54 | } | ||||
| 55 | |||||
| 56 | has entries => ( | ||||
| 57 | traits => ["Hash"], | ||||
| 58 | isa => "HashRef", | ||||
| 59 | reader => "_entries", | ||||
| 60 | default => sub { return {} }, | ||||
| 61 | 1 | 33µs | 1 | 371ms | handles => { # spent 371ms making 1 call to Moose::has |
| 62 | entries => "values", | ||||
| 63 | ids => "keys", | ||||
| 64 | }, | ||||
| 65 | ); | ||||
| 66 | |||||
| 67 | sub id_to_entry { | ||||
| 68 | my ( $self, $id ) = @_; | ||||
| 69 | $self->_entries->{$id}; | ||||
| 70 | } | ||||
| 71 | |||||
| 72 | has intrinsic => ( | ||||
| 73 | isa => "HashRef", | ||||
| 74 | is => "ro", | ||||
| 75 | default => sub { idhash my %hash }, | ||||
| 76 | 1 | 20µs | 1 | 8.04ms | ); # spent 8.04ms making 1 call to Moose::has |
| 77 | |||||
| 78 | sub intrinsic_entry { | ||||
| 79 | my ( $self, $obj ) = @_; | ||||
| 80 | $self->intrinsic->{$obj}; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | sub insert_intrinsic { | ||||
| 84 | my ( $self, $object, $entry ) = @_; | ||||
| 85 | $self->intrinsic->{$object} = $entry; | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | # a list of the IDs of all simple entries | ||||
| 89 | has simple_entries => ( | ||||
| 90 | isa => 'ArrayRef', | ||||
| 91 | is => "ro", | ||||
| 92 | default => sub { [] }, | ||||
| 93 | 1 | 22µs | 1 | 8.10ms | ); # spent 8.10ms making 1 call to Moose::has |
| 94 | |||||
| 95 | # first_class keeps track of the simple references which are first class | ||||
| 96 | # (either weak or shared, and must have an entry) | ||||
| 97 | has first_class => ( | ||||
| 98 | isa => 'Set::Object', | ||||
| 99 | is => "ro", | ||||
| 100 | default => sub { Set::Object->new }, | ||||
| 101 | 1 | 21µs | 1 | 8.78ms | ); # spent 8.78ms making 1 call to Moose::has |
| 102 | |||||
| 103 | has options => ( | ||||
| 104 | isa => 'HashRef', | ||||
| 105 | is => "ro", | ||||
| 106 | default => sub { {} }, | ||||
| 107 | 1 | 19µs | 1 | 8.14ms | ); # spent 8.14ms making 1 call to Moose::has |
| 108 | |||||
| 109 | sub insert { | ||||
| 110 | my ( $self, $id, $object, @args ) = @_; | ||||
| 111 | |||||
| 112 | $self->_objects->{$object} = $id; | ||||
| 113 | $self->_ids->{$id} = $object; | ||||
| 114 | $self->_entry_args->{$id} = \@args if @args; | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | sub insert_entry { | ||||
| 118 | my ( $self, $id, $entry, $object, @args ) = @_; | ||||
| 119 | |||||
| 120 | $self->_entries->{$id} = $entry; | ||||
| 121 | $self->insert($id, $object, @args); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | sub compact_entries { | ||||
| 125 | my $self = shift; | ||||
| 126 | |||||
| 127 | my ( $entries, $fc, $simple, $options ) = ( $self->_entries, $self->first_class, $self->simple_entries, $self->options ); | ||||
| 128 | |||||
| 129 | # unify non shared simple references | ||||
| 130 | if ( my @flatten = grep { not $fc->includes($_) } @$simple ) { | ||||
| 131 | my %flatten; | ||||
| 132 | @flatten{@flatten} = delete @{$entries}{@flatten}; | ||||
| 133 | |||||
| 134 | $self->compact_entry($_, \%flatten) for values %$entries; | ||||
| 135 | } | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | sub compact_entry { | ||||
| 139 | my ( $self, $entry, $flatten ) = @_; | ||||
| 140 | |||||
| 141 | my $data = $entry->data; | ||||
| 142 | |||||
| 143 | if ( $self->compact_data($data, $flatten) ) { | ||||
| 144 | $entry->_data($data); | ||||
| 145 | } | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | sub compact_data { | ||||
| 149 | my ( $self, $data, $flatten ) = @_; | ||||
| 150 | |||||
| 151 | if ( ref $data eq 'KiokuDB::Reference' ) { | ||||
| 152 | my $id = $data->id; | ||||
| 153 | |||||
| 154 | if ( my $entry = $flatten->{$id} ) { | ||||
| 155 | # replace reference with data from entry, so that the | ||||
| 156 | # simple data is inlined, and mark that entry for removal | ||||
| 157 | $self->compact_entry($entry, $flatten); | ||||
| 158 | |||||
| 159 | if ( $entry->tied or $entry->class ) { | ||||
| 160 | $entry->clear_id; | ||||
| 161 | $_[1] = $entry; | ||||
| 162 | } else { | ||||
| 163 | $_[1] = $entry->data; | ||||
| 164 | } | ||||
| 165 | return 1; | ||||
| 166 | } | ||||
| 167 | } elsif ( ref($data) eq 'ARRAY' ) { | ||||
| 168 | ref && $self->compact_data($_, $flatten) for @$data; | ||||
| 169 | } elsif ( ref($data) eq 'HASH' ) { | ||||
| 170 | ref && $self->compact_data($_, $flatten) for values %$data; | ||||
| 171 | } elsif ( ref($data) eq 'SCALAR' || ref($data) eq 'REF' ) { | ||||
| 172 | $self->compact_data($$data, $flatten); | ||||
| 173 | } elsif ( ref($data) eq 'KiokuDB::Entry' ) { | ||||
| 174 | $self->compact_entry($data, $flatten); | ||||
| 175 | } else { | ||||
| 176 | # passthrough | ||||
| 177 | } | ||||
| 178 | |||||
| 179 | return; | ||||
| 180 | } | ||||
| 181 | |||||
| 182 | sub imply_root { | ||||
| 183 | my ( $self, @ids ) = @_; | ||||
| 184 | |||||
| 185 | my $entries = $self->_entries; | ||||
| 186 | |||||
| 187 | foreach my $id ( @ids ) { | ||||
| 188 | my $entry = $entries->{$id} or next; | ||||
| 189 | next if $entry->has_root; # set by typemap | ||||
| 190 | $entry->root(1); | ||||
| 191 | } | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | sub commit { | ||||
| 195 | my ( $self, $backend ) = @_; | ||||
| 196 | |||||
| 197 | $self->insert_to_backend($backend); | ||||
| 198 | $self->update_entries( in_storage => 1 ); | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | sub insert_to_backend { | ||||
| 202 | my ( $self, $backend ) = @_; | ||||
| 203 | |||||
| 204 | $backend->insert(values %{ $self->_entries }); | ||||
| 205 | } | ||||
| 206 | |||||
| 207 | sub update_entries { | ||||
| 208 | my ( $self, @shared_args ) = @_; | ||||
| 209 | |||||
| 210 | my ( $e, $o ) = ( $self->_entries, $self->_ids ); | ||||
| 211 | |||||
| 212 | my $l = $self->live_objects; | ||||
| 213 | |||||
| 214 | my $args = $self->_entry_args; | ||||
| 215 | |||||
| 216 | foreach my $id ( keys %$e ) { | ||||
| 217 | my ( $object, $entry ) = ( $o->{$id}, $e->{$id} ); | ||||
| 218 | |||||
| 219 | my @args = @{ $args->{$id} || [] }; # FIXME XXX FIXME FIXME XXX BLAH BLAH | ||||
| 220 | |||||
| 221 | $l->register_entry( $id => $entry, @shared_args ); | ||||
| 222 | |||||
| 223 | unless ( $l->object_to_id($object) ) { | ||||
| 224 | $l->register_object( $id => $object, @args ); | ||||
| 225 | } else { | ||||
| 226 | $l->update_object_entry( $object, $entry, @args ); | ||||
| 227 | } | ||||
| 228 | } | ||||
| 229 | } | ||||
| 230 | |||||
| 231 | 1 | 25µs | 2 | 31.9ms | __PACKAGE__->meta->make_immutable; # spent 31.8ms making 1 call to Class::MOP::Class::make_immutable
# spent 99µs making 1 call to KiokuDB::Collapser::Buffer::meta |
| 232 | |||||
| 233 | 1 | 96µs | __PACKAGE__ | ||
| 234 | |||||
| 235 | 1 | 69µs | 1 | 4.66ms | __END__ # spent 4.66ms making 1 call to B::Hooks::EndOfScope::__ANON__[B/Hooks/EndOfScope.pm:26] |