You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass variables by reference if possible by using a copy-on-write strategy. This was touched on in the last call, so I'm putting it up for more discussion. Since it's a little tricky to implement, lower-hanging optimizations should probably be implemented first.
Motivation
Passing large arrays or structs to private functions can lead to bytecode bloat and extra gas usage. This is even more likely in user code now that structs are more convenient to pass around. Solidity allows one to pass variables by reference which is more optimized, but since references are hard to reason about, this seems to be out of line with Vyper's philosophy of making code maximally human-readable. This proposal strikes a middle ground by allowing pass-by-reference as a compiler-internal optimization without exposing it to the user.
Specification
When non-word types are passed as arguments to private functions, pass a reference instead of a value. If and when a reference argument is written to, write it to the local function frame and change the reference to point to its location in the local frame. Dynamic packing/unpacking code can also be skipped since this only applies to private functions.
Backwards Compatibility
No user-facing changes. Will probably increase compiler complexity.
Simple Summary
Optimize variable passing in private functions.
Abstract
Pass variables by reference if possible by using a copy-on-write strategy. This was touched on in the last call, so I'm putting it up for more discussion. Since it's a little tricky to implement, lower-hanging optimizations should probably be implemented first.
Motivation
Passing large arrays or structs to private functions can lead to bytecode bloat and extra gas usage. This is even more likely in user code now that structs are more convenient to pass around. Solidity allows one to pass variables by reference which is more optimized, but since references are hard to reason about, this seems to be out of line with Vyper's philosophy of making code maximally human-readable. This proposal strikes a middle ground by allowing pass-by-reference as a compiler-internal optimization without exposing it to the user.
Specification
When non-word types are passed as arguments to private functions, pass a reference instead of a value. If and when a reference argument is written to, write it to the local function frame and change the reference to point to its location in the local frame. Dynamic packing/unpacking code can also be skipped since this only applies to private functions.
Backwards Compatibility
No user-facing changes. Will probably increase compiler complexity.
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: