@RichardWhaling
Scala Love 2020
How Scala Native's dual personalities
relate to two different ecosystems:
And what this tells us about
where Scala Native is effective
But what does Scala without Java mean?
three different aspects:
So how much coverage do we need?
GraalVM's JIT is state-of-the-art for supporting dynamic and functional languages on the JVM
Graal-native-image (SubstrateVM) provides AOT compilation and a lightweight runtime for JVM bytecode
Both are awesome!
But SubstrateVM does not have GraalVM's JIT
Both work on Java bytecode, not Scala code
SN has advantages because it's optimizer has access to Scala code, whereas Graal only gets the JVM output of scalac
SN's optimizer and runtime has comparable performance to Graal, while outputting compact binaries
Graal is better at JVM platform coverage and features
SN is stronger at unsafe memory usage and idiomatic C interop
Next Up: C Interop
SN provides C interop + unsafe/low-level capabilties
But what do we use them for?
the unsafe API provides the following capabilities:
These are all traditionally taught in C, and not often directly exposed in higher-level languages.
My hot take - these are fundamental information structures for low-level programming, and we can do a better job than C at using them
val jPtr:Ptr[Int] = stackalloc[Int]
println(s"jPtr has value ${jPtr} and size ${sizeof[Ptr[Int]]} bytes")
val j:Int = !jPtr
println(s"j has value ${j} and size ${sizeof[Int]}")
!jPtr = 5
println(s"jPtr has value ${jPtr} and size ${sizeof[Ptr[Int]]} bytes")
val j2:Int = !jPtr
println(s"j2 has value ${j2} and size ${sizeof[Int]}, j has value ${j}")
val arraySize = 16 * sizeof[Int]
val allocation:Ptr[Byte] = stdlib.malloc(arraySize)
val intArray = allocation.asInstanceOf[Ptr[Int]]
for (i <- 0 to 16) {
intArray(i) = i * 2
}
for (i <- 0 to 16) {
val address = intArray + i
val item = intArray(i)
val check = !(intArray + i) == intArray(i)
println(s"item $i at address ${intArray + i} has value $item, check: $check")
}
// just to be safe
stdlib.free(allocation)
C-level performance for working with contiguous data
Clean model for interfacing with safe code
Syntax that is easier to write correctly than C
Explicitly model mutability as a type
Access to any C library!
And we still get:
state-of-the-art GC
full Scala FP capabilities
pattern matching
errors & exceptions
immutable data structures, etc
Repeating my caveat - this isn't a fight
Comparing to highlight different capabilities
Understanding where tools complement each other
hot take - the Rust community is challenging the C model, but has yet to demonstrate generality
SN has advantages at very low-level code (pointers, arrays, bit-flipping) as well as high level (FP, GC, immutability)
Go is amazing as long as your domain is well aligned with its provided abstractions
Good at "systems" but at a higher level than C
I could keep going, OCaml is great!
SN has similar strengths but Scala community is larger
Subjectively - Scala is more productive & approachable
Starting with Haoyi's list:
http://www.lihaoyi.com/post/TheDeathofHypeWhatsNextforScala.html
My additions:
These are all more experimental and speculative
(But potentially very high impact)
Creating a new process or VM to serve a request is very sensitive to startup time, binary size, memory usage etc.
Typically billed by seconds of execution x memory usage
SN's low footprint is very hard to beat here
Hardware support is always a challenge but doable
Shadaj Laddad has a 32-bit branch of SN that targets ARM
SN could be really great here:
flipping bits is the essence of embedded programming
LLVM already includes WebAssembly as a target
Surprisingly analogous to embedded - 32 bit, resource constrained, also runs on Shadaj's fork
Hannes Rutz has run SN in a Web Audio oscillator unit
Open question: how does this relate to SJS?
Hot take: to the extent that wasm conquers the world, it demonstrates that the C/linear memory model is general!
Two new classes of hardware peripherals:
1. Non-volatile memory
Two new classes of hardware peripherals:
2. High-speed (10Gbps) NIC
Two new classes of hardware peripherals:
1. Non-volatile memory
2. High-speed (10Gbps) NIC
A language and platform that can build novel abstractions on top of plain linear memory is ideally positioned for these changes
I feel like we could build something genuinely groundbreaking with SN and this class of hardware.