Skip to content

Commit 4918760

Browse files
committed
improve performance
1 parent b4524f0 commit 4918760

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

script/core/completion/completion.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,8 @@ local function completion(uri, position, triggerCharacter)
19361936
return nil
19371937
end
19381938
clearStack()
1939+
vm.lockCache()
1940+
local _ <close> = vm.unlockCache
19391941
local results = {}
19401942
tracy.ZoneBeginN 'completion #2'
19411943
tryCompletions(state, position, triggerCharacter, results)

script/vm/node.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,26 @@ function vm.removeNode(source)
232232
vm.nodeCache[source] = nil
233233
end
234234

235+
local lockCount = 0
236+
local needClearCache = false
237+
function vm.lockCache()
238+
lockCount = lockCount + 1
239+
end
240+
241+
function vm.unlockCache()
242+
lockCount = lockCount - 1
243+
if needClearCache then
244+
needClearCache = false
245+
vm.clearNodeCache()
246+
end
247+
end
248+
235249
function vm.clearNodeCache()
250+
if lockCount > 0 then
251+
needClearCache = true
252+
return
253+
end
254+
log.debug('clearNodeCache')
236255
vm.nodeCache = {}
237256
end
238257

0 commit comments

Comments
 (0)