Skip to content

Commit

Permalink
Save 2 Scalar containers per Promise.new
Browse files Browse the repository at this point in the history
GC runs from 18 -> 14 for Promise.new for ^50000

No change for subclasses of Promise
  • Loading branch information
lizmat committed Aug 31, 2021
1 parent 94462df commit 3aba970
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/core.c/Promise.pm6
Expand Up @@ -41,10 +41,24 @@ my class Promise does Awaitable {
has Mu $!dynamic_context;
has Bool $!report-broken-if-sunk;

method !SET-SELF(\scheduler, \report) {
$!scheduler := scheduler;
$!report-broken-if-sunk := nqp::if(nqp::istrue(report),True,False);
$!lock := nqp::create(Lock);
$!cond := $!lock.condition;
$!status := Planned;
$!thens := nqp::list;
self
}
submethod new(:$scheduler = $*SCHEDULER, :$report-broken-if-sunk) {
my \p = nqp::create(self);
p.BUILD(:$scheduler, :$report-broken-if-sunk);
p
if nqp::eqaddr(self,Promise) {
nqp::create(self)!SET-SELF($scheduler, $report-broken-if-sunk)
}
else {
my \p = nqp::create(self);
p.BUILD(:$scheduler, :$report-broken-if-sunk);
p
}
}

submethod BUILD(:$!scheduler = $*SCHEDULER, :$report-broken-if-sunk --> Nil) {
Expand Down

0 comments on commit 3aba970

Please sign in to comment.