diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-20 17:07:26 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-20 17:07:26 +0800 |
commit | 91b6d42fe7bdfba92a5de947390dcdd781503589 (patch) | |
tree | 6cf0d4add746b4edfef0ca3ed8f1701ba0b78c3f /server/src | |
parent | 2270e01b1e25decff28cb2127e0c9156ead77375 (diff) | |
download | lua-language-server-91b6d42fe7bdfba92a5de947390dcdd781503589.zip |
测试时每次重置全局缓存,会造成测试速度变慢很多
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/service.lua | 2 | ||||
-rw-r--r-- | server/src/vm/global.lua | 1 | ||||
-rw-r--r-- | server/src/vm/library.lua | 11 | ||||
-rw-r--r-- | server/src/vm/source.lua | 1 |
4 files changed, 14 insertions, 1 deletions
diff --git a/server/src/service.lua b/server/src/service.lua index cb6a20a9..e456ff3c 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -592,7 +592,7 @@ end function mt:onTick() self:_loadProto() self:_doCompileTask() - if os.clock() - self._clock >= 60 then + if os.clock() - self._clock >= 10 then self._clock = os.clock() self:_testMemory() end diff --git a/server/src/vm/global.lua b/server/src/vm/global.lua index 806c8931..63db8487 100644 --- a/server/src/vm/global.lua +++ b/server/src/vm/global.lua @@ -6,6 +6,7 @@ local sourceMgr = require 'vm.source' return function (lsp) local global = lsp and lsp.globalValue if not global then + libraryBuilder.clear() local t = {} for name, lib in pairs(library.global) do t[name] = libraryBuilder.value(lib) diff --git a/server/src/vm/library.lua b/server/src/vm/library.lua index 67d2d263..60f56368 100644 --- a/server/src/vm/library.lua +++ b/server/src/vm/library.lua @@ -4,11 +4,15 @@ local createValue local createFunction local CHILD_CACHE = {} +local VALUE_CACHE = {} local buildLibValue local buildLibChild function buildLibValue(lib) + if VALUE_CACHE[lib] then + return VALUE_CACHE[lib] + end if not createValue then createValue = require 'vm.value' createFunction = require 'vm.function' @@ -49,6 +53,7 @@ function buildLibValue(lib) value = createValue(tp or 'any', sourceMgr.dummy()) end value:setLib(lib) + VALUE_CACHE[lib] = value if lib.child then for fName, fLib in pairs(lib.child) do @@ -78,7 +83,13 @@ function buildLibChild(lib) return child end +local function clearCache() + CHILD_CACHE = {} + VALUE_CACHE = {} +end + return { value = buildLibValue, child = buildLibChild, + clear = clearCache, } diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index af8b9ab3..bbe243b9 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -111,6 +111,7 @@ end local function dummy() local src = {} instant(src) + log.debug('临时source', debug.traceback()) return src end |