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

Search: Stop auto-selecting previous index (performance) #1979

Merged
merged 1 commit into from
Mar 30, 2020

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Mar 26, 2020

In #1941 we introduced instant search results.
In #1919 and in #1966 we refactored the previousIndex into Redux

The result was that we weren't resetting the previousIndex properly
and so on every search we would select some note, often the first
one in the list. If this note were large or slow to render then the
performance gains we achieved with search were destroyed by the cost
of rendering the notes.

In this patch we're properly resetting the previousNote whenever
we actually filter the notes. This means that searches will clear
the selected note if it's not in the search results. This also brings
back the performance gains we got by refactoring search itself.

Testing

Open an account with large or slow-to-render notes.
Search for almost anything.

In develop you might notice that the app becomes unresponsive.
In this branch you should see full responsiveness.

Verify that when trashing, restoring, and permanently deleting a
note that the one above it in the note list gets selected.

In #1941 we introduced instant search results.
In #1919 and in #1966 we refactored the `previousIndex` into Redux

The result was that we weren't resetting the `previousIndex` properly
and so on every search we would select _some_ note, often the first
one in the list. If this note were large or slow to render then the
performance gains we achieved with search were destroyed by the cost
of rendering the notes.

In this patch we're properly resetting the `previousNote` whenever
we actually filter the notes. This means that searches will clear
the selected note if it's not in the search results. This also brings
back the performance gains we got by refactoring search itself.
@dmsnell dmsnell requested review from belcherj and a team March 26, 2020 03:32
Copy link
Contributor

@belcherj belcherj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@dmsnell dmsnell merged commit 0db494a into develop Mar 30, 2020
@dmsnell dmsnell deleted the search/stop-auto-selecting-notes branch March 30, 2020 23:28
@dmsnell dmsnell added this to the 1.16 milestone Apr 1, 2020
dmsnell added a commit that referenced this pull request Apr 2, 2020
Fixes #1941
Supplants #1966
Supplants #1979

It turns out that having search inside a WebWorker isn't as necessary
as we thought and at the same time presents one major obstacle: search
must be asynchronous. This causes a few problems with the app is
currently designed, namely that the interaction between `previousIndex`,
trash/delete/restore operations, and the note list.

The primary goal of the larger state-refactor project has been to
eliminate non-atomic state updates and the WebWorker's asyncronous
mandate means that there is no way to synchronously update state, which
means that there's no way to run the trashing actions at the same time
that we update the search filter. This leaves an awkward rendered state
where the note in the note list is trashed and the toolbar above it
shows the trash "Delete forever" and "Restore" buttons but we're still
looking at the note list.

In order to resolve these bugs and eliminate further issues I have
brought the search back into the main thread. Why? Won't this destroy
all that we gained in terms of performance?" you might ask. No, actually
most of the performance gain came from changes I made to the search
mechanism _while_ moving it into a WebWorker. I had wanted it to be in
a WebWorker because it was slow, but now that we can see that it's
very very fast and shouldn't be a UI blocker we don't have the same
motivation to get it out of the main thread.

In summary, this patch moves the search back into the main thread and
exposes the `updateFilter()` function so that it can be called synchronously
for actions which demand immediate UI updates.
dmsnell added a commit that referenced this pull request Apr 3, 2020
Fixes #1941
Supplants #1966
Supplants #1979

It turns out that having search inside a WebWorker isn't as necessary
as we thought and at the same time presents one major obstacle: search
must be asynchronous. This causes a few problems with the app is
currently designed, namely that the interaction between `previousIndex`,
trash/delete/restore operations, and the note list.

The primary goal of the larger state-refactor project has been to
eliminate non-atomic state updates and the WebWorker's asyncronous
mandate means that there is no way to synchronously update state, which
means that there's no way to run the trashing actions at the same time
that we update the search filter. This leaves an awkward rendered state
where the note in the note list is trashed and the toolbar above it
shows the trash "Delete forever" and "Restore" buttons but we're still
looking at the note list.

In order to resolve these bugs and eliminate further issues I have
brought the search back into the main thread. Why? Won't this destroy
all that we gained in terms of performance?" you might ask. No, actually
most of the performance gain came from changes I made to the search
mechanism _while_ moving it into a WebWorker. I had wanted it to be in
a WebWorker because it was slow, but now that we can see that it's
very very fast and shouldn't be a UI blocker we don't have the same
motivation to get it out of the main thread.

In summary, this patch moves the search back into the main thread and
exposes the `updateFilter()` function so that it can be called synchronously
for actions which demand immediate UI updates.
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.

2 participants