You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Submitted by Arbil on 7/8/2014 12:00:00 AM 136 votes on UserVoice prior to migration
According to my tests short struct tuples perform up to 25x faster than default ones if the cost of garbage collecting is taken into account. The code below allocates an array of default tuples/struct tuples respectively and collects it. The results are:
1249 ms for default tuples
44 ms for struct tuples
I remember reading that the Microsoft team had considered implementing tuples as structs but didn't see their advantage in the internal tests. I suspect the tests failed to take the garbage collection into account. If this is done the difference is huge.
Currently, even such a basic operation for high-performance code as a Dictionary.TryGetValue allocates memory! (Unless it is JITed away; the System.Tuple constructor is in the IL code).
I feel this is a real impediment for F# as a language for scientific, financial or game development.
Code:
type Pair<'a, 'b> =
struct
val Item1 : 'a
val Item2 : 'b
new(item1, item2) = {
Item1 = item1
Item2 = item2
}
end
let run() =
let size = 10000000
GC.Collect()
let watch = Diagnostics.Stopwatch.StartNew()
let mutable arrTuple = Array.init size (fun i -> (i,i))
arrTuple <- [|(0,0)|]
GC.Collect()
watch.Stop()
printfn "Took %A ms" watch.Elapsed.TotalMilliseconds
watch.Restart()
let mutable arrStruct = Array.init size (fun i -> Pair(i,i))
arrStruct <- [|Pair(0,0)|]
GC.Collect()
watch.Stop()
printfn "Took %A ms" watch.Elapsed.TotalMilliseconds
Add support for StructTuple [6148669]
Submitted by Arbil on 7/8/2014 12:00:00 AM
136 votes on UserVoice prior to migration
According to my tests short struct tuples perform up to 25x faster than default ones if the cost of garbage collecting is taken into account. The code below allocates an array of default tuples/struct tuples respectively and collects it. The results are:
1249 ms for default tuples
44 ms for struct tuples
I remember reading that the Microsoft team had considered implementing tuples as structs but didn't see their advantage in the internal tests. I suspect the tests failed to take the garbage collection into account. If this is done the difference is huge.
Currently, even such a basic operation for high-performance code as a Dictionary.TryGetValue allocates memory! (Unless it is JITed away; the System.Tuple constructor is in the IL code).
I feel this is a real impediment for F# as a language for scientific, financial or game development.
Code:
type Pair<'a, 'b> =
struct
val Item1 : 'a
val Item2 : 'b
new(item1, item2) = {
Item1 = item1
Item2 = item2
}
end
let run() =
let size = 10000000
GC.Collect()
let watch = Diagnostics.Stopwatch.StartNew()
let mutable arrTuple = Array.init size (fun i -> (i,i))
arrTuple <- [|(0,0)|]
GC.Collect()
watch.Stop()
printfn "Took %A ms" watch.Elapsed.TotalMilliseconds
watch.Restart()
let mutable arrStruct = Array.init size (fun i -> Pair(i,i))
arrStruct <- [|Pair(0,0)|]
GC.Collect()
watch.Stop()
printfn "Took %A ms" watch.Elapsed.TotalMilliseconds
Response
** by fslang-admin on 8/2/2016 12:00:00 AM **
Completed, see https://github.com/fsharp/FSharpLangDesign/blob/master/RFCs/FS-1006-struct-tuples.md
Don Syme, F# Language and Core Library Evolution
Original UserVoice Submission
Archived Uservoice Comments
The text was updated successfully, but these errors were encountered: