summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/files.lua2
-rw-r--r--script/vm/getLinks.lua4
-rw-r--r--script/workspace/workspace.lua27
4 files changed, 32 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md
index 712ed6b2..4a290acf 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,7 @@
## 1.11.0
* `NEW` `Lua.runtime.plugin`
+* `CHG` performance optimization
* `CHG` completion: improve performance of workspace words
* `FIX` hover: tail comments may be cutted
* `FIX` runtime errors
diff --git a/script/files.lua b/script/files.lua
index 93213ad0..893a3ce9 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -360,7 +360,7 @@ end
--- 判断文件名相等
function m.eq(a, b)
if platform.OS == 'Windows' then
- return a:lower() == b:lower()
+ return a:lower():gsub('[/\\]+', '/') == b:lower():gsub('[/\\]+', '/')
else
return a == b
end
diff --git a/script/vm/getLinks.lua b/script/vm/getLinks.lua
index c1690762..0cb93bd0 100644
--- a/script/vm/getLinks.lua
+++ b/script/vm/getLinks.lua
@@ -10,6 +10,7 @@ local function getFileLinks(uri)
if not ast then
return links
end
+ tracy.ZoneBeginN('getFileLinks')
guide.eachSpecialOf(ast.ast, 'require', function (source)
local call = source.parent
if not call or call.type ~= 'call' then
@@ -28,9 +29,10 @@ local function getFileLinks(uri)
links[u][#links[u]+1] = call
end
end)
+ tracy.ZoneEnd()
return links
end
-
+require 'tracy'.enable()
local function getLinksTo(uri)
uri = files.asKey(uri)
local links = {}
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index cb033582..f99092bc 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -300,9 +300,19 @@ function m.findUrisByFilePath(path)
if type(path) ~= 'string' then
return {}
end
+ local lpath = path:lower():gsub('[/\\]+', '/')
+ local vm = require 'vm'
+ local resultCache = vm.getCache 'findUrisByRequirePath.result'
+ if resultCache[path] then
+ return resultCache[path].results, resultCache[path].posts
+ end
+ tracy.ZoneBeginN('findUrisByFilePath #1')
local results = {}
local posts = {}
for uri in files.eachFile() do
+ if not uri:find(lpath, 1, true) then
+ goto CONTINUE
+ end
local pathLen = #path
local curPath = furi.decode(files.getOriginUri(uri))
local curLen = #curPath
@@ -315,7 +325,13 @@ function m.findUrisByFilePath(path)
posts[uri] = post:gsub('^[/\\]+', '')
end
end
+ ::CONTINUE::
end
+ tracy.ZoneEnd()
+ resultCache[path] = {
+ results = results,
+ posts = posts,
+ }
return results, posts
end
@@ -325,6 +341,12 @@ function m.findUrisByRequirePath(path)
if type(path) ~= 'string' then
return {}
end
+ local vm = require 'vm'
+ local cache = vm.getCache 'findUrisByRequirePath'
+ if cache[path] then
+ return cache[path].results, cache[path].searchers
+ end
+ tracy.ZoneBeginN('findUrisByRequirePath')
local results = {}
local mark = {}
local searchers = {}
@@ -350,6 +372,11 @@ function m.findUrisByRequirePath(path)
end
end
end
+ tracy.ZoneEnd()
+ cache[path] = {
+ results = results,
+ searchers = searchers,
+ }
return results, searchers
end