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

Regression in use of Future InternalExecutor #7861

Closed
scabug opened this issue Sep 20, 2013 · 2 comments
Closed

Regression in use of Future InternalExecutor #7861

scabug opened this issue Sep 20, 2013 · 2 comments

Comments

@scabug
Copy link

scabug commented Sep 20, 2013

% git show da54f34a6526b --stat
commit da54f34a6526b49b9e13e60c4fce242325c1c36e
Author: Viktor Klang <viktor.klang@gmail.com>
Date:   Wed Jun 19 23:16:53 2013 +0200

    Cleaning up method implementations in Future
        Optimizations:
        1) Avoiding isDefinedAt + apply and using applyOrElse to allow for optimizations later
        2) Reducing method sizes to be more JIT + inliner friendly
        3) Reusing core combinators to reuse inliner/JIT optimizations and be more code-cache friendly

 src/library/scala/concurrent/Future.scala | 181 ++++++++++++++++++++---------------------------------------------------------------
 1 file changed, 44 insertions(+), 137 deletions(-)

% scala-hash da54f34a6526b~1 test/files/run/future-flatmap-exec-count.scala
[info] da54f34a65 => /Users/jason/usr/scala-v2.10.1-318-g70e2ead
execute()
called continuation

% scala-hash da54f34a6526b test/files/run/future-flatmap-exec-count.scala
[info] da54f34a65 => /Users/jason/usr/scala-v2.10.1-319-gda54f34
execute()
called continuation
execute()

% cat test/files/run/future-flatmap-exec-count.scala
import scala.concurrent._
import java.util.concurrent.atomic.AtomicInteger

object Test {
  def main(args: Array[String]) {
    test()
  }

  def test() = {
    val p = Promise[Int]()
    val fp = p.future
    val ec = new TestExecutionContext(ExecutionContext.Implicits.global)

    val flatMapped = fp.flatMap({ (x: Int) =>
      println("called continuation")
      Future.successful(2 * x)
    })(ec)
    p.success(111)
    Await.result(flatMapped, duration.Duration.Inf)
  }

  class TestExecutionContext(delegate: ExecutionContext) extends ExecutionContext {
    def execute(runnable: Runnable): Unit = ???

    def reportFailure(t: Throwable): Unit = ???

    override def prepare(): ExecutionContext = {
      val preparedDelegate = delegate.prepare()
      return new ExecutionContext {
        def execute(runnable: Runnable): Unit = {
          println("execute()")
          preparedDelegate.execute(runnable)
        }

        def reportFailure(t: Throwable): Unit = ???
      }
    }
  }
}

@scabug
Copy link
Author

scabug commented Sep 20, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7861?orig=1
Reporter: @retronym
Affected Versions: 2.10.3-RC1

@scabug
Copy link
Author

scabug commented Sep 20, 2013

@retronym said:
scala/scala#2969

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants