in reply to Re^11: How to speed up a nested loop?
in thread How to speed up a nested loop?

I think you're misunderstanding. What you had before calculated $rx in the loop, and then had:
...$tiles[$rx][$ry]...
in the inner loop. Which looks up index $rx, gets an array reference, looks up index $ry, etc.

I moved calculating $rx out of the loop and the lookup on $rx out of the loop with:

my $tiles_for_rx = ($tiles[$rx] ||= []);
and then in the loop had:
...$tiles_for_rx->[$ry]...
which means that the lookup of index $rx doesn't happen in the inner loop any more.

If your inner loop executes 15 times for each iteration of the outer loop, you just lost 14 calculations of $rx, and 14 lookups on index $rx. Less work is generally faster.