diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 10:36:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-13 10:36:41 +0800 |
commit | 1716e334b260396da460148560045bc55894c322 (patch) | |
tree | aa0a5856165c02ff594dbe496050e54f72b353ff | |
parent | 52d631e2e5879c218adb0a969d337fc85732b593 (diff) | |
download | lua-language-server-1716e334b260396da460148560045bc55894c322.zip |
垃圾回收机制改回经典模式
-rw-r--r-- | server/main.lua | 2 | ||||
-rw-r--r-- | server/src/service.lua | 22 | ||||
-rw-r--r-- | server/src/vm/source.lua | 9 | ||||
-rw-r--r-- | server/src/vm/value.lua | 3 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 17 |
5 files changed, 20 insertions, 33 deletions
diff --git a/server/main.lua b/server/main.lua index 35b75789..4f3dcf71 100644 --- a/server/main.lua +++ b/server/main.lua @@ -6,7 +6,7 @@ LANG = LANG or 'en-US' package.path = (ROOT / 'src' / '?.lua'):string() .. ';' .. (ROOT / 'src' / '?' / 'init.lua'):string() -collectgarbage('generational') +--collectgarbage('generational') log = require 'log' log.init(ROOT, ROOT / 'log' / 'service.log') diff --git a/server/src/service.lua b/server/src/service.lua index a66864a8..cd3d24ed 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -25,6 +25,8 @@ local ErrorCodes = { RequestCancelled = -32800, } +local CachedVM = setmetatable({}, {__mode = 'kv'}) + local mt = {} mt.__index = mt @@ -335,6 +337,7 @@ function mt:compileVM(uri) if obj.vm then obj.vm:remove() end + CachedVM[vm] = true obj.vm = vm obj.vmCost = os.clock() - clock obj.vmVersion = version @@ -534,13 +537,26 @@ function mt:onTick() for _ in pairs(self._file) do count = count + 1 end + local alive = 0 + local dead = 0 + for vm in pairs(CachedVM) do + if vm:isRemoved() then + dead = dead + 1 + else + alive = alive + 1 + end + end local mem = collectgarbage 'count' log.debug(('\n\z State\n\z - Mem: [%.3f]kb\n\z - Cache: [%d]'):format( + Mem: [%.3f]kb\n\z + CachedVM: [%d]\n\z + AlivedVM: [%d]\n\z + DeadVM: [%d]'):format( mem, - count + count, + alive, + dead )) end end diff --git a/server/src/vm/source.lua b/server/src/vm/source.lua index 83f9569b..e6e15e9c 100644 --- a/server/src/vm/source.lua +++ b/server/src/vm/source.lua @@ -62,14 +62,6 @@ function mt:getUri() return self.uri end -function mt:setVM() - self.vm = vm -end - -function mt:isRemoved() - return self.vm:isRemoved() -end - function mt:set(name, v) if not self._flag then self._flag = {} @@ -92,7 +84,6 @@ return function (vm, source) if source._hasInstant then return false end - source.vm = vm setmetatable(source, mt) return true end diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index ee173c38..ece9e856 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -249,9 +249,6 @@ function mt:addInfo(tp, source, ...) if not source then return end - if source.uri ~= self.uri then - return - end Sort = Sort + 1 local info = { type = tp, diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index aeaffc13..4a54aeae 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -1166,22 +1166,6 @@ local function compile(ast, lsp, uri) return vm end --- TODO 测试代码 -local CachedVM = setmetatable({}, {__mode = 'kv'}) - -local function checkCachedVM(vm) - CachedVM[vm] = true - local total = 0 - local alive = 0 - for vm in pairs(CachedVM) do - total = total + 1 - if not vm:isRemoved() then - alive =alive + 1 - end - end - log.debug(('持有的VM:%d/%d'):format(alive, total)) -end - return function (ast, lsp, uri) if not ast then return nil @@ -1190,6 +1174,5 @@ return function (ast, lsp, uri) if not suc then return nil, res end - checkCachedVM(res) return res end |