New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"if" without "else" much slower than "if" with empty "else" #6025
Comments
From alex6k@yahoo.comTake a look at the following examples - the second is more than 10x(!!!) faster: In my understanding of https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Actions.nqp#L1675 the first example is equivalent to: m: my int $i = 0; loop { if $i++ == 10_000_000 { last } else { Empty } }; say now - INIT now; |
From @zoffixznetOn Sat, 21 Jan 2017 11:45:10 -0800, alex6k@yahoo.com wrote:
That's because the two examples you are comparing are entirely different. The case with implicit or explicit Empty can <Zoffix> m: sub stuff { if 0 {} }; dd [1, stuff(), 4] But the explicit `else {}` results in a Nil, which leaves unwanted stuff in lists: <Zoffix> m: sub stuff { if 0 {} else {} }; dd [1, stuff(), 4] So naturally, the optimizer can check whether whether the value of the conditional is ever used and avoid the Empty stuff, and it does so in some cases: <Zoffix> m: sub stuff { if 0 {} else {}; 42 }; for ^100_000 { $ = [1, stuff(), 4] }; say now - INIT now; It doesn't seem to do that for the OP case (even when you tack on an extra value after it so result isn't used). So perhaps it could be taught to do so. Note that I doubt you'd see much speedup from this in real-life code: "10 times" may sound impressive, but the average comes down to difference between 21.9 *nano*seconds vs 219 *nano*seconds. |
The RT System itself - Status changed from 'new' to 'open' |
From @zoffixznetOn Sat, 21 Jan 2017 11:45:10 -0800, alex6k@yahoo.com wrote:
Thank you for the report. This is now fixed. The `else`-less version is now nearly twice faster: $ ./perl6 -e 'm: my int $i = 0; loop { if $i++ == 10_000_000 { last }}; say now - INIT now;' Fix: rakudo/rakudo@1815c36843ac58f |
@zoffixznet - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#130613 (status was 'resolved')
Searchable as RT130613$
The text was updated successfully, but these errors were encountered: