Cheat to speedup using nqp::iterator+nqp::shift on a list#1809
Cheat to speedup using nqp::iterator+nqp::shift on a list#1809MasterDuke17 wants to merge 1 commit into
Conversation
…ly during iteration
|
I noticed this when looking at Raku/nqp#685. |
|
Why can we assume that the array is in a good state? |
Well, I believe we’re allowed to act as if it’s in a good state. Modifying an array during iteration is not allowed AIUI. Also, the iterator keeps track of the index compared to the size of the array. |
|
Is this PR still good? If so, what would be against merging it? |
I couldn't tell if this comment was purely about nqp level commitments or also about Raku level commitments. For Raku, I'll say this. Shortly after For nqp, I'll say this. The doc for
|
We can assume the backing array is in a good state so reach in directly during iteration.
time MVM_SPESH_BLOCKING=1 nqp -e 'my $l := nqp::list(); my int $p := 0; while $p++ < 10_000 { nqp::push($l, $p) }; my int $j := 10000; while $j-- { my $iter := nqp::iterator($l); nqp::while($iter, my $a := nqp::shift($iter)) }'drops from ~1.46s to ~1.25s andtime MVM_SPESH_BLOCKING=1 nqp -e 'my $l := nqp::list_s(); my int $p := 0; while $p++ < 10_000 { nqp::push_s($l, $p) }; my int $j := 10000; while $j-- { my $iter := nqp::iterator($l); nqp::while($iter, my $a := nqp::shift_s($iter)) }'drops from ~2.01s to ~1.83s.