# New Ticket Created by David Warring
# Please include the string: [perl #126520]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=126520 >
Consider the following, which should be a simple and conventional use of Perl 6
Proxy objects:
class C {
has $!foo;
method foo is rw {
say "foo";
$!foo;
}
has $!bar;
method bar is rw {
Proxy.new(
say "proxy new";
FETCH => sub ($) {
say "bar fetch";
$!bar
},
STORE => sub ($, $v) {
say "bar store";
$!bar = $v;
},
);
}
}
my $c = C.new;
say "FETCHES";
$c.foo;
$c.bar;
say "STORES";
$c.foo++;
$c.bar++;
OUTPUT:
FETCHES
foo
proxy new
bar fetch
bar fetch
bar fetch
STORES
foo
proxy new
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar store
===================
In the above example, the bar proxy is called 10x whereas foo is called twice.
In particular, the proxy FETCH is called 7X to do a simple increment.
I'm raising this because this is the 'hot path' in projects such as
https://github.com/p6-pdf/perl6-PDF-Tools.
Would like to see this reduced, if possible.