> Setting a flag on the object to not run validity checks is one option, and safer than a global variable.

OP here, thanks for the replies. By "global" I meant to somehow disable all the slow sanity checks in Imager.pm. Methods like setpixel and getpixel are likely to be called a lot inside loops. Disabling the call to _valid_image on each pixel seems pretty safe so far and is a big gain. Since _valid_image is called in almost every method in Imager.pm they can all be fixed on line 658:

sub _valid_image { return 1;
The second hack that skips the call to _color is crude because it disables dwim on the color attribute of setpixel (color=>'blue') and requires it be supplied with an Imager::Color object (color=>Imager::Color->new('blue')). Doing that right would require more work but it hasn't broken my code so far while patching a live copy of Imager.pm. Probably because it was noticed long ago that dwim colors are to be avoided because setpixel is 2-3x faster when using color objects with rgb arrays like Imager::Color->new([255,0,0]).

In reply to Re^2: Double the speed of Imager->setpixel by Anonymous Monk
in thread Double the speed of Imager->setpixel by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.