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

Improve implementation of MappedWrite #779

Open
edmorley opened this issue Feb 14, 2024 · 0 comments
Open

Improve implementation of MappedWrite #779

edmorley opened this issue Feb 14, 2024 · 0 comments
Labels
enhancement New feature or request libherokubuildpack

Comments

@edmorley
Copy link
Member

MappedWrite currently manually appends a single element at a time to its buffer in its io::Write implementation (rather than a split and push several at once approach, or similar):

fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
for byte in buf {
self.buffer.push(*byte);
if *byte == self.marker_byte {
self.map_and_write_current_buffer()?;
}
}

This seems suboptimal from a performance point of view (given MappedWrite's primary use-case is to process the stdout of a process, which could be large in volume).

I happened to spot that the Rust stdlib actually has std::io::LineWriter which does something similar to what MappedWrite does.

Whilst we can't use LineWriter for our use-case (since it doesn't support a way to map the lines), it's possible we could take inspiration from its implementation:
https://github.com/rust-lang/rust/blob/master/library/std/src/io/buffered/linewriter.rs
https://github.com/rust-lang/rust/blob/master/library/std/src/io/buffered/linewritershim.rs

@edmorley edmorley added enhancement New feature or request libherokubuildpack labels Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request libherokubuildpack
Projects
None yet
Development

No branches or pull requests

1 participant