Get the latest tech news
In-Memory Filesystems in Rust
I’ve been working on a CLI tool recently, and one of the things it does is manage files on disk. I have written a lot of file management tests for Bundler, and the two biggest reasons that the Bundler test suite is slow are exec and fstat. Knowing that, I thought I would try to get out ahead of the slow file stat problem by using an in-memory filesystem for testing.
Conceptually, I was hoping to be able to replace std::fs:: with mycli::fs:: and swap out the backend in tests for something that’s completely in-memory so I don’t have to spend time waiting for syscalls. Next, I looked at rsfs, which is a little bit older, and seems sort of unmaintained, but explicitly says that it aims to reproduce the functionality of std::fs, while adding the ability to run the filesystem in memory if desired. While that high level speedup from using vfs never went away, I was eventually forced to conclude it was a difference in linker cache, or an artifact of cargo test running many executables, or something else entirely.
Or read this on Hacker News