summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-09 17:56:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-09 17:56:55 +0800
commit3d8c74d8a57e0c0051f103cc7bce1777b4699483 (patch)
tree1c9a1e8c3f65e539cede3df4de8a7cbec867b670
parent96291a4363b8139c49cee154ee83728413169156 (diff)
downloadlua-language-server-3d8c74d8a57e0c0051f103cc7bce1777b4699483.zip
check lock when pushing
-rw-r--r--changelog.md1
-rw-r--r--script/parser/guide.lua51
2 files changed, 27 insertions, 25 deletions
diff --git a/changelog.md b/changelog.md
index a240b316..e0040339 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,7 @@
## 1.15.0
* `CHG` main thread no longer loop sleeps, see [#329](https://github.com/sumneko/lua-language-server/issues/329) [#386](https://github.com/sumneko/lua-language-server/issues/386)
+* `CHG` improve performance
## 1.14.3
`2021-2-8`
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index a0409b79..0fbd6978 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -2690,11 +2690,21 @@ end
function m.searchSameFields(status, simple, mode)
local queues, starts, forces = allocQueue()
local queueLen = 0
+ local locks = {}
local function pushQueue(obj, start, force)
if obj.type == 'getlocal'
or obj.type == 'setlocal' then
obj = obj.node
end
+ local lock = locks[start]
+ if not lock then
+ lock = {}
+ locks[start] = lock
+ end
+ if lock[obj] then
+ return
+ end
+ lock[obj] = true
queueLen = queueLen + 1
queues[queueLen] = obj
starts[queueLen] = start
@@ -2718,7 +2728,6 @@ function m.searchSameFields(status, simple, mode)
pushQueue(simple.node, 1)
end
local max = 0
- local locks = {}
for i = 1, 1e6 do
if queueLen <= 0 then
break
@@ -2730,33 +2739,25 @@ function m.searchSameFields(status, simple, mode)
starts[queueLen] = nil
forces[queueLen] = nil
queueLen = queueLen - 1
- local lock = locks[start]
- if not lock then
- lock = {}
- locks[start] = lock
- end
- if not lock[obj] then
- lock[obj] = true
- max = max + 1
- status.share.count = status.share.count + 1
- if status.share.count % 10000 == 0 then
- --if TEST then
- -- print('####', status.share.count, osClock() - status.clock)
- --end
- if status.interface and status.interface.pulse then
- status.interface.pulse()
- end
- end
- --if status.share.count >= 100000 then
- -- logWarn('Count too large!')
- -- break
+ max = max + 1
+ status.share.count = status.share.count + 1
+ if status.share.count % 10000 == 0 then
+ --if TEST then
+ -- print('####', status.share.count, osClock() - status.clock)
--end
- m.checkSameSimple(status, simple, obj, start, force, mode, pushQueue)
- if max >= 100000 then
- logWarn('Queue too large!')
- break
+ if status.interface and status.interface.pulse then
+ status.interface.pulse()
end
end
+ --if status.share.count >= 100000 then
+ -- logWarn('Count too large!')
+ -- break
+ --end
+ m.checkSameSimple(status, simple, obj, start, force, mode, pushQueue)
+ if max >= 100000 then
+ logWarn('Queue too large!')
+ break
+ end
end
--deallocQueue(queues, starts, forces)
end