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

[Feat] Scripting with instant startup #3127

Closed
jatcwang opened this issue Aug 25, 2024 · 4 comments
Closed

[Feat] Scripting with instant startup #3127

jatcwang opened this issue Aug 25, 2024 · 4 comments
Labels
enhancement New feature or request package command Scala Native scripting Issues tied to *.sc script inputs.

Comments

@jatcwang
Copy link
Contributor

jatcwang commented Aug 25, 2024

Is your feature request related to a problem? Please describe.

I'd like to be able to write a scala-cli script which supports instant startup (via compiling to native binaries).

Currently scala-cli supports compiling to native binaries via scala-native or GraalVM native-image.

However:

  1. There seems to be be a bit of delay in running scripts even if there are no changes (Around 0.3s on my computer). I'm guessing this is due to compilation (even if it's a no-op)
  2. When using GraalVM native-image, there's no currently no single command to compile and run a script. I think we only have scala-cli --power package --native-image my_script.scala -f -o my_bin to generate the binary.

Describe the solution you'd like

  1. Make change-detection faster (if possible)
  2. Provide a single command to execute a script by first compiling it to GraalVM native binary

If we can make no.1 instant then we would've solved the instant start-up issue for scala-native binaries

Additional Context
In https://github.com/jatcwang/instant-scala, I have a bare-bones wrapper bash script which compares the cached and current hash of the script file and runs the cached native binary if they're the same.

@jatcwang jatcwang added the enhancement New feature or request label Aug 25, 2024
@jatcwang jatcwang changed the title Scripting with instant startup [Feat] Scripting with instant startup Aug 25, 2024
@lbialy
Copy link

lbialy commented Aug 25, 2024

This seems quite contradictory - on one hand you'd want instant startup, something that's only possible with either a hot jvm running in the background or a native binary. On the other hand you'd want this to be be free of native compilation overhead (unconstrained by native-image or scala-native) but also not to leave a running jvm behind. While I'd also want something like that, I don't think you can turn Scala into an interpreted language.

@jatcwang
Copy link
Contributor Author

There were two options I listed

  1. Compile to native binary with faster change detection
  2. Persistent JVM server which executes the scripts a la nailgun

You're right that No.2 contradicts my listed desire to not have a JVM running in the background. I have removed it as it probably makes sense to be its own separate issue. I've updated the OP to focus more on no.1

@Gedochao Gedochao added package command Scala Native scripting Issues tied to *.sc script inputs. labels Sep 2, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Sep 2, 2024

I get the feeling that there's at least 3 different feature requests listed in the discussion above:

  • building a native artifact (with Scala Native or GraalVM) and then running it in a single command
  • reusing native artifacts if they've already been built (we don't detect if it should be rebuilt or not)
  • hot reload JVM for launching scripts a'la nailgun

For us to discuss those and potentially plan them (or more likely, allow an external contributor to pick them up), those would need to be raised as separate feature requests.
The way the requirements are put in this issue, I can't see how we'd start the work on this.

Additionally, we may not be able to consider these things before the package sub-command gets redesigned, as per the discussion in #1794 (which is not even defined in an issue yet, although has been heavily discussed elsewhere).

I'd advise to start a discussion on your use case before raising subsequent feature requests.

@Gedochao
Copy link
Contributor

Gedochao commented Sep 2, 2024

Closing this for now, please re-raise the individual points separately (perhaps a discussion thread would be better first)

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request package command Scala Native scripting Issues tied to *.sc script inputs.
Projects
None yet
Development

No branches or pull requests

3 participants