Skip to content

Commit e2f6e4e

Browse files
committed
Cache decoding failures
1 parent 379361e commit e2f6e4e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/scala/ch/epfl/scala/decoder/internal/CachedBinaryDecoder.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import tastyquery.Symbols.*
66
import ch.epfl.scala.decoder.*
77

88
import scala.collection.concurrent.TrieMap
9+
import scala.util.Try
910

1011
class CachedBinaryDecoder(using Context, ThrowOrWarn) extends BinaryDecoder:
11-
private val classCache: TrieMap[String, DecodedClass] = TrieMap.empty
12-
private val methodCache: TrieMap[(String, binary.SignedName), DecodedMethod] = TrieMap.empty
13-
private val liftedTreesCache: TrieMap[Symbol, Seq[LiftedTree[?]]] = TrieMap.empty
12+
// even failures can be quite expensive, so we cache them
13+
private val classCache: TrieMap[String, Try[DecodedClass]] = TrieMap.empty
14+
private val methodCache: TrieMap[(String, binary.SignedName), Try[DecodedMethod]] = TrieMap.empty
15+
private val liftedTreesCache: TrieMap[Symbol, Try[Seq[LiftedTree[?]]]] = TrieMap.empty
1416

1517
override def decode(cls: binary.ClassType): DecodedClass =
16-
classCache.getOrElseUpdate(cls.name, super.decode(cls))
18+
classCache.getOrElseUpdate(cls.name, Try(super.decode(cls))).get
1719

1820
override def decode(method: binary.Method): DecodedMethod =
19-
methodCache.getOrElseUpdate((method.declaringClass.name, method.signedName), super.decode(method))
21+
methodCache.getOrElseUpdate((method.declaringClass.name, method.signedName), Try(super.decode(method))).get
2022

2123
override protected def collectAllLiftedTrees(owner: Symbol): Seq[LiftedTree[?]] =
22-
liftedTreesCache.getOrElseUpdate(owner, super.collectAllLiftedTrees(owner))
24+
liftedTreesCache.getOrElseUpdate(owner, Try(super.collectAllLiftedTrees(owner))).get

0 commit comments

Comments
 (0)