-
Notifications
You must be signed in to change notification settings - Fork 108
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
Faster dwarfdump #284
Faster dwarfdump #284
Conversation
Rust's padding code is slow; it writes the padded item to a temporary buffer, measures the length of that buffer to determine how much padding is needed, then writes the padding bytes and the buffered value. When we're just using padding to output a specific number of spaces, we can instead build a string of spaces and print slices of it. Before: time ( target/release/examples/dwarfdump -i ~/mozilla-central/obj-ff-opt/dist/bin/libxul.so >& /dev/null ) real 3m36.962s user 3m35.254s sys 0m1.463s After: time ( target/release/examples/dwarfdump -i ~/mozilla-central/obj-ff-opt/dist/bin/libxul.so >& /dev/null ) real 2m21.745s user 2m20.175s sys 0m1.412s
Using slices of spaces instead of regular padding can speed things up even more, though it's a little more invasive; we need to be able to obtain the value of an enum as a static string to avoid dynamically calculating its length. Before: time ( target/release/examples/dwarfdump -i ~/mozilla-central/obj-ff-opt/dist/bin/libxul.so >& /dev/null ) real 2m21.745s user 2m20.175s sys 0m1.412s After: time ( target/release/examples/dwarfdump -i ~/mozilla-central/obj-ff-opt/dist/bin/libxul.so >& /dev/null ) real 1m39.153s user 1m37.714s sys 0m1.320s
It shouldn't be doing this for |
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { | ||
match *self { | ||
impl $struct_name { | ||
pub fn static_string(&self) -> Option<&'static str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also add something that returns Cow<'static, str>
so that the caller can handle the unknown case identically... but then that case doesn't matter much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Some simple changes make dwarfdump more than twice as fast.