diff options
| author | Raphael Gaschignard <raphael@rtpg.co> | 2020-10-26 14:16:48 +0900 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-10-28 20:42:38 +0100 |
| commit | 46633c50cc79ace6d4d584704e165a5dc68feb90 (patch) | |
| tree | dee0cb5c796da2979912c7f0e2b36ec480dfdfa9 | |
| parent | 1d14e985baf8847be60b81b7f6140e8606fd862a (diff) | |
| download | astroid-git-46633c50cc79ace6d4d584704e165a5dc68feb90.tar.gz | |
Drop tracebacks on Astroid import errors for caches
Before this change, when there were import failures by Astroid, it
would store the error in the module cache (for example a "module not
found" error), including tracebacks. These tracebacks would take up a
lot of memory, and don't seem to be used for any sort of purpose
beyond debugging value.
On one project stripping this value entirely reduces memory usage by
75%.
| -rw-r--r-- | astroid/manager.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/astroid/manager.py b/astroid/manager.py index 82208adf..e2d23084 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -236,11 +236,13 @@ class AstroidManager: value = exceptions.AstroidImportError( "Failed to import module {modname} with error:\n{error}.", modname=modname, - error=ex, + # we remove the traceback here to save on memory usage (since these exceptions are cached) + error=ex.with_traceback(None), ) self._mod_file_cache[(modname, contextfile)] = value if isinstance(value, exceptions.AstroidBuildingError): - raise value + # we remove the traceback here to save on memory usage (since these exceptions are cached) + raise value.with_traceback(None) return value def ast_from_module(self, module, modname=None): |
