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

Trim dependencies of addr2line for backtrace #160

Merged
merged 1 commit into from
May 10, 2020

Conversation

alexcrichton
Copy link
Contributor

This commit trims the dependencies of addr2line to be used in the
backtrace crate. The purpose here is to slowly trim down the list of
dependencies to make it easier to eventually include this in the
standard library. Fow now this handles three previously required
dependenies of addr2line:

  • smallvec - this is made optional where if not present a standard
    alloc::vec::Vec<T> is used.
  • fallible-iterator - this is simply made optional.
  • lazycell - this is dropped in favor of a small hand-rolled
    implementation.

The new features are enabled by default and the thinking is that the
backtrace crate would disable all these features by default. If the
std feature of backtrace is activated it'd activate these features,
however.

This commit trims the dependencies of `addr2line` to be used in the
`backtrace` crate. The purpose here is to slowly trim down the list of
dependencies to make it easier to eventually include this in the
standard library. Fow now this handles three previously required
dependenies of `addr2line`:

* `smallvec` - this is made optional where if not present a standard
  `alloc::vec::Vec<T>` is used.
* `fallible-iterator` - this is simply made optional.
* `lazycell` - this is dropped in favor of a small hand-rolled
  implementation.

The new features are enabled by default and the thinking is that the
`backtrace` crate would disable all these features by default. If the
`std` feature of `backtrace` is activated it'd activate these features,
however.
// method which will only perform mutation if we aren't already
// `Some`.
let val = closure();
(*ptr).get_or_insert(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(*ptr).get_or_insert(val)
(*self.contents.get()).get_or_insert(val)

If borrow_with is called from inside the closure, then ptr is invalidated according to stacked borrows I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe this is necessary since the value of ptr doesn't change, and borrows into it are temporary. If miri or something throws an error here it can of course be changed.

Copy link
Contributor

@bjorn3 bjorn3 May 7, 2020

Choose a reason for hiding this comment

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

ptr is of course a raw pointer. The following worked fine in miri:

let c = LazyCell::new();
c.borrow_with(|| {
    *c.borrow_with(|| 0)
});

Copy link
Contributor

Choose a reason for hiding this comment

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

@bjorn3 I'm taking your comment to mean that this conversation is resolved.

Comment on lines +16 to +17
let ptr = self.contents.get();
if let Some(val) = &*ptr {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let ptr = self.contents.get();
if let Some(val) = &*ptr {
if let Some(val) = &*self.contents.get() {

Cargo.toml Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
Copy link
Contributor

@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.

Looks good.

I checked that smallvec is still a gain here. Is backtrace-rs ok with giving that up?

 name                                vec ns/iter  smallvec ns/iter  diff ns/iter  diff %  speedup 
 context_query_with_functions_rc     3,333,028    3,035,749             -297,279  -8.92%   x 1.10 
 context_query_with_functions_slice  2,956,228    2,763,440             -192,788  -6.52%   x 1.07 

// method which will only perform mutation if we aren't already
// `Some`.
let val = closure();
(*ptr).get_or_insert(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

@bjorn3 I'm taking your comment to mean that this conversation is resolved.

@philipc philipc merged commit 5f57ded into gimli-rs:master May 10, 2020
@alexcrichton
Copy link
Contributor Author

I think a small perf hit is probably ok, but I'll measure one more time before merging all updates to confirn

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