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

Performance issue with the redundancy operations

Open yyzdtccjdtc opened this issue 3 years ago • 1 comments

https://github.com/BurntSushi/rust-csv/blob/41c71ed353a71526c52633d854466c1619dacae4/csv-core/src/reader.rs#L669

For this line of code, it will always update the value of self.line, even if the value of it does not change. This introduces some redundant operations.

If we change the code to this, we can eliminate these redundant operations.

if input[nin] == b'\n'{
     self.line += 1;
}

According to my tests with the ema example with this application (https://github.com/greyblake/ta-rs), the average execution time decreased from 2.74s to 2.68s, which is a 1.02x speedup.

Hope this information helps!

yyzdtccjdtc avatar Jun 01 '22 15:06 yyzdtccjdtc

Interesting. Seems like the compiler should be smarter than that here. But happy to make this change. PRs are welcome.

BurntSushi avatar Jun 01 '22 16:06 BurntSushi