Skip to content
Snippets Groups Projects
Commit 26209188 authored by 最萌小汐's avatar 最萌小汐
Browse files

优化性能

parent d5ecec7f
No related branches found
No related tags found
No related merge requests found
......@@ -48,7 +48,7 @@
"type": "lua",
"request": "attach",
"stopOnEntry": true,
"address": "127.0.0.1:11419",
"address": "127.0.0.1:11420",
"outputCapture": [
]
},
......
// Just some comment
{
"Lua.diagnostics.globals": [ // Just some comment
// Just some comment
"Lua.diagnostics.globals": [
"ERR",
"OUT",
"IN",
// Just some comment
"log",
"ac",
"_G",
......
......@@ -18,4 +18,6 @@ xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
local service = require 'service'
-- TODO
ALL_DEEP = true
service.start()
......@@ -8,7 +8,7 @@ local findSource = require 'core.find-source'
local lang = require 'language'
local function getHoverAsFunction(source)
local values = vm.getInfers(source)
local values = vm.getInfers(source, 'deep')
local desc = getDesc(source)
local labels = {}
local defs = 0
......
......@@ -172,20 +172,23 @@ end
return function (source)
local literals = {}
local classes = {}
local clock = os.clock()
for _, src in ipairs(vm.getFields(source, 'deep')) do
local key = getKey(src)
if not key then
goto CONTINUE
end
local class, literal = getField(src)
if not classes[key] then
classes[key] = {}
end
if not literals[key] then
literals[key] = {}
end
if os.clock() - clock <= 1 then
local class, literal = getField(src)
classes[key][#classes[key]+1] = class
literals[key][#literals[key]+1] = literal
end
::CONTINUE::
end
......
......@@ -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]
......
......@@ -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]
......
......@@ -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]
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment