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

Simple observable collection optimizations #149

Merged

Conversation

TysonMN
Copy link
Member

@TysonMN TysonMN commented Oct 12, 2019

Fixes #134 and partially addresses #137 by implementing all of the "simple" optimizations.

I have not tested anything yet. I will test later.

The two remaining more complicated optimizations are removing all elements that need to be removed in nearly linear time (as discussed here) and ordering in nearly linear time (as discussed here).

@cmeeren
Copy link
Member

cmeeren commented Oct 12, 2019

Thanks a lot! Let me know when you're ready to merge. (PS, you can mark PRs as "drafts" or something like that when you create them, to signal if you don't want them merged right away.)

@reinux do you want to give this PR a spin to check how much it impacts the performance you mentioned in #113 (comment)?

@reinux
Copy link

reinux commented Oct 12, 2019

Works great! Down from about 250ms per update to 120ms.

Haven't set up any proper tests, but it seems to work as expected.

The Seq.find is definitely the other big bottleneck at the moment.

Thanks, @bender2k14!

@cmeeren
Copy link
Member

cmeeren commented Oct 13, 2019

The Seq.find is definitely the other big bottleneck at the moment.

@reinux @bender2k14 Do you think the dictionary stuff in #137 (comment) could work well in this PR?

@reinux
Copy link

reinux commented Oct 13, 2019

The Seq.find and the Move call that follows are actually what causes the bug that I mentioned in that comment. As @bender2k14 notes, caching the ID->ixs of the current items up front causes it to be out of sync as the Move calls change the indices. His branch actually uses the dictionary for the rest of the function, where that isn't an issue.

@TysonMN
Copy link
Member Author

TysonMN commented Oct 13, 2019

Indeed. Of all the planning that I did for this PR, I didn't notice that replacing Seq.fine with dictionary lookups would cause a bug. Good thing @reinux ran into it before me ;) :P

@TysonMN
Copy link
Member Author

TysonMN commented Oct 13, 2019

I added a commit that calls Clear when it would be efficient to do so

@cmeeren
Copy link
Member

cmeeren commented Oct 13, 2019

Seems that commit broke some tests. Could you investigate?

@TysonMN
Copy link
Member Author

TysonMN commented Oct 13, 2019

Oh, I had an improvement to that commit that I forgot to include. I force pushed a new commit. The tests all pass for me.

The previous commit had the correct behavior, but raised more (clear) events than it needed to. It is great to see that there are some tests that noticed the difference.

@TysonMN
Copy link
Member Author

TysonMN commented Oct 14, 2019

Thanks a lot

My pleasure :)

Let me know when you're ready to merge.

I am ready. I have reviewed my changes several times and have done some manual testing. I think everything is working.

PS, you can mark PRs as "drafts" or something like that when you create them, to signal if you don't want them merged right away.

Oh, great. I will keep that in mind for next time.

@cmeeren
Copy link
Member

cmeeren commented Oct 14, 2019

In #134 (comment) you mention adding a test; should that be part of this PR or should I go ahead and merge? (If it's related to the changes in this PR, it should ideally be part of it.)

@TysonMN
Copy link
Member Author

TysonMN commented Oct 14, 2019

It makes sense to add the test to this PR. Coming soon!

@TysonMN
Copy link
Member Author

TysonMN commented Oct 15, 2019

It took me longer than I expected to write the test. The good news though is that I think it is complete. I have it failing on master. Tomorrow I will confirm that it passes on the branch in this PR. Then I will force push the branch with the test created first.

@TysonMN TysonMN force-pushed the simple_ObservableCollection_optimizations branch from c52a5ec to 086d350 Compare October 15, 2019 13:29
@TysonMN
Copy link
Member Author

TysonMN commented Oct 15, 2019

Done! :D

Ready to merge

@cmeeren
Copy link
Member

cmeeren commented Oct 15, 2019

Thanks a lot! Will try to review and merge tomorrow.

src/Elmish.WPF.Tests/ViewModelTests.fs Outdated Show resolved Hide resolved
@TysonMN TysonMN force-pushed the simple_ObservableCollection_optimizations branch from 086d350 to c3f76fd Compare October 15, 2019 20:33
@cmeeren cmeeren merged commit 6312973 into elmish:master Oct 16, 2019
@cmeeren cmeeren mentioned this pull request Oct 16, 2019
@TysonMN TysonMN deleted the simple_ObservableCollection_optimizations branch October 16, 2019 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of ObservableCollection<T>.Remove(T)
3 participants