We use caching to speed up LightTypeTag creation on Scala 2, we might want to port this technique to Scala 3 implementation also.
We can also improve Scala 2 caching, e.g. right now we cache individual AbstractReference's, but we don't cache basesDb or InheritanceDb (or we could cache the entire serialized LTT instead)
Implementation plan
Currently Scala 2 implementation caches individual AbstractReferences and Scala 3 caches nothing.
Important: some contributors tried to introduce caches at TagMacro. TagMacro is the high-level entrypoint, while we may try to introduce cache there, in my opinion that's the least beneficial location, because the internal machinery does not recurse to TagMacro while building tags. My advice would be to keep the TagMacro-level caches under a separate option (and port this technique to Scala 2), but we should concentrate on LightTypeTag and its underlying structures.
I think that we should do the following:
- Add tree-level caching at
TagMacro level to Scala 2 implementation
- Explore the possibility of adding tree-level caching into
LightTypeTag in both Scala versions
- Add individual value-level caching to Scala 3 implementation
- Explore our idea of caching the content of
basesDbs and inheritanceDbs
- Probably the most beneficial we should try to cache serialized form of the type tags! Cache key is the type which is being inspected, cache value is the serialized form of the tag!
- For each type of cache we implement, we would need to introduce a separate on/off flag
- Relying on the benchmarks, we would have to figure out what cache types are the most beneficial and turn them on by default
I believe, that there is a good potential to significant compilation speed improvement.
Important notes:
- The values in our caches MUST be wrapped into
SoftReferences. It's ok to recompute but it's not OK to crash the compiler by heap exhaustion.
- We should pay attention to using correct and efficient cache keys
For potential contributors: don't waste your tokens unless you have some understanding of what exactly you are doing! So far all the fully automated attempts to use LLMs failed on this issue, but in fact it's a simple mechanical job!
We use caching to speed up LightTypeTag creation on Scala 2, we might want to port this technique to Scala 3 implementation also.
We can also improve Scala 2 caching, e.g. right now we cache individual AbstractReference's, but we don't cache basesDb or InheritanceDb (or we could cache the entire serialized LTT instead)
Implementation plan
Currently Scala 2 implementation caches individual
AbstractReferences and Scala 3 caches nothing.Important: some contributors tried to introduce caches at
TagMacro.TagMacrois the high-level entrypoint, while we may try to introduce cache there, in my opinion that's the least beneficial location, because the internal machinery does not recurse toTagMacrowhile building tags. My advice would be to keep theTagMacro-level caches under a separate option (and port this technique to Scala 2), but we should concentrate onLightTypeTagand its underlying structures.I think that we should do the following:
TagMacrolevel to Scala 2 implementationLightTypeTagin both Scala versionsbasesDbs andinheritanceDbsI believe, that there is a good potential to significant compilation speed improvement.
Important notes:
SoftReferences. It's ok to recompute but it's not OK to crash the compiler by heap exhaustion.For potential contributors: don't waste your tokens unless you have some understanding of what exactly you are doing! So far all the fully automated attempts to use LLMs failed on this issue, but in fact it's a simple mechanical job!