fix: run NSRunningApplication metadata lookups off main thread with bounded concurrency (#9)#23
Merged
Conversation
…ounded concurrency (#9)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
ProcessSnapshotProvider.resolveMetadata同步调用NSRunningApplication(processIdentifier:),会触发进程属性查询,在进程已退出或大量进程时可能产生延迟。虽然在 actor 线程内执行,但 macOS 内部可能仍路由到主线程,容易成为瓶颈。maxMetadataLookupsPerSnapshot = 48只限制了参与排序的进程数量,不是全局 metadata 查询的并发限制。解决方案
snapshot()改为async throws,在 actor 内并发执行 metadata 解析resolveMetadataBatch()使用TaskGroup+Throttleactor 将 metadata 解析任务分散到后台,最大并发数maxConcurrentMetadataLookups = 8TaskGroup.addTask内执行NSRunningApplication查询,实际运行在 Swift 协程后台线程,不阻塞 actorAppMetadata/CachedMetadata/RawProcess标记为Sendable,满足 actor isolated 约束行为变化
NSRunningApplication内部路由阻塞refreshMetadataCache串行写入Closes #9