diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-29 20:58:47 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-29 20:58:47 +0800 |
commit | 2620918840cb28fdd641fa986367ad9e8175a730 (patch) | |
tree | 7c1665dfae55d9c9bc3b3778271fd7b76093eb87 /script-beta/vm | |
parent | d5ecec7f362db69879e5097e41bd334d76260783 (diff) | |
download | lua-language-server-2620918840cb28fdd641fa986367ad9e8175a730.zip |
优化性能
Diffstat (limited to 'script-beta/vm')
-rw-r--r-- | script-beta/vm/eachDef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachField.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/eachRef.lua | 4 | ||||
-rw-r--r-- | script-beta/vm/getInfer.lua | 46 |
4 files changed, 51 insertions, 7 deletions
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua index 5d1aa566..0cd3c6ca 100644 --- a/script-beta/vm/eachDef.lua +++ b/script-beta/vm/eachDef.lua @@ -26,12 +26,16 @@ local function eachDef(source, deep) end function vm.getDefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachDefOfGlobal')[name] or vm.getCache('eachDef')[source] or eachDef(source, 'deep') vm.getCache('eachDefOfGlobal')[name] = cache + vm.getCache('eachDef')[source] = cache return cache else local cache = vm.getCache('eachDef')[source] diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua index 90892f03..798566b4 100644 --- a/script-beta/vm/eachField.lua +++ b/script-beta/vm/eachField.lua @@ -47,12 +47,16 @@ local function eachField(source, deep) end function vm.getFields(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachFieldOfGlobal')[name] or vm.getCache('eachField')[source] or eachField(source, 'deep') vm.getCache('eachFieldOfGlobal')[name] = cache + vm.getCache('eachField')[source] = cache return cache else local cache = vm.getCache('eachField')[source] diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua index ea46c9ee..cd003443 100644 --- a/script-beta/vm/eachRef.lua +++ b/script-beta/vm/eachRef.lua @@ -25,12 +25,16 @@ local function getRefs(source, deep) end function vm.getRefs(source, deep) + if ALL_DEEP then + deep = 'deep' + end if guide.isGlobal(source) then local name = guide.getKeyName(source) local cache = vm.getCache('eachRefOfGlobal')[name] or vm.getCache('eachRef')[source] or getRefs(source, 'deep') vm.getCache('eachRefOfGlobal')[name] = cache + vm.getCache('eachRef')[source] = cache return cache else local cache = vm.getCache('eachRef')[source] diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua index c0f2d118..c7c422f4 100644 --- a/script-beta/vm/getInfer.lua +++ b/script-beta/vm/getInfer.lua @@ -1,6 +1,7 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local util = require 'utility' +local await = require 'await' NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end }) @@ -52,16 +53,47 @@ function vm.getInferLiteral(source, deep) return table.concat(literals, '|') end +local function getInfers(source, deep) + local results = {} + local lock = vm.lock('getInfers', source) + if not lock then + return results + end + + await.delay() + + local clock = os.clock() + local myResults, count = guide.requestInfer(source, vm.interface, deep) + if DEVELOP and os.clock() - clock > 0.1 then + log.warn('requestInfer', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })) + end + vm.mergeResults(results, myResults) + + lock() + + return results +end + --- 获取对象的值 --- 会尝试穿透函数调用 function vm.getInfers(source, deep) - if not source then - return + if ALL_DEEP then + deep = 'deep' end - local clock = os.clock() - local infers = guide.requestInfer(source, vm.interface, deep) - if os.clock() - clock > 0.1 then - log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))) + if guide.isGlobal(source) then + local name = guide.getKeyName(source) + local cache = vm.getCache('getInfersOfGlobal')[name] + or vm.getCache('getInfers')[source] + or getInfers(source, 'deep') + vm.getCache('getInfersOfGlobal')[name] = cache + vm.getCache('getInfers')[source] = cache + return cache + else + local cache = vm.getCache('getInfers')[source] + or getInfers(source, deep) + if deep then + vm.getCache('getInfers')[source] = cache + end + return cache end - return infers end |