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

Overcompilation when no files have changed #3198

Closed
keynmol opened this issue Sep 23, 2024 · 4 comments
Closed

Overcompilation when no files have changed #3198

keynmol opened this issue Sep 23, 2024 · 4 comments
Labels
duplicate This issue or pull request already exists performance Issues concerning performance of the CLI. Scala Native scripting Issues tied to *.sc script inputs.

Comments

@keynmol
Copy link
Contributor

keynmol commented Sep 23, 2024

Version(s)
1.5.0

Describe the bug
When doing scala-cli run . --native, it seems that the project is being recompiled (I can see warnings being re-emitted) even though nothing has changed:

/v/f/j/4/T/tmp.d938Ip9W80 > scli run . --native
Compiling project (Scala 3.5.1, Scala Native 0.5.5)
[warn] ./test.scala:6:7
[warn] unused local definition
[warn]   val x = 25
[warn]       ^
Compiled project (Scala 3.5.1, Scala Native 0.5.5)
[info] Linking (multithreadingEnabled=true, disable if not used) (1046 ms)
[info] Discovered 888 classes and 5362 methods after classloading
[info] Checking intermediate code (quick) (41 ms)
[info] Multithreading was not explicitly enabled - initial class loading has not detected any usage of system threads. Multithreading support will be disabled to improve performance.
[info] Linking (multithreadingEnabled=false) (317 ms)
[info] Discovered 510 classes and 2557 methods after classloading
[info] Checking intermediate code (quick) (23 ms)
[info] Discovered 487 classes and 1958 methods after optimization
[info] Optimizing (debug mode) (396 ms)
[info] Produced 9 LLVM IR files
[info] Generating intermediate code (395 ms)
[info] Compiling to native code (932 ms)
[info] Linking with [pthread, dl]
[info] Linking native code (immix gc, none lto) (138 ms)
[info] Postprocessing (0 ms)
[info] Total (3314 ms)
yes
/v/f/j/4/T/tmp.d938Ip9W80 > scli run . --native
[warn] ./test.scala:6:7
[warn] unused local definition
[warn]   val x = 25
[warn]       ^
yes
/v/f/j/4/T/tmp.d938Ip9W80 > scli run . --native
[warn] ./test.scala:6:7
[warn] unused local definition
[warn]   val x = 25
[warn]       ^
yes

This adds overhead to the command, where actually running the binary takes 2ms on my laptop, but running scala-cli run . --native takes 30ms, even though it literally just runs the binary (or at least should). A user reports even higher overhead on a non-trivial program.

I don't know if Bloop actually compiles anything, but this certainly takes quite a bit of time (in relative terms)

To Reproduce

//> using toolkit default
//> using option -Wunused:all
//> using scala 3.5.1

@main def hello = 
  val x = 25
  println("yes")

Then run scala-cli run . --native a bunch of times. Warnings are re-emitted every time. Running with -v -v actually shows the bloop request being sent.

Expected behaviour

When no input files or parameters have changed, I expect the overhead of scala-cli run to be much lower.

@keynmol keynmol added the bug Something isn't working label Sep 23, 2024
@tgodzik
Copy link
Member

tgodzik commented Sep 23, 2024

I think we always send last warnings and do not compile anything inside Bloop. This is a correct behaviour in my opinion.

On the other hand though, I don't really understand the overhead. If we have no warnings present is it still an issue?

@keynmol
Copy link
Contributor Author

keynmol commented Sep 23, 2024

Heh, the overhead is even larger :D

/v/f/j/4/T/tmp.d938Ip9W80 > time scli run . --native
yes

________________________________________________________
Executed in  398.86 millis    fish           external
   usr time   46.06 millis    0.18 millis   45.89 millis
   sys time   36.60 millis    1.74 millis   34.86 millis

Actually here's a better view:

Benchmark 1: scala-cli run . --native
  Time (mean ± σ):     425.3 ms ±   8.0 ms    [User: 45.1 ms, System: 32.2 ms]
  Range (min … max):   413.3 ms … 438.0 ms    10 runs

Benchmark 2: ./.scala-build/tmp_e396f26dc8/native/main
  Time (mean ± σ):       1.7 ms ±   0.6 ms    [User: 0.6 ms, System: 0.6 ms]
  Range (min … max):     0.7 ms …   4.8 ms    561 runs

  Warning: Command took less than 5 ms to complete. Note that the results might be inaccurate because hyperfine can not calibrate the shell startup time much more precise than this limit. You can try to use the `-N`/`--shell=none` option to disable the shell completely.

Summary
  ./.scala-build/tmp_e396f26dc8/native/main ran
  244.94 ± 85.66 times faster than scala-cli run . --native

@tgodzik
Copy link
Member

tgodzik commented Sep 23, 2024

This might be related to #3158

@Gedochao Gedochao added Scala Native scripting Issues tied to *.sc script inputs. performance Issues concerning performance of the CLI. duplicate This issue or pull request already exists and removed bug Something isn't working labels Sep 24, 2024
@Gedochao
Copy link
Contributor

Seems to me this is a duplicate of #3158. Let's track it there.

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists performance Issues concerning performance of the CLI. Scala Native scripting Issues tied to *.sc script inputs.
Projects
None yet
Development

No branches or pull requests

3 participants