Skip to content

Commit

Permalink
Properly reuse JsonStringBuilders in CharArrayPool
Browse files Browse the repository at this point in the history
Fixes #1455
  • Loading branch information
qwwdfsad committed May 11, 2021
1 parent 47cfd88 commit d66dccb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal object CharArrayPool {
* and the pool will be populated in the 'release'
*/
val candidate = synchronized(this) {
arrays.lastOrNull()?.also { charsTotal -= it.size }
arrays.removeLastOrNull()?.also { charsTotal -= it.size }
}
return candidate ?: CharArray(128)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kotlinx.serialization.json

import kotlinx.coroutines.*
import kotlinx.serialization.builtins.*
import kotlinx.serialization.test.*
import org.junit.*
import kotlin.concurrent.*
import kotlin.random.*

class ParallelJsonStressTest : JsonTestBase() {
private val iterations = 1_000_000

@Test
fun testDecodeInParallel() = runBlocking<Unit> {
for (i in 1..1000) {
launch(Dispatchers.Default) {
val value = (1..10000).map { Random.nextDouble() }
assertSerializedAndRestored(value, ListSerializer(Double.serializer()))
}
}
}
}

0 comments on commit d66dccb

Please sign in to comment.