Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Question: Boxing on stack for function calls #8735
I am aware of similar proposal #1784. But what i am asking is a bit different. I am wondering if it's a good idea to allocate boxed value on stack in case boxing is done for a function argument. And move that box to heap later only if that box gets referenced from an object from heap. I think it would be a significant optimization for function calls with object-type arguments and the ones with variable number of arguments. I believe implementation should be straight forward without "thinking" on compiler's side, which is boxed values are pushed out of stack upon function return, and moved to heap when referenced by an object from heap.
That "move to heap when referenced by an object from heap" involves compiler thinking. And this type of thinking is actually more complicated than traditional escape analysis as "move to heap" needs to happen at most once for a given object.