nnethercote / dhat-rs

Heap profiling and ad hoc profiling for Rust programs.
Apache License 2.0
713 stars 36 forks source link

Use BufWriter around Json serialization #22

Closed agrover closed 1 year ago

agrover commented 1 year ago

Using strace, one can see that the current code is resulting in a large number of 2-3 byte write() calls. Use BufWriter to increase bytes per write() system call.

nnethercote commented 1 year ago

This is excellent, thank you. One question: the docs say:

It is critical to call flush before BufWriter is dropped. Though dropping will attempt to flush the contents of the buffer, any errors that happen in the process of dropping will be ignored. Calling flush ensures that the buffer is empty and thus dropping will not even attempt file operations.

I'm not sure if I agree about it being "critical", given that the code probably wouldn't do anything different if the flush call fails. But do you think adding a flush is worthwhile anyway?

agrover commented 1 year ago

I'd vote nah -- just do the simple thing. But if you want it I have no objections and can add it.

nnethercote commented 1 year ago

I released v0.3.1 with this change. Thanks again.