Skip to content

Use escape analysis to catch unnecessary heapification #393

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

Open
Manishearth opened this issue Oct 15, 2015 · 5 comments
Open

Use escape analysis to catch unnecessary heapification #393

Manishearth opened this issue Oct 15, 2015 · 5 comments
Assignees
Labels
A-lint Area: New lints C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. E-hard Call for participation: This a hard problem and requires more experience or effort to work on T-middle Type: Probably requires verifiying types

Comments

@Manishearth
Copy link
Member

Many languages with a pervasive GCs use "escape analysis" to avoid boxing things. So if an object can't escape a given scope, plop it on the stack instead of giving it to the GC heap. This reduces GC load.

While we're not a GCd language, the same principle can apply to the regular heap (with less optimization wins because we already got that optimization win by not having a GC in the first place)

The idea is to find places where optimizations like this are possible.

Basically, if:

  • A vec/string/box/heap thing is constructed locally (Via Vec::with_capacity, vec![], into_string(), Box::new, etc. Catching vec![] will be somewhat hard)
  • It's not modified (we can perhaps allow in-place modification)
  • It's not passed to a function expecting that heap thing (method expecting things like &[T] which are passed a deref coerced Vec are okay)
  • There is no way for the heap thing to "escape" its scope, i.e. by being returned or otherwise moved out.

Then we should suggest using the unboxed version.

This would be a fun lint to work on, but it's not easy. I might work on this myself but I don't have any time right now. Willing to mentor anyone who does want to.

@Manishearth Manishearth added E-hard Call for participation: This a hard problem and requires more experience or effort to work on T-middle Type: Probably requires verifiying types A-lint Area: New lints C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. labels Oct 15, 2015
@Manishearth Manishearth self-assigned this Dec 5, 2015
@Manishearth
Copy link
Member Author

#477 does part of this

@llogiq
Copy link
Contributor

llogiq commented Dec 5, 2015

I'd love to take a shot at this (because it has some overlap to the other big lint project I keep delaying because other stuff gets in the way), but I'm not sure if I find enough uninterrupted time, so I'm entirely OK with someone else taking it.

@Manishearth
Copy link
Member Author

Its already mostly done, though.

Well, there are many edge cases left which might be hard to handle.

@Manishearth
Copy link
Member Author

(Still, feel free to work on it! Let me know beforehand what you're working on so I don't redo the same thing)

@sanxiyn
Copy link
Member

sanxiyn commented Dec 10, 2015

Historical note: rustc had this, see rust-lang/rust#6647. unused_allocation is the remnant. This was when we had ~"" and ~[]. Somehow lint didn't get updated when we got String and Vec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints C-an-interesting-project Category: Interesting projects, that usually are more involved design/code wise. E-hard Call for participation: This a hard problem and requires more experience or effort to work on T-middle Type: Probably requires verifiying types
Projects
None yet
Development

No branches or pull requests

3 participants