rust-lang / docker-rust

The official Docker images for Rust
436 stars 88 forks source link

cargo build and cargo run is very slow #62

Closed vairamsvsjdo closed 4 years ago

vairamsvsjdo commented 4 years ago

Environment: windows 10: docker latest with wsl2 Docker version 19.03.8, build afacb8b docker-compose version 1.26.0-rc4, build d279b7a8

cargo build and cargo run is very slow. What needs to be done to improve compile time?

  1. created Dockerfile
FROM rust:1.31

WORKDIR /work

#RUN cargo install --path .

#CMD ["myapp"]
  1. created a folder work
mkdir work
  1. created a docker-compose.yml file
version: '3'
services:
  testrust:
    image: rust:latest
    volumes:
      - "./work:/work"
    environment:
      - "USER=vairamsvsjdo"
    working_dir: /work
  1. run docker-compose
docker-compose run testrust
  1. created a default rust app
root@ca05f88b00c6:/work# cargo init
     Created binary (application) package
  1. did cargo run and noticed it took 2.01s to build
root@ca05f88b00c6:/work# cargo run
   Compiling work v0.1.0 (/work)
    Finished dev [unoptimized + debuginfo] target(s) in 2.01s
     Running `target/debug/work`
Hello, world!

6. added 1,2,3 to end of Hello World and did cargo run to notice that it took 2.16s to compile and run

```bash
root@ca05f88b00c6:/work# cargo run
   Compiling work v0.1.0 (/work)
    Finished dev [unoptimized + debuginfo] target(s) in 2.16s
     Running `target/debug/work`
Hello, world 1,2,3!

7. did cargo run again to notice that it ran in 0.10s

```bash
root@ca05f88b00c6:/work# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/work`
Hello, world 1,2,3!
  1. to confirm the performance added ",4" text and noticed that the compile and run took again 2.14s and subsequent run in 0.12s. What needs to be done to improve compile time?
root@ca05f88b00c6:/work# cargo run
   Compiling work v0.1.0 (/work)
    Finished dev [unoptimized + debuginfo] target(s) in 2.14s
     Running `target/debug/work`
Hello, world 1,2,3,4!
root@ca05f88b00c6:/work# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/work`
Hello, world 1,2,3,4!
vairamsvsjdo commented 4 years ago

The most time consumed and lag is due to the buld time

root@11c937647f1b:/work# cargo build 
   Compiling work v0.1.0 (/work)
    Finished dev [unoptimized + debuginfo] target(s) in 1.86s
root@11c937647f1b:/work# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/work`
Hello, world 1,2,3,4,5!
sfackler commented 4 years ago

Stack overflow, the /r/rust subreddit, or users.rust-lang.org would be a better place to ask general questions like this.

vairakkumaar-svs-hf commented 4 years ago

I felt there is a performance issue with the compiler.

sfackler commented 4 years ago

This is not the issue tracker for the compiler either.