pyret-lang icon indicating copy to clipboard operation
pyret-lang copied to clipboard

Optimization idea: find `constr(...).method(...)` patterns and inline them away

Open blerner opened this issue 11 years ago • 2 comments

I see this pattern popping up a few times, where we create an object mostly for the benefit of using one of its methods. The object is created inline and passed directly to the method. If the method does not use self (other than to access its fields), then we can avoid the allocation entirely. For example: A.s-global("a-string").key() doesn't need to allocate anything, since key() just returns "global#" + self.name. Obviously, depending on the size of the inlined function, this might not be a net win, but in many common cases, it probably could help...

blerner avatar Jul 15 '14 14:07 blerner

@blerner is this still something that needs exploration?

schanzer avatar Aug 12 '20 18:08 schanzer

Probably still a good idea to eventually explore; any peephole optimizations will help with memory pressure and probably code size.

blerner avatar Aug 12 '20 18:08 blerner