rorygraves / scalac_perf

The Scala programming language
http://www.scala-lang.org/
16 stars 3 forks source link

rework PerRunLazy #30

Open mkeskells opened 6 years ago

mkeskells commented 6 years ago

maybe something like


  def perRunEager[T](component: PerRunInit)(init: => T): EagerVal[T] = {
    val r = new EagerVal(() => init)
    component.onUse(r.reInitialize())
    component.onUnused(r.reset())
    r
  }
  class EagerVal[T](init: () => T) {
    private[this] var v: T = _
    def apply: T = v
    def reset(): Unit = v = null.asInstanceOf[T]
    def reInitialize(): Unit = {v = init()}

then usage is like

  val x = perRunEager(comp)(() => true)...

  val y = x()

lots of things depend on settings, so should be able to depend on the settings changing, and able to maintain a cache that can be reused between runs, and maybe made soft between runs

we should include options to allow pre-initialisation to occur in background so ths bay be runsensitive cache?