WSL: Very bad performance in WSL (IO Operations)
Version
Microsoft Windows [Version 10.0.22621.1105]
WSL Version
- WSL 2
- WSL 1
Kernel Version
5.4.72
Distro Version
docker-desktop-data
Other Software
Visual Studio Code 1.74.2 Dev Container Extension v0.266.1 Docker Desktop 4.9.0
Repro Steps
I noticed this while working on a REST-API in Rust using axum (a library to create REST APIs). Even small code changes take forever when recompiling the project. The rust compiler is using incremental compilation (which you can verify by using -v on the cargo build command). I assume the issue is very low IO performance.
Prerequisites: Docker Desktop and Visual Studio Code (incl. Dev Container Extension) installed.
- Open Visual Studio Code in an empty folder
- Open the VS Code command prompt and select “Dev Containers: Create Dev Container Configuration Files…”
- Wait until the container has started and run “cargo init” from the terminal
- Run the following commands to configure the dependencies:
cargo add axum
cargo add tokio -F macros -F rt-multi-thread
- Add the following content to main.rs
use axum::{
routing::get,
Router,
};
#[tokio::main]
async fn main() {
// build our application with a single route
let app = Router::new().route("/hello", get(hello_world));
// run it with hyper on localhost:3000
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
async fn hello_world() -> String {
"Hello world!".to_owned()
}
- Now run
cargo buildto initially compile the project. Note: For some strange reason you might need to run the command multiple times, until it recognizes every library as fully compiled. When the command just outputsFinished...it is done. This is a different bug, but I am pretty sure this is unrelated and probably not for this place here.
Now change a single line in the code, for example “Hello world!” to “Hello!”.
Expected Behavior
This usually should take around one second, even on slow hardware. You test this by installing Rust directly in Windows and repeat the same steps, just without opening this in a Dev Container.
Actual Behavior
It takes more then 10 seconds (on my hardware) to complete. I know this doesn’t seem like much, but this is only a “hello world” project to show the problem. Even though there is some translation / virtualization happening the performance different shouldn’t be as high as it is.
I am missing some fundamental knowledge about WSL and its implementation to get to the bottom of this, but it seems to be related to directories shared with the host. For example when repeating the same steps, but instead of selecting “Dev Containers: Create Dev Container Configuration Files…” in the 2. step, select “Dev Containers: Create Dev Container”. This will create the container using a volume located on the native WSL filesystem, instead of using a mount path to the windows filesystem. I assume there is some kind of translation layer when accessing the windows filesystem from WSL that is the reason for this. But this shouldn’t be that extreme, right?
Just for reference my hardware specs: CPU: Ryzen 5800X (1800 MHz FCLK) RAM: 16GB DDR4 3600 MHz SSD: Samsung 980 Pro 512GB (NVMe) GPU: Nvidia RTX 2060
Diagnostic Logs
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (1 by maintainers)
Except that the primary usecase in my opinion is to have a files in linux and be able to operate on them using Unix commands and tools via terminal but have the IDE in Windows with the GUI. Therefore filesystem access from Windows -> Linux is important.
Yeah for me too, I still don´t understand why the performance penalty is so extreme, but I worked around it, by using native as well (or Linux all together 😃.
I think I will close this for now, if anyone comes across this and feels this should be addressed, drop a comment and I can reopen this.
@craigloewen-msft Okay, so yes, moving the files to the native WSL does work as intended (compile times around 1 second), but it doesn’t really solve the issue.
And yes, sure, I fully expect some performance loss, but there is now way the performance is over 10x when using the windows filesystem instead of the wsl native file system. And it also doesn’t explain the errors on the syslog, or this a normal message for WSL?
The main issue for me with all of this, is that it basically makes Dev Container unusable, as the whole purpose of Dev Container is having all necessary binaries and libraries separated from the development files.
So my main question here, is basically: Is this a bug or is everything working as it is supposed to? Because having a 10x performance hit and a bunch of errors in the syslog, for sure seems like a bug to me. 😄
From above link:
For the fastest performance speed, store your files in the WSL file system if you are working on them with Linux tools in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt) with Windows tools, store your files in the Windows file system. Files can be accessed across the operating systems, but it may significantly slow down performance.And indeed mixing OS tools and filesystems does have a penalty. Using cargo.exe on a WSL filesystem the build speed is slightly shorter, around 9 sec:
However
CARGO_INCREMENTAL=0must be added to the environment otherwise it fails with:error: incremental compilation: could not create session directory lock file: Incorrect function. (os error 1)Microsoft’s has good advice to heed
We recommend against working across operating systems with your files, unless you have a specific reason for doing so.