Optimizing Immutable and Purity

Dave Dave_Member at pathlink.com
Wed Dec 24 10:07:20 PST 2008


>
>>On a real program, how much faster is my code going to get, if I maximize 
>>use of pure functions and immutable data? I don't know. I don't have any 
>>experience with it on a large program.<
>

I was on a large project not too long ago which used some formal eval 
questionaires to gauge quality (much of it subjective). Long story short, 
the overall "quality" rating went up significantly after the only thing that 
changed was a few passes through the bottlenecks to improve performance in 
those areas. Say, 2% of the code. Slow areas in any program really bring 
down the overall user opinion of said program I think.

So, since the bottlenecks usually come down to just a few lines of code, the 
big advantage of the optimizations for immutable and pure to me would be 
avoiding having to often "drop down" into asm., manually re-writing to 
"hoist" duplicative code out of tight loops or experimenting with load -> 
update -> store patterns to get the compiler to spit out the best code.

All this can be time-consuming and error-prone so I would think that for 
some programs your work here would be very valuable, and save quite a bit of 
development time and cost _if_ the developer took advantage of pure and 
immutable, consistently, where applicable. Especially in libraries.

- Dave
 





More information about the Digitalmars-d mailing list