diff options
author | Tom Lau <tomandfatboy@gmail.com> | 2024-07-01 09:30:43 +0800 |
---|---|---|
committer | Tom Lau <tomandfatboy@gmail.com> | 2024-07-01 09:35:32 +0800 |
commit | fea3b6d81ace6a23bf990602731ba31902c26375 (patch) | |
tree | 6be2cd43f0086182edbb42e571285ca1c223445a | |
parent | 3886d2ede3345296fbadc96c09d42cca96affa77 (diff) | |
download | lua-language-server-fea3b6d81ace6a23bf990602731ba31902c26375.zip |
perf: Optimize work distribution in multi-threaded `--check`
The current hash function used to distribute work seems not perfect.
We can actually use round robin to distribute after sorting file list.
-rw-r--r-- | script/cli/check_worker.lua | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/script/cli/check_worker.lua b/script/cli/check_worker.lua index 23c34b2c..822c83dc 100644 --- a/script/cli/check_worker.lua +++ b/script/cli/check_worker.lua @@ -43,15 +43,6 @@ local checkLevel = define.DiagnosticSeverity[CHECKLEVEL] or define.DiagnosticSev util.enableCloseFunction() --- Hash function used to distribute work. -local function hashString(str) - local hash = 0 - for i = 1, #str do - hash = (hash * 37 & 0xFFFFFFFF) + str:byte(i, i) - end - return hash -end - local lastClock = os.clock() local results = {} @@ -109,9 +100,9 @@ xpcall(lclient.start, errorhandler, lclient, function (client) local uris = files.getChildFiles(rootUri) local max = #uris + table.sort(uris) -- sort file list to ensure the work distribution order across multiple threads for i, uri in ipairs(uris) do - local hash = hashString(uri) % numThreads + 1 - if hash == threadId then + if (i % numThreads + 1) == threadId then files.open(uri) diag.doDiagnostic(uri, true) -- Print regularly but always print the last entry to ensure that logs written to files don't look incomplete. |