Repository: spyder-ide/spyder

Issue:
Opening a folder with a lot of binary files 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
I am trying to open a folder with 20000 tiff files in the files explorer and that freezes spyder for ~
4 minutes.

### What steps reproduce the problem?

1. open a folder with 20000 tiff files in the files explorer (5GB total)
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:

Resolving patch:
diff --git a/spyder/utils/icon_manager.py b/spyder/utils/icon_manager.py
--- a/spyder/utils/icon_manager.py
+++ b/spyder/utils/icon_manager.py
@@ -45,6 +45,8 @@
 OFFICE_FILES = {'.xlsx': 'ExcelFileIcon', '.docx': 'WordFileIcon',
                 '.pptx': 'PowerpointFileIcon'}
 
+ICONS_BY_EXTENSION = {}
+
 # Magnification factors for attribute icons
 # per platform
 if sys.platform.startswith('linux'):
@@ -411,12 +413,20 @@ def get_icon_by_extension_or_type(fname, scale_factor):
     application_icons = {}
     application_icons.update(BIN_FILES)
     application_icons.update(DOCUMENT_FILES)
+
+    basename = osp.basename(fname)
+    __, extension = osp.splitext(basename.lower())
+    mime_type, __ = mime.guess_type(basename)
+
     if osp.isdir(fname):
-        return icon('DirOpenIcon', scale_factor)
+        extension = "Folder"
+
+    if (extension, scale_factor) in ICONS_BY_EXTENSION:
+        return ICONS_BY_EXTENSION[(extension, scale_factor)]
+
+    if osp.isdir(fname):
+        icon_by_extension = icon('DirOpenIcon', scale_factor)
     else:
-        basename = osp.basename(fname)
-        __, extension = osp.splitext(basename.lower())
-        mime_type, __ = mime.guess_type(basename)
         icon_by_extension = get_icon('binary', adjust_for_interface=True)
 
         if extension in OFFICE_FILES:
@@ -458,6 +468,8 @@ def get_icon_by_extension_or_type(fname, scale_factor):
                     if bin_name in application_icons:
                         icon_by_extension = icon(
                             application_icons[bin_name], scale_factor)
+
+    ICONS_BY_EXTENSION[(extension, scale_factor)] = icon_by_extension
     return icon_by_extension
 
 


Test patch: