hohav / peppi

Rust parser for Slippi SSBM replay files
MIT License
37 stars 9 forks source link

A single err!() macro call in hot path has 4-5% performance penalty #47

Closed NickCondron closed 1 year ago

NickCondron commented 1 year ago

https://github.com/hohav/peppi/blob/main/peppi/src/serde/de.rs#L859

The expect_bytes function is called many times. The err!() macro expands to a format!() call which inflicts a performance penalty. Changing the line to Err(std::io::Error::from(std::io::ErrorKind::InvalidData)) makes the code 4-5% faster for the event handlers use case. Making similar changes to other err!() calls made very little difference. It is clear to me that this function is called so much more often that only the performance penalty there is noticeable.

Obviously you lose info that is useful for debugging/troubleshooting, so I'm not saying we should change the code uncritically. However, it might be worth the tradeoff, or there may be a better alternative that isn't so expensive.

NickCondron commented 1 year ago

I think I was mistaken here. Reading back what I said doesn't make much sense.