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

Switch to sbt for Scala #459

Open
plokhotnyuk opened this issue Mar 30, 2023 · 5 comments
Open

Switch to sbt for Scala #459

plokhotnyuk opened this issue Mar 30, 2023 · 5 comments

Comments

@plokhotnyuk
Copy link
Contributor

plokhotnyuk commented Mar 30, 2023

It will allow to run with JVM JIT or as a binary compiled to the native code by GraalVM or Scala Native.

Here is an example of such project.

@plokhotnyuk
Copy link
Contributor Author

Below are results of running the Example02 class of the same project for validation of JSON from the system input:

andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time java -jar .jvm/target/scala-3.2.2/jsoniter-scala-examples-assembly-0.1.0-SNAPSHOT.jar < ./US_CDI.json 

real	0m2,111s
user	0m2,471s
sys	0m0,111s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time java -jar .jvm/target/scala-3.2.2/jsoniter-scala-examples-assembly-0.1.0-SNAPSHOT.jar < ./US_Crime.json 

real	0m14,445s
user	0m14,661s
sys	0m0,376s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time .jvm/target/native-image/jsoniter-scala-examples < ./US_CDI.json 

real	0m1,084s
user	0m1,008s
sys	0m0,076s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time .jvm/target/native-image/jsoniter-scala-examples < ./US_Crime.json 

real	0m7,525s
user	0m7,189s
sys	0m0,336s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time .native/target/scala-3.2.2/jsoniter-scala-examples-out < ./US_CDI.json 

real	0m0,828s
user	0m0,752s
sys	0m0,076s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time .native/target/scala-3.2.2/jsoniter-scala-examples-out < ./US_Crime.json 

real	0m6,036s
user	0m5,652s
sys	0m0,384s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ time java -XX:+UseParallelGC -jar .jvm/target/scala-3.2.2/jsoniter-scala-examples-assembly-0.1.0-SNAPSHOT.jar < ./US_CDI.json 

real	0m2,250s
user	0m2,576s
sys	0m0,096s
andriy@notebook:~/Projects/com/github/plokhotnyuk/jsoniter-scala/jsoniter-scala-examples$ ls -al *.json
-rw-rw-r-- 1 andriy andriy  659284748 sty 30 13:10 US_CDI.json
-rw-rw-r-- 1 andriy andriy 4199339253 mar  6 13:00 US_Crime.json

Both JSON files were downloaded from https://catalog.data.gov/dataset/?res_format=JSON

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Apr 3, 2023

Here is a top-down analysis with perf:

image

@nuald
Copy link
Collaborator

nuald commented Apr 3, 2023

Scala tests target Scala 3 that could be not compatible with Scala Native (so it's more that just using another build system as used libraries target Scala 3 too).

GraalVM is orthogonal to Scala, and that would be just testing JVM-based program on GraalVM. While it makes sense (as TruffleRuby tests are also running on GraalVM), it again has nothing to do with the build system.

All contributions are welcome, but it's not a priority. If you would like to see additional Scala tests, I'd recommend to rather extend the existing build process:

  • use GraalVM as alternative JVM (it's a little bit tricky as we can't just add GraalVM binaries into the PATH, so I guess the additional environment variable that has GraalVM path could be handy);
  • download and install Scala Native (it's a again a little bit tricky as they don't provide the direct binaries to use). I guess sbt could be used for that though, however it would be different projects anyway as the current code is probably not compatible with Snort Native anyway.

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented Apr 4, 2023

The latest Scala 3 release (3.2.2, not 3.3.0-RC3) is supported by Scala Native.

The sbt is a standard and the most advanced build tool for Scala it has a binary installation and could be easily installed by different packet managers: https://www.scala-sbt.org/download.html

This tool can easily build an uber jar, native-image with Scala Native or GraalVM using the same Scala sources as it is done in this project.

We have a precedent of using cargo in this repository, so other languages could be also honored to use their own build tools.

And the make files can still gather them into one build.

@plokhotnyuk
Copy link
Contributor Author

plokhotnyuk commented May 7, 2023

@nuald As an option scala-cli can be used instead of SBT for building of Scala Native and GraalVM native images as it is done in the similar project

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

No branches or pull requests

2 participants