Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.0-beta05 - Performance Benchmarks #115

Merged
merged 36 commits into from
Dec 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ff44402
[wip] add some metrics computation code setup
Nek-12 Nov 28, 2024
c58b692
chore: setup benchmarks module
Nek-12 Nov 28, 2024
20be1c2
feat: set up benchmark comparing FMVI and traditional setup
Nek-12 Nov 28, 2024
7fb8a5e
[wip] compare performance with fluxo
Nek-12 Nov 28, 2024
34edd52
enable parallel benchmark
Nek-12 Nov 28, 2024
09b3dc7
use better optimized fluxo store config for benchmarks
Nek-12 Nov 29, 2024
7a52c13
add start/stop benchmarks for fmvi and fluxo
Nek-12 Nov 29, 2024
964c419
fix: fix benchmarks
Nek-12 Dec 5, 2024
41d0019
api: Improve performance of updateStateImmediate
Nek-12 Dec 5, 2024
6996c65
fix: remove suspend channel calls due to perf overhead
Nek-12 Dec 5, 2024
2763c3e
feat: Optimize intent reduction
Nek-12 Dec 5, 2024
0c2a6f4
feat: optimize recover performance
Nek-12 Dec 5, 2024
fee4e92
chore: bump agp
Nek-12 Dec 7, 2024
de111b3
api: optimize state property accessor to be inline
Nek-12 Dec 7, 2024
4983b04
feat: optimize performance of atomic state updates by reusing context
Nek-12 Dec 7, 2024
727a223
feat: skip recover machinery when there is no handler defined
Nek-12 Dec 7, 2024
9428965
feat: implement StateStrategy with new optimized atomic behavior
Nek-12 Dec 7, 2024
5d5d4f8
feat: implement validations for non-reentrant store's recursive state…
Nek-12 Dec 7, 2024
42bbe31
fix: prevent store test dsl leaks when test method throws
Nek-12 Dec 7, 2024
c450796
feat: implement allowTransientSubscriptions property to avoid validat…
Nek-12 Dec 7, 2024
fa97c94
chore: implement recursive state updates fix
Nek-12 Dec 7, 2024
c5351e4
chore: fix build
Nek-12 Dec 7, 2024
70cd475
fix: fix kotlin compiler bug with inlined code in try/catch
Nek-12 Dec 8, 2024
6a29cdd
feat: add reset state plugin
Nek-12 Dec 8, 2024
831badb
fix: improve test stability
Nek-12 Dec 8, 2024
1d572c9
feat: add decorator live template, improve plugin live templates
Nek-12 Dec 8, 2024
aef9285
feat: update issue templates
Nek-12 Dec 8, 2024
12811d2
feat: migrate to kodlin.Uuid #108
Nek-12 Dec 8, 2024
cb449be
feat: add periodic saving behavior to saveState plugin #103
Nek-12 Dec 8, 2024
bb80453
chore: fix lint
Nek-12 Dec 8, 2024
12f412e
chore: improve publish workflow to only build on release
Nek-12 Dec 8, 2024
588e694
chore: fix lint (2)
Nek-12 Dec 8, 2024
435d040
chore: do not fail publishing on ide plugin upload error
Nek-12 Dec 8, 2024
70c11bb
chore: bump beta version
Nek-12 Dec 8, 2024
773279c
chore: fix benchmarks
Nek-12 Dec 8, 2024
e3aad21
feat: create benchmark test workflow
Nek-12 Dec 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: optimize performance of atomic state updates by reusing context
Nek-12 committed Dec 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 4983b04acead0c60393f3ceb9da185037ddfdb14
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment
import pro.respawn.flowmvi.benchmarks.setup.optimized.optimizedStore
import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicParallelStore

fun main() = runBlocking {
println(ProcessHandle.current().pid())
val store = optimizedStore(this)
val store = atomicParallelStore(this)
launch {
while (isActive) {
store.intent(Increment)
Original file line number Diff line number Diff line change
@@ -13,8 +13,11 @@ import pro.respawn.flowmvi.api.MVIIntent
import pro.respawn.flowmvi.api.MVIState
import pro.respawn.flowmvi.api.PipelineContext
import pro.respawn.flowmvi.dsl.updateStateImmediate
import pro.respawn.flowmvi.util.ReentrantMutexContextElement
import pro.respawn.flowmvi.util.ReentrantMutexContextKey
import pro.respawn.flowmvi.util.withReentrantLock


internal class StateModule<S : MVIState, I : MVIIntent, A : MVIAction>(
initial: S,
atomic: Boolean,
@@ -24,7 +27,8 @@ internal class StateModule<S : MVIState, I : MVIIntent, A : MVIAction>(
@Suppress("VariableNaming")
private val _states = MutableStateFlow(initial)
override val states: StateFlow<S> = _states.asStateFlow()
private val mutex = if (atomic) Mutex() else null
private val mutex = if (!atomic) null else
Mutex().let(::ReentrantMutexContextKey).let(::ReentrantMutexContextElement)

override fun compareAndSet(expect: S, new: S) = _states.compareAndSet(expect, new)

Original file line number Diff line number Diff line change
@@ -8,14 +8,16 @@ import kotlin.coroutines.coroutineContext
import kotlin.jvm.JvmInline

@PublishedApi
internal suspend inline fun <T> Mutex?.withReentrantLock(crossinline block: suspend () -> T): T {
internal suspend inline fun <T> ReentrantMutexContextElement?.withReentrantLock(
crossinline block: suspend () -> T
): T {
if (this == null) return block()
val key = ReentrantMutexContextKey(this)
val key = this.key
// call block directly when this mutex is already locked in the context
if (coroutineContext[key] != null) return block()
// otherwise add it to the context and lock the mutex
return withContext(ReentrantMutexContextElement(key)) {
withLock { block() }
return withContext(this) {
key.mutex.withLock { block() }
}
}