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

Re: PERL_OLD_COPY_ON_WRITE

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
December 11, 2011 12:05
Subject:
Re: PERL_OLD_COPY_ON_WRITE
Message ID:
95DD5DEF-7322-41A5-ABE3-EDAD1919517C@cpan.org

On Dec 11, 2011, at 11:40 AM, Jesse Luehrs wrote:

> On Sun, Dec 11, 2011 at 11:34:28AM -0800, Father Chrysostomos wrote:
>> sv.c contains this comment:
>> 
>> #ifndef PERL_OLD_COPY_ON_WRITE
>> 	     /* The change that added SV_COW_SHARED_HASH_KEYS makes the logic
>> 		when PERL_OLD_COPY_ON_WRITE is defined a little wrong.
>> 		Conceptually PERL_OLD_COPY_ON_WRITE being defined should
>> 		override SV_COW_SHARED_HASH_KEYS, because it means "always COW"
>> 		but in turn, it's somewhat dead code, never expected to go
>> 		live, but more kept as a placeholder on how to do it better
>> 		in a newer implementation.  */
>> 
>> What is wrong with PERL_OLD_COPY_ON_WRITE? Why wouldn’t it work the way it is written?
> 
> git blame points to here:
> 
> commit 34482cd6991b4dc2f3757baff881b50e6de59592
> Author: Nicholas Clark <nick@ccl4.org>
> Date:   Sun Nov 12 20:22:28 2006 +0000
> 
>    Change 24714 was arguably over-ambitious, in that non-core modules
>    can't be expected to know that sv_setsv() may now not "really" copy a
>    scalar. So arrange things so that COW of shared hash key scalars is
>    only done for calls within the the PERL_CORE.
> 
>    p4raw-id: //depot/perl@29248
> 
> -doy

But that does not explain why it’s ‘somewhat dead code, never expected to go live’.  It wouldn’t have to apply to XS module if it does go live.  And the commit you cite arranged flags in such a way that it *could* go live without affecting XS modules.  What I don’t understand is how it is ‘a placeholder on how to do it better’, because I don’t see the (supposedly obvious?) flaw in the current code. (Apart from the use of the UV to point to the next SV; but we could use SvLEN instead.)

I’ve been experimenting with a COW implementation that allocates strings with shared_he-shaped buffers to begin with, so they can be upgraded to real shared string scalars.  But the overhead of storing such a shared_he in the string table exceeds the cost of copying the string most of the time.  (The work wasn’t wasted.  My experiment uncovered some existing COW bugs that I fixed recently.)


Thread Previous | 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