mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
Part B of the dispatchers/thread-caps audit. EventDeduplicator is fed from relay subscription callbacks (AdvancedSearchBarState.trackRelayEvent), which arrive on multiple threads concurrently. It backed a plain mutableSet with a single KmpLock, so every delivery from every relay thread serialized on one monitor. Add ConcurrentSet<E> as a KMP expect/actual util: - jvmAndroid actual: ConcurrentHashMap.newKeySet() — lock-striped writes, lock-free reads, no single cross-thread monitor. - iOS actual: a KmpLock-guarded set (no lock-free set in the K/N stdlib) — same behaviour as before, no regression. The win lands on JVM/Android, which is where the high-throughput event paths run. Point EventDeduplicator at it. Covered by ConcurrentSetTest (commonTest, behaviour) and ConcurrentSetConcurrencyTest (jvmTest, exactly-one-add-per-key under 8 threads). Scope note: the other two commonMain sites the audit flagged were left as-is on purpose. The compose subscription managers' KmpLock is a deliberate, documented KMP choice on a single (main-thread) writer where the lock is effectively free; EOSECache is a bounded LRU with compound value mutation on a per-subscription (not per-event) path. Neither is a clean fit for a concurrent set, and converting them would fight a documented decision for negligible gain. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ANuUziXKRafSTBxbh4SMoq