Skip to content
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

Merged
merged 2 commits into from
Mar 4, 2018
Merged

Faster dwarfdump #284

merged 2 commits into from
Mar 4, 2018

Conversation

rocallahan
Copy link
Contributor

Some simple changes make dwarfdump more than twice as fast.

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
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 92.517% when pulling f138c5b on rocallahan:faster-dump into ac0ec00 on gimli-rs:master.

@philipc
Copy link
Collaborator

philipc commented Mar 4, 2018

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.

It shouldn't be doing this for &str arguments though? If it is, then that sounds like something that can be fixed in libstd? Padding using a single slice is still going to be faster than looping over padding characters though.

fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
impl $struct_name {
pub fn static_string(&self) -> Option<&'static str> {
Copy link
Collaborator

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.

Copy link
Collaborator

@philipc philipc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@philipc philipc merged commit 71a1138 into gimli-rs:master Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants