rust-csv icon indicating copy to clipboard operation
rust-csv copied to clipboard

Non-allocating trim method

Open do4gr opened this issue 3 years ago • 7 comments

Hey, thanks for the library.

When I was using it I saw that a lot of time was spent in the trim method and stumbled over the comment about making it non-allocating.

I took a stab at it and cargo bench shows a big improvement. Let me know if that is something that you would be interested in , than I can keep working on it a bit more.

Below is the output of the included bench functions for trimming. I think they are showing the best case though since the test file seems to contain no trimmable white-space. Also what is confusing to me is that the StringRecord benchmark also benefits from improvements to the ByteRecord trim method, not sure where this is coming from.

Screen Shot 2021-09-24 at 21 59 36

do4gr avatar Sep 24 '21 20:09 do4gr

I cleaned up the code a bit and added a bench case that actually has to remove whitespace. There the difference is less stark, but still pretty big.

Screen Shot 2021-10-02 at 12 36 10 Screen Shot 2021-10-02 at 12 37 02

do4gr avatar Oct 02 '21 10:10 do4gr

Thank you for this pull request. This yields a significant performance improvement in our project.

@BurntSushi what would be the next steps to consider this PR?

Tristramg avatar Dec 31 '21 09:12 Tristramg

I need to review it. From a quick glance, it looks like there's some clean up required here. For example, there shouldn't be a "trim original" routine in the public API.

CI also obviously needs to be fixed.

BurntSushi avatar Dec 31 '21 13:12 BurntSushi

@do4gr hello, thank you at lot for this. Do you plan to work on this PR again? Otherwise I can try to polish what you did in order to get it merged.

Tristramg avatar Jan 03 '22 14:01 Tristramg

I'll remove the trim_original and then we'll see whether the PR run succeed. I think it was just flakey CI.

do4gr avatar Jan 04 '22 12:01 do4gr

Apart from that from my side the PR would be done. There is nothing more I was thinking of including.

do4gr avatar Jan 04 '22 12:01 do4gr

That's it from my side. Let me know if there is more that needs to be done.

do4gr avatar Jan 05 '22 22:01 do4gr