Use escape analysis to catch unnecessary heapification #393
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
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:
Vec::with_capacity
,vec![]
,into_string()
,Box::new
, etc. Catchingvec![]
will be somewhat hard)&[T]
which are passed a deref coerced Vec are okay)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.
The text was updated successfully, but these errors were encountered: