baronfel / fsharp-lang-testbed

0 stars 0 forks source link

Optimize IL for methods to use mutable code for better performance #29

Open baronfel opened 7 years ago

baronfel commented 7 years ago

Idea 11543415: Optimize IL for methods to use mutable code for better performance

Status : declined

Submitted by knocte on 1/22/2016 12:00:00 AM

1 votes

It turns out that using immutable algorithm is not always the best thing in regards to performance. An interesting story about this is http://viralfsharp.com/2015/12/27/look-and-say-f/ So mutable code can actually be better in regards to performance (because it involves less allocations?). So maybe, in the cases in which it can be assured that no race condition can happen (i.e. mutable locals instead of mutable fields, because the former cannot be shared between threads), the F# compiler should try to optimize the IL generated for methods, to mutable-locals-optimized IL. An example of how Streams could be optimized: https://github.com/nessos/Streams