-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function performance seems to be affected by a match arm which is not evaluated. #110764
Comments
is this caused by #110737 |
This is probably because format captures the pointers. You can confirm by passing copies of the variables to format. |
I am not sure how cloning data into error message vs just letting the format capture the pointers shall improve performance of the match arm which is never executed but here are the results which I still find puzzling. Essentially I get three different and progressively worse performance results by changing a match arm of the code that is never executed, how does this make sense? What am I missing about format! pointers? I run same bench mark in each case and only changed the format! of the match arm that never executes. Q: What is the performance with panic! macro on?
Result
Result
Result
|
so I am very new to rust and perhaps missing a trick here but I figured I will raise the question here because I am puzzled by this behavior.
I have a function lets call it serialize which takes a slice of u8 bytes and writes it to the u8 fixed size array allocated on stack. Because the pre-allocated fixed size array can over flow I have to do a check in the function prior to writing if there are enough bytes available on that stack allocated array. In my bench mark I then check performance of this serialize function and I know that in the scenario I had setup there is always sufficient room to write into. However, I have to do a mach to test for this and it seems that some of the code in the match arm which is never executed still gets evaluated.
Here is the actual function, so essentially it seem that the format! block of the first match arm is affecting performance characteristics of the function. If I for example simply add panic! on top of Result::Err I get 2x performance improvement and the bench completes with out panicking. I get similar effect If I simply put a empty string into the format! macro like so format!("") what am I doing wrong?
Is format! macro gets expanded into something outside of the match arm? and always runs regardless of the condition ?
The text was updated successfully, but these errors were encountered: