4 ms·
The simple program: my $i = 0; while ++$i <= 100000000 { } .. got a factor of 2.5 improvement with what we had several months ago If the topic is optimization
by petercooper 12y ago
The simple program: my $i = 0; while ++$i <= 100000000 { } .. got a factor of 2.5 improvement with what we had several months ago
If the topic is optimization improvements, is the improvement in question one that assigns the eventual value directly to $i? :-) (Or if that's literally the whole program, optimizes it away to nothing.)
- chrisseaton 12y agoIt's quite hard to remove that loop. First of all, keep in mind that the loop isn't empty - it includes the iteration condition. Then think you've got a loop of 100000000 iterations. Are you suggesting we should unroll that so that it can be constant folded using conventional techniques? That's going to be prohibitively expensive in terms of space and time. If we can't unroll we could peel it an iteration at a time, but we'll need some kind of analysis that will detect that the body of the loop can be constant folded, while at the still time having the control flow nodes in there. That might well be possible, but I'm not personally aware of how to do it - are you?
- petercooper 12y agoAs I'm academically naive to the topic (though I have a long term interest) I was being 50% tongue in cheek and 50% "well, why not?" so take my comments in my capacity as an enthusiastic but ignorant buffoon basking in the presence of a certified genius. With that said, I wrote the C equivalent of that Perl code, compiled -O0, disassemble, and it's what you'd expect.. add, mov, cmp, jg. At O3, the entire program is replaced by the no op: xor eax, eax. I am surely comparing apples and oranges here and missing your point about the control flow nodes, but gcc is making such an optimization on a naive implementation so it seems conceptually possible in a more dynamic environment if the same limitations can be calculated to be present on such an example, maybe?
- viraptor 12y agoIn a fairly dynamic language, it may be more problematic than in C. I mean in C you know i is an int and will not change. Maybe even know it's not used later on, so changing i at all is useless. I honestly don't know how much magic you can inject into Perl6, but there have to be languages dynamic enough that allow you to override integer increments and make $i=10; ++$i return an array of oranges. Possibly even from another thread while you're iterating.
- petercooper 12y agoIf only I knew how to poke around in V8 some more, I'd be interested to see what V8 would do on a JavaScript equivalent. JavaScript is reasonably dynamic and its performance has skyrocketed in recent years mostly due to jumps in JIT approaches and optimization. Of course, V8 has some of the smartest people in the field working on it and the backing of Google.. :)