Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implemented compile time caching for scala 3 #518

Closed
wants to merge 1 commit into from

Conversation

ARYPROGRAMMER
Copy link

This PR fixes #350 by implementing compile-time caching in the Scala 3 macro by storing the computed string representation of LightTypeTag

Both cached and non‑cached variants now produce full LightTypeTags (not just partial references).
A new benchmark (TagCachingBenchmark) demonstrates the performance difference between the two modes.
We compare the new cached implementation against the previous non‑cached variant using the provided benchmark.

Testing:

In the project root (/path-whatever/izumi-reflect), run: ▸ sbt compile
Run the benchmark: ▸ sbt "runMain benchmarks.TagCachingBenchmark"
Verify that the printed timings show that the cached version is faster after the warm-up

this applies the caching technique to the Scala 3 macro, extending it for full Tag generation, and includes a benchmark that proves the cache’s benefit.

demo1
demo2

/claim #350

Copy link

algora-pbc bot commented Feb 9, 2025

💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe.

Copy link
Member

@pshirshov pshirshov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caching mechanism must be integrated into existing introspection macros, every time a type to be inspected, the cache should be checked first.

case None =>
val tpeStr = Type.show[T]
var dummy = 0L
for(i <- 1 to 10000) { dummy += i }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop is a dummy heavy computation meant to simulate an expensive operation during LightTypeTag creation. It's only for benchmarking purposes, so you can see the caching benefit by comparing the cached version to one that always runs this costly computation.

@pshirshov pshirshov closed this Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement compile-time caching for Scala 3
2 participants