Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for StructTuple #294

Open
baronfel opened this issue Oct 14, 2016 · 0 comments
Open

Add support for StructTuple #294

baronfel opened this issue Oct 14, 2016 · 0 comments

Comments

@baronfel
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant