-
Notifications
You must be signed in to change notification settings - Fork 824
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
fix(virtual-fs): Fix horrible write performance for in-memory files #3905
Conversation
310ae50
to
4def192
Compare
The write() implementation for in-memory files used by the TmpFs / mem_fs was terrible: it used to re-allocate and copy the whole data if the write position was not at the end of the file. This re-writes the implementation to grow the buffer in place if required. Also adds some tests. Closes #3903
4def192
to
047823e
Compare
|
||
self.buffer = new_buffer; | ||
} | ||
if buf.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the file by truncated in that case, depending on the write mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buf
is only the newly written data.
self.buffer.append(&mut remainder)?; | ||
} | ||
if end_cursor > self.buffer.len() { | ||
self.buffer.resize(end_cursor, 0)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't the file (well the vec) be srinked if it's smaller?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why it's inside an if
check.
This only runs when the new data makes the file larger than it previously was.
|
||
file.write(b" mkay?", &mut cursor).unwrap(); | ||
assert_eq!(file.buffer.deref(), b"alter the universe! mkay?"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a test with a seek and truncate could be interesting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely.
We should have a proper test suite for trait FileSystem
implementations.
I only added a tests for write()
because that's the only thing I changed.
Superseded by #4165 |
The write() implementation for in-memory files used by the TmpFs /
mem_fs was terrible: it used to re-allocate and copy the whole data if
the write position was not at the end of the file.
This re-writes the implementation to grow the buffer in place if
required.
Also adds some tests.
Closes #3903