Skip to content

Commit f040a1e

Browse files
committed
perf(lsp): completion serves lock-free — never queues behind the cold build
Device logs: completion requests landing during the background rebuild waited on stateLock (3s+ → sora dropped the popup). completion()/hover() now read the atomically-published snapshot facade without the lock; mutations keep the lock. setWorkspaceMetadata also moves its heavy rebuild to the background thread and bumps the generation so the running/next background build picks up the new metadata (the attempts-loop re-run already handles that).
1 parent 13e6f78 commit f040a1e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

‎src/jvmMain/kotlin/io/github/dingyi222666/luaparser/lsp/LuaLanguageService.kt‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,23 @@ class LuaLanguageService(
374374
return result.affectedDocuments
375375
}
376376

377-
fun setWorkspaceMetadata(metadata: Map<String, String>): Unit = synchronized(stateLock) {
378-
workspaceGeneration += 1
379-
workspaceMetadata = metadata.toMap()
380-
// Configuration that invalidates global metadata falls back to a full rebuild.
381-
rebuildFull()
382-
Unit
377+
fun setWorkspaceMetadata(metadata: Map<String, String>): Unit {
378+
// Store + bump generation under lock, then run the heavy rebuild on the
379+
// background thread (scheduleBackgroundRebuild no-ops if one is already
380+
// running; its post-build moved-check re-runs with the NEW metadata).
381+
// A synchronous rebuild here blocked every completion/hover request for
382+
// the whole 13-18s dex+corpus build on device.
383+
val changed = synchronized(stateLock) {
384+
val moved = workspaceMetadata != metadata.toMap()
385+
if (moved) {
386+
workspaceGeneration += 1
387+
workspaceMetadata = metadata.toMap()
388+
}
389+
moved
390+
}
391+
if (changed) {
392+
scheduleBackgroundRebuild()
393+
}
383394
}
384395

385396
/**

0 commit comments

Comments
 (0)