From b22421e7e9e9c6609e9ee979ac9d02da2a1eabdf Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Fri, 30 Mar 2018 12:19:32 +0200 Subject: [PATCH] Split off to-millis(,True) into to-millis-allow-zero 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 { } }' --- src/core/ThreadPoolScheduler.pm6 | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/core/ThreadPoolScheduler.pm6 b/src/core/ThreadPoolScheduler.pm6 index e1697b1019a..3e2b3cdba77 100644 --- a/src/core/ThreadPoolScheduler.pm6 +++ b/src/core/ThreadPoolScheduler.pm6 @@ -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;