Skip to content

Commit

Permalink
Merge pull request #308 from fwbrasil/sttp-opt
Browse files Browse the repository at this point in the history
optimization: cache ClassTag[Token] to avoid thread blocking
  • Loading branch information
adamw authored Oct 15, 2023
2 parents 88d58e8 + df0b997 commit 46c860a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/main/scala/sttp/model/UriInterpolator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 46c860a

Please sign in to comment.