subs and variables speed question

Hi All,

sub xxx( Buf $YugeBuf is ro ) {some midricle}

Is $YugeBuf (up to 100 MB) a copy of just the structure?
I don't want the time time of a copy.


Many thanks,
-T
0
perl6
2/9/2019 9:56:37 PM
perl.perl6.users 1202 articles. 0 followers. Follow

9 Replies
75 Views

Similar Articles

[PageSpeed] 29

On 2/9/19 1:56 PM, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> sub xxx( Buf $YugeBuf is ro ) {some midricle}
> 
> Is $YugeBuf (up to 100 MB) a copy of just the structure?
> I don't want the time time of a copy.
> 
> 
> Many thanks,
> -T

Without all the typos:

Hi All,

sub xxx( Buf $YugeBuf is ro ) {some miricle}

Is $YugeBuf (up to 100 MB) a copy of the entire variable
or just the structure?  I don't want the time hit of a copy.

Many thanks,
-T
0
perl6
2/9/2019 10:28:28 PM
On 2/9/19 2:28 PM, ToddAndMargo via perl6-users wrote:
> On 2/9/19 1:56 PM, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> sub xxx( Buf $YugeBuf is ro ) {some midricle}
>>
>> Is $YugeBuf (up to 100 MB) a copy of just the structure?
>> I don't want the time time of a copy.
>>
>>
>> Many thanks,
>> -T
>=20
> Without all the typos:
>=20
> Hi All,
>=20
> sub xxx( Buf $YugeBuf is ro ) {some miricle}
>=20
> Is $YugeBuf (up to 100 MB) a copy of the entire variable
> or just the structure?=C2=A0 I don't want the time hit of a copy.
>=20
> Many thanks,
> -T


It is not a duplicate:

[20:30] <ToddAndMargo> A question for the developers.  sub xxx( Buf=20
$YugeBuf is ro ) {some miricle}     Is $YugeBuf (up to 100 MB) a copy of =

the entire variable or just the structure?  I don't want the time hit of =

a copy
[20:32] =3D=3D Cabanossi=20
[~Cabanossi@ppp-88-217-73-102.dynamic.mnet-online.de] has joined #perl6
[20:36] =3D=3D kurahaupo_=20
[~kurahaupo@pa49-195-197-60.pa.nsw.optusnet.com.au] has joined #perl6
[20:36] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has quit [Read error:=
=20
Connection reset by peer]
[20:36] <guifa> ToddAndMargo: it seems to be
[20:37] =3D=3D kurahaupo_=20
[~kurahaupo@pa49-195-197-60.pa.nsw.optusnet.com.au] has quit [Read=20
error: Connection reset by peer]
[20:38] <guifa> p6: sub a (Buf $b) { say $b.WHERE }; my $c =3D=20
Buf.new(1,2,3); say $c.WHERE; a($c)
[20:38] <+camelia> rakudo-moar d904b7048: OUTPUT:=20
=C2=AB139828431461220=E2=90=A4139828431461220=E2=90=A4=C2=BB
[20:39] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has joined #perl6
[20:45] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has quit [Read error:=
=20
Connection reset by peer]
[20:45] <guifa> Err, I meant that to be "Buf $b is readonly" but result=20
is the same.
[20:46] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has joined #perl6
[20:48] =3D=3D aindilis=20
[~aindilis@172-12-3-117.lightspeed.sgnwmi.sbcglobal.net] has quit [Ping=20
timeout: 240 seconds]
[20:49] <guifa> Even when you use "is copy", the copy doesn't get made=20
until after the value has been modified.  Seems Rakudo is smart in that=20
regards:
[20:49] <guifa> p6: sub a ($a is copy) { say $a.WHERE; $a++; say=20
$a.WHERE}; my $b =3D 1; say $b.WHERE; a($b)
[20:49] <+camelia> rakudo-moar d904b7048: OUTPUT:=20
=C2=AB140226293132168=E2=90=A4140226293132168=E2=90=A4140226293132208=E2=90=
=A4=C2=BB
[20:49] =3D=3D aindilis=20
[~aindilis@172-12-3-117.lightspeed.sgnwmi.sbcglobal.net] has joined #perl=
6
[20:53] <guifa> Just be aware that readonly doesn't necessarily mean=20
what you might think it does:
[20:53] <guifa> p6: sub a (Buf $b is readonly) { $b[0] =3D 0}; my $c =3D =

Buf.new(1,2,3); a($c); say $c
[20:53] <+camelia> rakudo-moar d904b7048: OUTPUT: =C2=ABBuf:0x<00 02 03>=E2=
=90=A4=C2=BB
0
perl6
2/11/2019 6:07:34 AM
WHERE is pretty sweet command!


$ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c = 
Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'

7F385D41334C
7F385D41334C
0
perl6
2/11/2019 6:12:04 AM
On 2/9/19 2:28 PM, ToddAndMargo via perl6-users wrote:
> On 2/9/19 1:56 PM, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> sub xxx( Buf $YugeBuf is ro ) {some midricle}
>>
>> Is $YugeBuf (up to 100 MB) a copy of just the structure?
>> I don't want the time time of a copy.
>>
>>
>> Many thanks,
>> -T
>=20
> Without all the typos:
>=20
> Hi All,
>=20
> sub xxx( Buf $YugeBuf is ro ) {some miricle}
>=20
> Is $YugeBuf (up to 100 MB) a copy of the entire variable
> or just the structure?=C2=A0 I don't want the time hit of a copy.
>=20
> Many thanks,
> -T


It is not a duplicate:

[20:30] <ToddAndMargo> A question for the developers.  sub xxx( Buf=20
$YugeBuf is ro ) {some miricle}     Is $YugeBuf (up to 100 MB) a copy of =

the entire variable or just the structure?  I don't want the time hit of =

a copy
[20:32] =3D=3D Cabanossi=20
[~Cabanossi@ppp-88-217-73-102.dynamic.mnet-online.de] has joined #perl6
[20:36] =3D=3D kurahaupo_=20
[~kurahaupo@pa49-195-197-60.pa.nsw.optusnet.com.au] has joined #perl6
[20:36] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has quit [Read error:=
=20
Connection reset by peer]
[20:36] <guifa> ToddAndMargo: it seems to be
[20:37] =3D=3D kurahaupo_=20
[~kurahaupo@pa49-195-197-60.pa.nsw.optusnet.com.au] has quit [Read=20
error: Connection reset by peer]
[20:38] <guifa> p6: sub a (Buf $b) { say $b.WHERE }; my $c =3D=20
Buf.new(1,2,3); say $c.WHERE; a($c)
[20:38] <+camelia> rakudo-moar d904b7048: OUTPUT:=20
=C2=AB139828431461220=E2=90=A4139828431461220=E2=90=A4=C2=BB
[20:39] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has joined #perl6
[20:45] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has quit [Read error:=
=20
Connection reset by peer]
[20:45] <guifa> Err, I meant that to be "Buf $b is readonly" but result=20
is the same.
[20:46] =3D=3D kurahaupo [~kurahaupo@125.254.10.75] has joined #perl6
[20:48] =3D=3D aindilis=20
[~aindilis@172-12-3-117.lightspeed.sgnwmi.sbcglobal.net] has quit [Ping=20
timeout: 240 seconds]
[20:49] <guifa> Even when you use "is copy", the copy doesn't get made=20
until after the value has been modified.  Seems Rakudo is smart in that=20
regards:
[20:49] <guifa> p6: sub a ($a is copy) { say $a.WHERE; $a++; say=20
$a.WHERE}; my $b =3D 1; say $b.WHERE; a($b)
[20:49] <+camelia> rakudo-moar d904b7048: OUTPUT:=20
=C2=AB140226293132168=E2=90=A4140226293132168=E2=90=A4140226293132208=E2=90=
=A4=C2=BB
[20:49] =3D=3D aindilis=20
[~aindilis@172-12-3-117.lightspeed.sgnwmi.sbcglobal.net] has joined #perl=
6
[20:53] <guifa> Just be aware that readonly doesn't necessarily mean=20
what you might think it does:
[20:53] <guifa> p6: sub a (Buf $b is readonly) { $b[0] =3D 0}; my $c =3D =

Buf.new(1,2,3); a($c); say $c
[20:53] <+camelia> rakudo-moar d904b7048: OUTPUT: =C2=ABBuf:0x<00 02 03>=E2=
=90=A4=C2=BB
0
perl6
2/11/2019 6:19:05 AM
Please be aware that WHERE will give you the actual memory address of an
object, but moarvm has a moving garbage collector, which means that
objects can change their memory location. at the moment it will only
happen up to two times, i believe.

you'll probably have a better result with .WHICH for what you want to
achieve.

On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
> WHERE is pretty sweet command!
>
>
> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =
> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>
> 7F385D41334C
> 7F385D41334C
0
timo
2/11/2019 10:52:50 AM
On 2/11/19 2:52 AM, Timo Paulssen wrote:
> Please be aware that WHERE will give you the actual memory address of an
> object, but moarvm has a moving garbage collector, which means that
> objects can change their memory location. at the moment it will only
> happen up to two times, i believe.
> 
> you'll probably have a better result with .WHICH for what you want to
> achieve.
> 
> On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
>> WHERE is pretty sweet command!
>>
>>
>> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =
>> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>>
>> 7F385D41334C
>> 7F385D41334C

$ p6 'sub a (Buf $b) { say $b.WHICH.base(0x10) }; my $c = 
Buf.new(1,2,3); say $c.WHICH.base(0x10); a($c);'
No such method 'base' for invocant of type 'ObjAt'. Did you mean any of 
these?
     Hash
     hash
     take

   in block <unit> at -e line 1



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
2/11/2019 11:16:52 AM
WHICH doesn't give you a numerical value. just print it as it is.

On 11/02/2019 12:16, ToddAndMargo via perl6-users wrote:
> On 2/11/19 2:52 AM, Timo Paulssen wrote:
>> Please be aware that WHERE will give you the actual memory address of =
an
>> object, but moarvm has a moving garbage collector, which means that
>> objects can change their memory location. at the moment it will only
>> happen up to two times, i believe.
>>
>> you'll probably have a better result with .WHICH for what you want to
>> achieve.
>>
>> On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
>>> WHERE is pretty sweet command!
>>>
>>>
>>> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =3D
>>> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>>>
>>> 7F385D41334C
>>> 7F385D41334C
>
> $ p6 'sub a (Buf $b) { say $b.WHICH.base(0x10) }; my $c =3D
> Buf.new(1,2,3); say $c.WHICH.base(0x10); a($c);'
> No such method 'base' for invocant of type 'ObjAt'. Did you mean any
> of these?
> =C2=A0=C2=A0=C2=A0 Hash
> =C2=A0=C2=A0=C2=A0 hash
> =C2=A0=C2=A0=C2=A0 take
>
> =C2=A0 in block <unit> at -e line 1
>
>
>
0
timo
2/11/2019 11:27:53 AM
>>> On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
>>>> WHERE is pretty sweet command!
>>>>
>>>>
>>>> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =
>>>> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>>>>
>>>> 7F385D41334C
>>>> 7F385D41334C


> On 11/02/2019 12:16, ToddAndMargo via perl6-users wrote:
>> On 2/11/19 2:52 AM, Timo Paulssen wrote:
>>> Please be aware that WHERE will give you the actual memory address of an
>>> object, but moarvm has a moving garbage collector, which means that
>>> objects can change their memory location. at the moment it will only
>>> happen up to two times, i believe.
>>>
>>> you'll probably have a better result with .WHICH for what you want to
>>> achieve.

 >>
 >> $ p6 'sub a (Buf $b) { say $b.WHICH.base(0x10) }; my $c =
 >> Buf.new(1,2,3); say $c.WHICH.base(0x10); a($c);'
 >> No such method 'base' for invocant of type 'ObjAt'. Did you mean any
 >> of these?
 >>      Hash
 >>      hash
 >>      take
 >>
 >>    in block <unit> at -e line 1
 >>
 >>

On 2/11/19 3:27 AM, Timo Paulssen wrote:
 > WHICH doesn't give you a numerical value. just print it as it is.


$ p6 'sub a (Buf $b) { say $b.WHICH }; my $c = Buf.new(1,2,3); say 
$c.WHICH; a($c);'
Buf|71848984
Buf|71848984

If "moarvm has a moving garbage collector" moves my 100 MB+ buffer 
around, "I am in a heap of trouble".
0
perl6
2/11/2019 5:32:01 PM
> On 2/11/19 3:27 AM, Timo Paulssen wrote:
> > WHICH doesn't give you a numerical value. just print it as it is.
>
>
> $ p6 'sub a (Buf $b) { say $b.WHICH }; my $c = Buf.new(1,2,3); say
> $c.WHICH; a($c);'
> Buf|71848984
> Buf|71848984
>
> If "moarvm has a moving garbage collector" moves my 100 MB+ buffer
> around, "I am in a heap of trouble".
The buffer lives one indirection (aka pointer) away from the part that
is garbage-collector managed, so moving the object doesn't make a
difference here, luckily.
0
timo
2/11/2019 8:51:30 PM
Reply: