in reply to Re^2: RFC:Hacking Tie::File to read complex data
in thread RFC:Hacking Tie::File to read complex data

I found some inline methods in Tie::File source code with comments like "inlining read_record() would make this loop five times faster"

I noticed those too. At first I thought: "It's telling that Dominus didn't actually do the inlining", and I assumed that he had good reasons for that1. And I imagine you are glad too he didn't do it, or you would have had to override _fill_offsets() as well, copying most of the code. On the other hand, the last update to Tie::File was in 2003, so maybe he just didn't get around to it, and lost interest.

Sorry, I don't understand this point [about subclassing. rr]
I'd like to retract that point. I misread your code, and thought you had if( $_caller_pack eq __PACKAGE__ ). You use ne there, which inlines the get_next_rec only for that particular class, so that's perfectly reasonable. Had it been eq then subclasses would have gotten the inline version, and would have been unable to override get_next_rec(). I apologise for the confusion.

Your benchmark looks impressive, but I can't tell if it's because of your special record reading code, or because of your inlining. Is it really just because of the method call overhead?

Note 1: one reason being that _read_record() gets called in several places, so inlining it in that one spot would mean code duplication, which is always a maintenance problem.

Replies are listed 'Best First'.
Re^4: RFC:Hacking Tie::File to read complex data
by citromatik (Curate) on Jun 15, 2007 at 16:07 UTC

    <quote>It's telling that Dominus didn't actually do the inlining</quote>

    Yes, you are right... 1 point for Dominus!... but wait!... look at the FETCH method!!:
    sub FETCH { my ($self, $n) = @_; my $rec; # check the defer buffer $rec = $self->{deferred}{$n} if exists $self->{deferred}{$n}; $rec = $self->_fetch($n) unless defined $rec; # inlined _chomp1 substr($rec, - $self->{recseplen}) = "" if defined $rec && $self->{autochomp}; $rec; }
    Ohhh!! Inlining ahead!... he falls in the dark side of the coding force!!:
    # Chomp one record in-place; return modified record sub _chomp1 { my ($self, $rec) = @_; return $rec unless $self->{autochomp}; return unless defined $rec; substr($rec, - $self->{recseplen}) = ""; $rec; }

    :-) Sorry, it is friday!!

    Have a nice weekend!! and thanks for your comments!

    Cheers!

    citromatik