diff --git a/serialization-deterministic/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializerFactories.kt b/serialization-deterministic/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializerFactories.kt index 8e1d0465c1..e3f74f2db9 100644 --- a/serialization-deterministic/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializerFactories.kt +++ b/serialization-deterministic/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializerFactories.kt @@ -21,6 +21,7 @@ private class DeterministicSerializerFactoryFactory : SerializerFactoryFactory { serializersByType = mutableMapOf(), serializersByDescriptor = mutableMapOf(), customSerializers = ArrayList(), + customSerializersCache = mutableMapOf(), transformsCache = mutableMapOf() ) } diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializerFactory.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializerFactory.kt index bba29c007a..b18c4cccbe 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializerFactory.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/SerializerFactory.kt @@ -25,6 +25,8 @@ import javax.annotation.concurrent.ThreadSafe data class SerializationSchemas(val schema: Schema, val transforms: TransformsSchema) @KeepForDJVM data class FactorySchemaAndDescriptor(val schemas: SerializationSchemas, val typeDescriptor: Any) +@KeepForDJVM +data class CustomSerializersCacheKey(val clazz: Class<*>, val declaredType: Type) /** * Factory of serializers designed to be shared across threads and invocations. @@ -56,6 +58,7 @@ open class SerializerFactory( private val serializersByType: MutableMap>, val serializersByDescriptor: MutableMap>, private val customSerializers: MutableList, + private val customSerializersCache: MutableMap?>, val transformsCache: MutableMap>>, private val onlyCustomSerializers: Boolean = false ) { @@ -74,6 +77,7 @@ open class SerializerFactory( ConcurrentHashMap(), CopyOnWriteArrayList(), ConcurrentHashMap(), + ConcurrentHashMap(), onlyCustomSerializers ) @@ -377,6 +381,13 @@ open class SerializerFactory( } internal fun findCustomSerializer(clazz: Class<*>, declaredType: Type): AMQPSerializer? { + return customSerializersCache.computeIfAbsent(CustomSerializersCacheKey(clazz, declaredType), ::doFindCustomSerializer) + } + + private fun doFindCustomSerializer(key: CustomSerializersCacheKey): AMQPSerializer? { + + val (clazz, declaredType) = key + // e.g. Imagine if we provided a Map serializer this way, then it won't work if the declared type is // AbstractMap, only Map. Otherwise it needs to inject additional schema for a RestrictedType source of the // super type. Could be done, but do we need it? @@ -389,7 +400,7 @@ open class SerializerFactory( || !customSerializer.isSerializerFor(declaredSuperClass) || !customSerializer.revealSubclassesInSchema ) { - logger.info ("action=\"Using custom serializer\", class=${clazz.typeName}, " + + logger.debug("action=\"Using custom serializer\", class=${clazz.typeName}, " + "declaredType=${declaredType.typeName}") @Suppress("UNCHECKED_CAST")