Repository: spyder-ide/spyder

Issue:
New way to update folding regions (PR #13783) freezes Spyder
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [ ] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ ] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ ] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

While using the editor, Spyder freeses for ~30s very often. I saw with the frame explorer that it was blocked in the new code intoduced by PR #13783. After reverting the merge, spyder works again.

### What steps reproduce the problem?

1. 
2. 
3. 

### What is the expected output? What do you see instead?



### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

PASTE TRACEBACK HERE

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 
* Python version: 
* Qt version: 
* PyQt version: 
* Operating System name/version: 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
Hi @impact27 thanks for the feedback :+1: Not sure if @andfoy or @ccordoba12 are aware of the performance issue but pinging them here just in case 
Thanks @impact27 for reporting. How long is the file that shows the freezes?
I'm experiencing the same thing too. It occurs on files that are not very long, like 500 lines maybe.
@andfoy, could you reproduce this one?
It seems that textdistance is causing delays here:

![imagen](https://user-images.githubusercontent.com/1878982/100280225-cf24ce00-2f35-11eb-96c5-66a8ba5f1009.png)

It seems that the lag was due to the usage of Jaro-Wrinkler distance, after replacing it with a normalized Jaccard index, the performance did improve:

![spyder_prof](https://user-images.githubusercontent.com/1878982/100281576-29bf2980-2f38-11eb-8307-18f2016ddd26.png)



Resolving patch:
diff --git a/spyder/plugins/editor/panels/utils.py b/spyder/plugins/editor/panels/utils.py
--- a/spyder/plugins/editor/panels/utils.py
+++ b/spyder/plugins/editor/panels/utils.py
@@ -151,7 +151,7 @@ def merge_folding(ranges, current_tree, root):
     while deleted_entry is not None and changed_entry is not None:
         deleted_entry_i = deleted_entry.data
         changed_entry_i = changed_entry.data
-        dist = textdistance.jaro_winkler.normalized_similarity(
+        dist = textdistance.jaccard.normalized_similarity(
             deleted_entry_i.text, changed_entry_i.text)
 
         if dist >= 0.80:


Test patch: