From df0b99771038e2880339fa7e4650b8d82bcb1e5a Mon Sep 17 00:00:00 2001 From: Flavio Brasil Date: Sat, 14 Oct 2023 14:38:24 -0700 Subject: [PATCH] optimization: cache ClassTag[Token] to avoid thread blocking --- core/src/main/scala/sttp/model/UriInterpolator.scala | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/scala/sttp/model/UriInterpolator.scala b/core/src/main/scala/sttp/model/UriInterpolator.scala index a18463ec..0481e494 100644 --- a/core/src/main/scala/sttp/model/UriInterpolator.scala +++ b/core/src/main/scala/sttp/model/UriInterpolator.scala @@ -5,6 +5,7 @@ import sttp.model.internal.{ArrayView, FastCharSet, FastCharMap, ParseUtils, Rfc import scala.annotation.tailrec import scala.collection.immutable.VectorBuilder import scala.collection.mutable.ArrayBuffer +import scala.reflect.ClassTag trait UriInterpolator { implicit class UriContext(val sc: StringContext) { @@ -43,6 +44,10 @@ object UriInterpolator { private val startingUri = Uri(None, None, Uri.EmptyPath, Nil, None) + // Dynamic class tag resultion uses `synchronized` and can block threads. + // Cache the class tag locally to avoid it. + private implicit val tokenClassTag: ClassTag[Token] = ClassTag(classOf[Token]) + private val builders = List( UriBuilder.Scheme, UriBuilder.UserInfo,