intro : I spent whole day looking why my processing operation is so so slow. It was really slow on low data. I checked sql views , procedures , and linq logics – and all of them worked perfect. but then I saw the little thing takes ages to process.
member X.CountStatistics()=
linq.TrueIncidents
|> PSeq.groupBy (fun v -> v.Name)
|> PSeq.map (fun (k, vs) -> k, PSeq.length vs)
|> Array.ofSeq
It simply counts grouped values but how much time it spends ! about 10 seconds on easy table,
There must be something angry recursive but I can’t see it…
How can I make this operation “a bit faster” or recode it to linq-to-sql ?
The current version of the F# LINQ support is a bit limited.
I think that the best way to write this is to sacrifice some of the elegance in using F# for this and write it as a stored procedure in SQL. Then you could add the stored procedure to your
linqdata context and call it nicely using a generated method. When F# LINQ improves a bit in the future, you can change it back :-).Regarding the
PSeqexample – as far as I know, there was some efficiency issue because the methods were not inlined (thanks to inlining, the compiler was able to do some additional optimization and it removed some overhead). You can try downloading the source and addinginlinetomapandgroupBy.