Skip to content

Commit

Permalink
Split off to-millis(,True) into to-millis-allow-zero
Browse files Browse the repository at this point in the history
This speeds up cueing of start { } blocks a bit and saves one Scalar allocation
per cue.  First part of more refactoring on ThreadPoolScheduler.cue, which
currently takes 6.5% of CPU on 'await do for ^100000 { start { } }'
  • Loading branch information
lizmat committed Mar 30, 2018
1 parent b9906ab commit b22421e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/core/ThreadPoolScheduler.pm6
Expand Up @@ -835,18 +835,28 @@ my class ThreadPoolScheduler does Scheduler {
die "Cannot specify :every, :times and :stop at the same time"
if $every.defined and $times > 1 and &stop;

# For $in/$at times, if the resultant delay is less than 0.001 (including
# negatives) equate those to zero. For $every intervals, we convert
# such values to minimum resolution of 0.001 and warn about that
sub to-millis(Numeric() $value, $allow-zero = False) {
my $proposed := (1000 * $value).Int;
$proposed > 0 ?? $proposed
!! $allow-zero ?? 0
!! do {warn "Minimum timer resolution is 1ms; using that "
~ "instead of {1000 * $value}ms";
1}
# For $in/$at times, if the resultant delay is less than 0.001
# (including negatives) equate those to zero. For $every intervals,
# we convert such values to minimum resolution of 0.001 and warn
# about that
sub to-millis(Numeric() $value) {
nqp::if(
nqp::isgt_i((my int $proposed = (1000 * $value).Int),0),
$proposed,
nqp::stmts(
warn("Minimum timer resolution is 1ms; using that instead of {1000 * $value}ms"),
1
)
)
}
sub to-millis-allow-zero(Numeric() $value) {
nqp::if(
nqp::isgt_i((my int $proposed = (1000 * $value).Int),0),
$proposed
# not true == 0 == what we need
)
}
my $delay = to-millis ($at ?? $at - now !! $in // 0), True;
my $delay = to-millis-allow-zero($at ?? $at - now !! $in // 0);

# Wrap any catch handler around the code to run.
my &run := &catch ?? wrap-catch(&code, &catch) !! &code;
Expand Down

0 comments on commit b22421e

Please sign in to comment.