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

Performance problems with Hash::Util::FieldHash

Thread Next
From:
Jerry D. Hedden
Date:
April 18, 2007 07:31
Subject:
Performance problems with Hash::Util::FieldHash
Message ID:
1ff86f510704180731n325a71f7p950ef5a9cc6f8e8c@mail.gmail.com
I began looking at adapting Object::InsideOut to using
Hash::Util::FieldHash.  My first endeavor was to see how
fast they were.  Much to my surprise, their performance is
disappointing.  I compared simple get and set accessors for
inside-out classes using field hashes, refaddr and
stringified objects.  (See attachments.  The code is quite
simple.)

    'get' operations:
                  Rate   Refaddr FieldHash Stringify
    Refaddr   151543/s        --      -25%      -49%
    FieldHash 201418/s       33%        --      -32%
    Stringify 297227/s       96%       48%        --

    'set' operations:
                  Rate FieldHash   Refaddr Stringify
    FieldHash  79496/s        --      -49%      -74%
    Refaddr   156784/s       97%        --      -49%
    Stringify 309688/s      290%       98%        --

While field hashes do a bit better than refaddr in get
operations, stringification is the hands down winner!  Why?

I tried to speed things up a bit by borrowing the trick from
blead 28961, and replaced HUF_id with

    SV* HUF_id(SV* ref, NV cookie) {
        UV id = PTR2UV(SvRV(ref));
        return sv_2mortal(newSVpvn((char *)&id, sizeof(id)));
    }

This only have about a 10% improvement:

    'get' operations:
                  Rate   Refaddr FieldHash Stringify
    Refaddr   151543/s        --      -31%      -49%
    FieldHash 221005/s       46%        --      -25%
    Stringify 294645/s       94%       33%        --

    'set' operations:
                  Rate FieldHash   Refaddr Stringify
    FieldHash  85843/s        --      -45%      -73%
    Refaddr   155647/s       81%        --      -50%
    Stringify 312161/s      264%      101%        --

And, of course, all this pales in comparison to what
Object::InsideOut already does.

    'get' operations:
                  Rate   Refaddr FieldHash Stringify       OIO
    Refaddr   150377/s        --      -25%      -50%      -83%
    FieldHash 199990/s       33%        --      -33%      -77%
    Stringify 300178/s      100%       50%        --      -66%
    OIO       870557/s      479%      335%      190%        --

    'set' operations:
                  Rate FieldHash   Refaddr Stringify       OIO
    FieldHash  79518/s        --      -49%      -75%      -91%
    Refaddr   154844/s       95%        --      -51%      -82%
    Stringify 316440/s      298%      104%        --      -64%
    OIO       867219/s      991%      460%      174%        --

While I fully appreciate the significance of the work done
by Anno, unless something drastic can be done to improve
their performance, there doesn't seem to be any reason to
bother trying to use field hashes.

Thread Next


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