Skip to content

Improve lock performance#220

Draft
kmcbride wants to merge 2 commits into
spotify:masterfrom
kmcbride:lock-performance
Draft

Improve lock performance#220
kmcbride wants to merge 2 commits into
spotify:masterfrom
kmcbride:lock-performance

Conversation

@kmcbride
Copy link
Copy Markdown
Collaborator

Replaces existing NSRecursiveLock and serial DispatchQueue synchronization with unfair locks. This isn't using OSAllocatedUnfairLock due to the supported deployment targets, but it's something to consider in the future.

Benchmark Before After Speedup
Lock.synchronized (100k) 0.013s 0.011s 1.2x
Synchronized read (100k) 0.044s 0.014s 3.1x
Synchronized write (100k) 0.029s 0.015s 1.9x
Synchronized mutate (100k) 0.043s 0.014s 3.1x
Synchronized compareAndSwap (100k) 0.044s 0.014s 3.1x
Contended mutate (4 threads, 10k each) 0.133s 0.009s 14.8x
Contended mixed R/W (4 threads, 5k each) 0.142s 0.015s 9.5x
EffectExecutor emit (10k) 0.037s 0.021s 1.8x
EffectExecutor concurrent (4 threads, 2.5k) 0.042s 0.028s 1.5x
ThreadSafeConnectable accept (10k) 0.002s 0.002s ~same
ThreadSafeConnectable concurrent (4 threads) 0.009s 0.006s 1.5x

There's also an additional tweak with a much more modest (~10%) improvement for resolving route handlers.

Comment thread MobiusCore/Source/EffectHandlers/ThreadSafeConnectable.swift Outdated
@kmcbride kmcbride marked this pull request as draft April 16, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant