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

PR: Compute Projects switcher results in a worker to avoid freezes #21275

Merged
merged 26 commits into from
Aug 26, 2023

Conversation

ccordoba12
Copy link
Member

@ccordoba12 ccordoba12 commented Aug 20, 2023

Description of Changes

  • Since the initial implementation was synchronous, the interface was freezing when using the Switcher with large projects (i.e. projects that have more than 1000 files).
  • Highlight matched characters of Projects switcher results that match the searched text.
  • Remove binary files from the results computed by fzf because they can't be opened in the editor.
  • Fix process workers because they were not working as expected.
  • Simplify the way sections are shown in the Switcher, which was not very efficient and hard to understand.
  • Improve test that checks the integration between Projects and the Switcher.
  • Set app and monospace interface fonts when running single main window tests. That avoids a ton of Qt warnings to be displayed.

Issue(s) Resolved

Fixes #20940.

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct: @ccordoba12

- ProcessWorkers don't need threads, so they are not necessary.
- Also, add a method to ProcessWorker to set its current working
directory.
Also, reduce the number of results shown in the switcher to display it
without lags.
This is necessary now that fzf is called asynchronously.
Also, rename methods in Projects related to switcher searching to be
more meaningful.
It's not clear why that was required before.
This is necessary to make some adjustments in the switcher when that's
the case.
Also, avoid a small lag when opening the symbol finder by calling the
`setup` method directly after that.
Also, simplify when `setup_sections` is called: instead of doing it
every time an item is added, now we do it after all of them have been
sorted.
Also, change that section name to "Project" because we don't support
multiple projects.
Also, expand that test to check that:
- We make sections visible for the right number of items.
- Searching in the switcher is working as expected.
- The switcher is updated when removing files.
That avoids a ton of Qt warnings to be displayed.
Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

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

Thanks @ccordoba12 ! I was checking this locally and seems like there is some delays still for certain files? I tried with a dummy project with a lot of .parquet files and I noticed a lot of lag and also the files not appearing vs checking .py was more quick.

switcher

Checked with latest master and although there you can sense some general lag it shows the .parquet as well as the .py files:

old_switcher

Maybe there is now some logic/validation about what files to show that needs to be move to a worker too?

Also, I was thinking and maybe adding/showing some sort of loading indicator while searching could be worthy?

That's much faster than trying to detect if they are binary to exclude
them.
@ccordoba12
Copy link
Member Author

ccordoba12 commented Aug 22, 2023

I was checking this locally and seems like there is some delays still for certain files? I tried with a dummy project with a lot of .parquet files and I noticed a lot of lag and I noticed a lot of lag and also the files not appearing vs checking .py was more quick.

I was using encoding.is_text_file to detect binary files and exclude them from the switcher results. That's necessary because they can't be opened in the Editor, so there's no value in showing them. But I didn't realize that that's quite expensive for large binary files.

However, I changed that to simply compare the file extension of the fzf results with the list of extensions that can be opened in the editor, and the lag was removed for me. So, please test again.

Checked with latest master and although there you can sense some general lag it shows the .parquet as well as the .py files

As I said, there's no value in showing binary files if you want to quickly find and open a project file in the editor.

Also, I was thinking and maybe adding/showing some sort of loading indicator while searching could be worthy?

I agree, but that's a UI improvement that I have planned for later.

Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

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

Thanks @ccordoba12 ! Left comment/suggestion regarding a commented out line and a comment. Also, checking locally seems like an entry for the project root directory is created (not sure if that is intended or not). Other than that this LGTM 👍

spyder/plugins/switcher/widgets/switcher.py Outdated Show resolved Hide resolved
spyder/plugins/switcher/widgets/switcher.py Show resolved Hide resolved
spyder/plugins/projects/widgets/main_widget.py Outdated Show resolved Hide resolved
@ccordoba12
Copy link
Member Author

@dalthviz, besides fixing the problem you reported in your last review, I also added some changes to prevent trying to populate the switcher when closing it.

@dalthviz
Copy link
Member

Thanks for the fixes @ccordoba12 ! Checked again and the pointed elements look good now 👍 . However while checking again, I realized that I haven't checked this without fzf installed and seems like in that case another weird behavior happens. Seems like without fzf the open files filtering doesn't work :/

switcher_no_fzf

- This helps to simplify the _on_search_text_changed method of its
widget.
- Use that method from Projects to remove the items added by it before
painting new ones.
That way its results can be filtered when fzf is not present.
That created a special case for Projects, which is not really necessary.
@ccordoba12
Copy link
Member Author

ccordoba12 commented Aug 25, 2023

However while checking again, I realized that I haven't checked this without fzf installed and seems like in that case another weird behavior happens

Thanks for noticing that @dalthviz! It should be fixed now with my last commits.

When I was doing those changes, I also realized that we don't need to create a special, unnecessary dependency between the Switcher and Projects. So, I decided to remove it.

@dalthviz
Copy link
Member

Checked again @ccordoba12 and seems like while the filtering works without fzf, when it is installed the project section always shows regardles of the text in the search line edit?:

switcher_with_fzf_project_section

Also, should we add some tests for the different scenarios we have been discussing here (trying to search for a binary file, trying to search with and without fzf available, searching for a non existent file, etc)?

@ccordoba12
Copy link
Member Author

ccordoba12 commented Aug 25, 2023

and seems like while the filtering works without fzf

Great!

when it is installed the project section always shows regardles of the text in the search line edit?

Yep, that's the behavior implemented before and I kept it in this PR too. I think that's more a UX issue than a backend problem (which is what I'm trying to fix here), so it should be left for later. In addition, we're currently discussing about that in our UX meetings and haven't decided what to do yet.

Copy link
Member

@dalthviz dalthviz left a comment

Choose a reason for hiding this comment

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

Thanks @ccordoba12 ! This LGTM. However, before merging, do you think that adding more tests is worthy? If not feel free to merge 👍

@ccordoba12
Copy link
Member Author

ccordoba12 commented Aug 25, 2023

However, before merging, do you think that adding more tests is worthy?

Good point and sorry for missing the comment you posted about it (I just read it):

Also, should we add some tests for the different scenarios we have been discussing here (trying to search for a binary file, trying to search with and without fzf available, searching for a non existent file, etc)?

I'll expand our current test for the projects/switcher integration to cover those scenarios as well.

This includes new cases for binary and nonexistent files, and missing
fzf.
@ccordoba12
Copy link
Member Author

Test improved, so I'm going to merge this one.

Thanks @dalthviz for all your help!

@ccordoba12 ccordoba12 merged commit c5de2ed into spyder-ide:master Aug 26, 2023
20 checks passed
@ccordoba12 ccordoba12 deleted the issue-20940 branch August 26, 2023 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancements to Projects file switcher
2 participants