-
Notifications
You must be signed in to change notification settings - Fork 32
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
Optimize LazyList implementation #3
Comments
I took a bit of time to test this modification. I've significantly refactored the code since Greg's original post to /// Return a new list which contains the given item followed by the given list.
static member internal Cons (value, list) : LazyList<'T> =
// Preconditions
checkNonNull "list" list
// Original code
// LazyList<_>.CreateLazy <| fun () ->
// Cons (value, list)
// Implementation suggested by issue #3.
LazyList (Value (Cons (value, list))) I compiled ExtCore both with and without the suggested optimization, in both Debug and Release configurations. I ran the unit tests for the LazyList fixture using the NUnit GUI Runner several times for each combination, and recorded the running time for each test run (in seconds). Compiled in Debug configuration:
Statistics
Compiled in Release configuration:
Statistics
It looks like the optimization provides a small but consistent improvement for the Debug configuration. The Release results aren't as clear-cut -- the average and minimum running time of the unit tests is roughly the same (the original is faster by <1%), but the optimization does seems to improve the maximum running time. Based on these results, it's difficult to definitively say whether it's worth incorporating this optimization. To get a better comparison of the performance gains to be had, it would be useful to construct some benchmarks with longer running times and larger lists. Once these are constructed, it would also be good to compare the memory usage and GC impact of the optimization; it seems that the optimized version would provide more improvement in these areas, rather than improving execution speed (since the optimization avoids creating unnecessary closures). One last note -- after making the optimization, all of the LazyList tests in the |
It may be worth revisiting this and re-performing the benchmark with BenchmarkDotNet on the latest .NET framework. |
Via the
fsharp-opensource
mailing list, Greg Chapman suggested a possible optimization forLazyList
:https://groups.google.com/forum/#!searchin/fsharp-opensource/lazy/fsharp-opensource/Zd221uJ0BGM/A1h8bJtv_c0J
The text was updated successfully, but these errors were encountered: