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.
https://github.com/hohav/peppi/blob/main/peppi/src/serde/de.rs#L859
The
expect_bytes
function is called many times. Theerr!()
macro expands to aformat!()
call which inflicts a performance penalty. Changing the line toErr(std::io::Error::from(std::io::ErrorKind::InvalidData))
makes the code 4-5% faster for the event handlers use case. Making similar changes to othererr!()
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.