The JIT runtime
The kscript you install is compiled ahead of time, which is why it starts in milliseconds and needs no .NET. What that build can't do is compile a script's busy loops and functions to machine code as it runs, which makes loops and number work several times faster, and tight loops over numbers many times faster. Each release also ships the same kscript as a .NET program that can: the JIT runtime (the kscript-runtime-<platform> archive, which kscript compile also builds programs from).
kscript serve runs on the JIT runtime. The first time, kscript downloads the one for its own version, checks it against the release's SHA256SUMS and keeps it in ~/.kscript/runtimes (%LOCALAPPDATA%\kscript\runtimes on Windows), saying so in one line. Then the runtime serves in its place, with the same arguments, folder, environment and terminal, so Ctrl+C, docker stop and the exit code work as before. When the runtime can't be downloaded, such as offline or in a kscript you built yourself, the server runs in the installed kscript and says why in one line.
Scripts run in the installed kscript, because the JIT runtime takes about a third of a second longer to start, which most scripts never win back. A script that spends seconds in loops can ask for it:
| Command | What it does |
|---|---|
kscript --jit solve.kscript | This run. |
kscript serve --no-jit | Serve from the installed kscript. |
| Setting | Scripts | kscript serve |
|---|---|---|
--jit / --no-jit |
on / off for this run (before the script's name) | on / off for this run |
KSCRIPT_JIT=1 / KSCRIPT_JIT=0 |
on / off | on / off |
"jit": true / "jit": false in kscript.json |
on / off for the project | on / off for the project |
| nothing | off | on |
The flag wins over the variable, and the variable over kscript.json.
kscript version says where the JIT compiler is. kscript version jit downloads the runtime now, so that a Docker image or a CI job has it before kscript serve first runs:
RUN kscript version jitA kscript built with dotnet build or dotnet run has the JIT compiler already, and never hands over.