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

perf: better api for std::fs::write #41

Closed
Boshen opened this issue Jan 16, 2023 · 3 comments
Closed

perf: better api for std::fs::write #41

Boshen opened this issue Jan 16, 2023 · 3 comments

Comments

@Boshen
Copy link
Contributor

Boshen commented Jan 16, 2023

The current api is not memory friendly for std::fs::write:

    std::fs::write(file_path, asset.get_source().buffer()).map_err(rspack_error::Error::from)?;

The buffer currently concats all the source code into a single String and then write to disk, this creates a huge memory pressure because we have to constantly reallocate for this String,
It would be better to expose a better api to work with BufWriter, where we can balance memory + fs::write syscall.

@Boshen
Copy link
Contributor Author

Boshen commented Jan 16, 2023

Evidence:
image

@Boshen
Copy link
Contributor Author

Boshen commented Jan 17, 2023

pub fn to_writer<W: Write>(&self, w: W) -> Result<()> should be good.

@Boshen
Copy link
Contributor Author

Boshen commented Jan 17, 2023

After the change in #42

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant