No description, website, or topics provided.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark/src/main
core/src
ext-boopickle
ext-prometheus/src
project
.gitignore
LICENCE
README.md
build.sbt
version.sbt

README.md

I've begun work on #Scala / @graalvm integration. My goals:

  • FP & nice ergonomics from Scala
  • Performance & multithreading
  • React SSR

https://twitter.com/japgolly/status/1058657919254679552

Demo

// Use semantics and implicit config for JS
// (Graal also supports Python, R, Ruby, LLVM)
import GraalJs._

// 1. Pre-compile expression functions for fast invocation.
// 2. Typeclasses determine how to translate and/or marshall data from Scala to JS.
val expr: (Int, Int) => Expr[String] =
  Expr.compile2((a, b) => s"($a + $b) * 2 + '!'")(_.asString)

// Let's use a single synchronous JS evaluator/environment
val ctx = ContextSync()

val result = ctx.eval(expr(3, 8))
assert(result == Right("22!"))

Demo: Call Scala.JS from JVM (binary protocol)

Shared code:

import boopickle.Default._

final case class ScalaData(a: Int, b: Int)
object ScalaData {
  // Binary format shared between JVM & JS
  implicit val pickler: Pickler[ScalaData] = generatePickler
}

Scala.JS code:

@JSExportTopLevel("myScalaJsFn") // This is how we'll call this fn from the JVM
def demo(p: Pickled[ScalaData]): String =
  s"a is ${p.value.a} and b is ${p.value.b}"

Scala (JVM) code:

val expr =
  for {
    _  Expr.requireFileOnClasspath("my_scalajs-fastopt.js") // Load our Scala.JS code
    d = ScalaData(9999,3)                                    // Data to be converted JVM → binary → Scala.JS
    s  Expr.callFn1("myScalaJsFn", d).asString              // Call Scala.JS with a case class
  } yield s

val result = ContextSync().eval(expr)
assert(result == Right("a is 9999 and b is 3"))

Roadmap

  • expressions
    • composition
    • purity
    • parse results
    • error handling
    • null handling
    • binding interpolation (REMOVED)
    • binding typeclasses
    • bindind codec (eg binary/json)
  • service
    • before/around/after hooks
    • single
    • multi-threaded service
      • fixed pool
      • shutdown
    • synchronous with time limit
    • synchronous resource pool (?)
    • pure scheduling & execution (?)
    • higher-level profunctor-like (?)
    • metrics
    • metrics: labels from Expr
    • caching (?)
  • warmup
    • rules - eg. up to 10000 reps/thread & up to 30 sec | until completes within 20ms
    • on idle (?)
    • implement results of warmpup discussion with graal team
  • React SSR
    • render util (so one needn't write direct JS) (?)
    • window and especially window.location management
    • test util
    • howto guide
      • SBT howto
      • JS deps howto (webpack|SBT)
      • main scala howto
      • testing howto
      • Graal flags?
      • jetty
  • Integration
    • Scalaz (?)
    • Cats (?)
    • Cats Effect (?)
    • Prometheus
    • BooPickle
    • circe (?)
    • clear-config
    • caffiene (?)
  • build
    • travis
    • tut