develooper Front page | perl.perl5.porters | Postings from December 2009

[PATCH 0/3] MAGIC fixes

Thread Next
From:
Chip Salzenberg
Date:
December 5, 2009 21:23
Subject:
[PATCH 0/3] MAGIC fixes
Message ID:
20091206052327.GE5454@tytlal.topaz.cx
Long rumored, here are the fixes for MAGIC + utf8 slowdown.

Some time ago, production usage of Perl at Topsy fell afoul a bug in utf8
attribute caching in 5.10.1.  The bug manifested as lvalue substr() getting
slower and Slower and SLOWER over time.  Turns out the SVt_PVLV target for
the opcode had a MAGIC chain that was getting longer and Longer and LONGER.

The fundamental bug comes down to this:

  You can't trust SvMAGICAL.

When calling MAGIC vtable entries, perl temporarily turns off SvMAGICAL,
presumably with the intent of avoiding recursion.  So if you find SvMAGICAL
to be false, and conclude as a result that the MAGIC you're looking for is
not there ... well, that could be a mistake.  Sadly that mistake was made by
the utf8 caching code.

The fix takes three parts.

[1/3] The code to save and restore the magical flags had been tweaked over
time to save and restore SvREADONLY as well - but when the saved magical
flags were cleared, SvREADONLY was also cleared by accident.  That's fixed.

[2/3] When MAGIC is removed, the previous code was not careful to disable
MAGICAL flags that no longer applied.  That's fixed.

[3/3] The fix for the infinitely growing MAGIC chain in utf8 caching.

Share & Enjoy!

-- 
Chip Salzenberg

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