On Fri, Aug 21, 2020 at 7:16 PM joseph.p...@gmail.com < joseph.p.mcguc...@gmail.com> wrote:
> > > The feature where GO performs escape analysis and promotes stack variables > to the heap: Did that originate with GO or was it first implemented > elsewhere? > > As Ian says, this is a "rather old" trick in the bag of tricks compiler writers use. However, note that it interacts with other features of a language which make it easier or harder to get a good escape analysis approximation to work. It is also important to stress that you first do the escape analysis part and obtain information about what escapes a given scope. With that information in hand, you can then perform various optimizations when the analysis says they are safe to perform. You can then perform scalar replacement as an optimization, promoting field access to a temporary variable, which in turn means you can trigger other optimizations. In many cases you end up moving the fields to CPU registers, so it isn't even on the stack anymore. Functional languages have a long history of utilizing escape analysis. The idea is to figure out if a closure, which is extremely common, needs allocation on the heap or stack, with the stack in preference. One key complication is that the analysis usually needs to work at a higher order, due to the commonality of higher-order-functions (i.e., functions where input arguments are functions and the output of the function also contains functions). -- J. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGrdgiUKPgiPW3k_N0UKZSefFPBkLH_nCOcAwKNmOnFWtpZRcw%40mail.gmail.com.