Skip to content

Commit

Permalink
Micro optimize the Awaitable role
Browse files Browse the repository at this point in the history
Using private methods in roles still incurs a substantial runtime
overhead.  By making the private methods public with UPPER_CASE names,
we make the following code 10% faster with 5% fewer allocations:

  await do for ^100000 { start { } }
  • Loading branch information
lizmat committed Apr 2, 2018
1 parent 7327a33 commit 266f4a2
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/core/Awaitable.pm6
Expand Up @@ -25,19 +25,18 @@ my role Awaitable::Handle {
has Exception $.cause;

method already-success(Mu \result) {
nqp::create(self)!already-success(result)
nqp::create(self).ALREADY_SUCCESS(result)
}
method !already-success(Mu \result) {
$!already := True;
$!success := True;
method ALREADY_SUCCESS(Mu \result) {
$!already := $!success := True;
$!result := result;
self
}

method already-failure(Mu \cause) {
self.CREATE!already-failure(cause)
nqp::create(self).ALREADY_FAILURE(cause)
}
method !already-failure(Mu \cause) {
method ALREADY_FAILURE(Mu \cause) {
$!already := True;
$!success := False;
$!cause := cause;
Expand Down

0 comments on commit 266f4a2

Please sign in to comment.