summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-15 19:24:46 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-15 19:24:46 +0800
commit491876016134b50680667053177faeae411aa9a2 (patch)
treeb38c5ba204cb1d9d4fc25eeb30a2f97c0815c076
parentb4524f05ee0a21176cb9a0e22941b04a3eca3773 (diff)
downloadlua-language-server-491876016134b50680667053177faeae411aa9a2.zip
improve performance
-rw-r--r--script/core/completion/completion.lua2
-rw-r--r--script/vm/node.lua19
2 files changed, 21 insertions, 0 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 428c8e96..75f75999 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1936,6 +1936,8 @@ local function completion(uri, position, triggerCharacter)
return nil
end
clearStack()
+ vm.lockCache()
+ local _ <close> = vm.unlockCache
local results = {}
tracy.ZoneBeginN 'completion #2'
tryCompletions(state, position, triggerCharacter, results)
diff --git a/script/vm/node.lua b/script/vm/node.lua
index ea6a5874..21f95a49 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -232,7 +232,26 @@ function vm.removeNode(source)
vm.nodeCache[source] = nil
end
+local lockCount = 0
+local needClearCache = false
+function vm.lockCache()
+ lockCount = lockCount + 1
+end
+
+function vm.unlockCache()
+ lockCount = lockCount - 1
+ if needClearCache then
+ needClearCache = false
+ vm.clearNodeCache()
+ end
+end
+
function vm.clearNodeCache()
+ if lockCount > 0 then
+ needClearCache = true
+ return
+ end
+ log.debug('clearNodeCache')
vm.nodeCache = {}
end