Skip to content

japgolly/scala-graal

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
doc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

scala-graal

libraryDependencies ++= Seq(
  "com.github.japgolly.scala-graal"  %% "core"           % "2.0.0"
  "com.github.japgolly.scala-graal" %%% "core-js"        % "2.0.0"
  "com.github.japgolly.scala-graal" %%% "ext-boopickle"  % "2.0.0"
  "com.github.japgolly.scala-graal"  %% "ext-prometheus" % "2.0.0"
)

Goals

  • Make it quick, easy and safe to interface with embedded languages from Scala
  • Hide and automate a lot of required GraalVM boilerplate
  • Support React SSR for Scala.JS applications

Demo

import japgolly.scalagraal._

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

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

// Use a basic synchronous JS environment
val ctx = GraalContext()

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

Learning

Features

  • Expressions
    • composition
    • purity
    • result parsing
    • error handling
    • null handling
    • binding typeclasses
    • binding codecs (eg binary/json/whatever)
  • Service
    • single-threaded
    • multi-threaded pool
    • synchronous
    • asynchronous
    • optional time limits
    • before/around/after hooks
    • automatic metrics
  • Warmup
    • ability to warmup VM
    • rules (eg. up to 10000 reps/thread & up to 30 sec | until completes within 20ms)
  • React SSR (Server-Side Rendering)
    • support for rendering JS components from JVM
    • conversion to constant-time (conditionally)
    • window and especially window.location management
  • Integrations
    • Prometheus - export metrics to Prometheus
    • BooPickle - marshall data back and forth using binary codecs

About

Make usage of Graal features easy and safe from Scala. Also features Scala-based React SSR.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages