Skip to content

Commit

Permalink
fix SirVer#1165: insert mode lag
Browse files Browse the repository at this point in the history
Ultisnips was traversing the whole runtimepath every time an expansion
was attempted, something that happens for every key press since there is
autotrigger.

Even without autotrigger, traversal was done at every snippet expansion,
which caused slowdowns in that case.

With this change, traversal happens only the first time, or after
a source must be refreshed (because a snippets file has been updated).
  • Loading branch information
mg979 committed Mar 6, 2024
1 parent b393ba6 commit 7518f98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions pythonx/UltiSnips/snippet/source/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SnippetSource:
def __init__(self):
self._snippets = defaultdict(SnippetDictionary)
self._extends = defaultdict(set)
self._must_refresh = True

def ensure(self, filetypes):
"""Ensures that snippets are loaded."""
Expand Down
8 changes: 5 additions & 3 deletions pythonx/UltiSnips/snippet/source/file/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def __init__(self):
SnippetSource.__init__(self)

def ensure(self, filetypes):
for ft in self.get_deep_extends(filetypes):
if self._needs_update(ft):
self._load_snippets_for(ft)
if self._must_refresh:
for ft in self.get_deep_extends(filetypes):
if self._needs_update(ft):
self._load_snippets_for(ft)
self._must_refresh = False

def refresh(self):
self.__init__()
Expand Down

0 comments on commit 7518f98

Please sign in to comment.