develooper Front page | perl.perl5.porters | Postings from April 2007

Re: Performance problems with Hash::Util::FieldHash

Thread Previous
From:
Jerry D. Hedden
Date:
April 18, 2007 09:24
Subject:
Re: Performance problems with Hash::Util::FieldHash
Message ID:
1ff86f510704180924u1e1231ccn156dca9140edab8a@mail.gmail.com
Jerry D. Hedden wrote:
> While field hashes do a bit better than refaddr in get
> operations, stringification is the hands down winner!  Why?

Rafael Garcia-Suarez wrote:
> Probably because IIRC field hashes have an additional overhead,
> setting magic, weakening references.

Is that applicable to 'set' and 'get' accessors?

    sub get_a { $a{ $_[0] } };
    sub set_a { $a{ $_[0] } = $_[1] };

The only things going on here are to convert the object to a
hash key and then get/set the value accordingly.  The
stringified version is doing the same thing, but a whole
lot faster!

Jerry D. Hedden wrote:
> And, of course, all this pales in comparison to what
> Object::InsideOut already does.

Rafael Garcia-Suarez wrote:
> How does it work internally ?

In the fastest case, OIO uses arrays for fields and stores
the index inside the object's scalar:

    sub get_a { $a[ ${$_[0]} ] };
    sub set_a { $a[ ${$_[0]} ] = $_[1] };

It can use hashes for fields, but again, the speed
difference is still huge.  I doubt anything will beat this,
but I thought that if field hashes performed reasonably
well, it would be worthwhile to add them as an optional
feature to OIO.

Rafael Garcia-Suarez wrote:
> Profiling anyone ?

I hope someone will take this up.

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About