Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

VIP: Optimize variable passing in private functions #1198

Closed
charles-cooper opened this issue Jan 15, 2019 · 2 comments
Closed

VIP: Optimize variable passing in private functions #1198

charles-cooper opened this issue Jan 15, 2019 · 2 comments
Assignees
Labels
VIP: Approved VIP Approved

Comments

@charles-cooper
Copy link
Member

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

@charles-cooper charles-cooper changed the title Optimize variable passing in private functions VIP: Optimize variable passing in private functions Jan 15, 2019
@jacqueswww jacqueswww added the VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting label Jan 15, 2019
@charles-cooper
Copy link
Member Author

Just realized this morning that since function parameters are always immutable, the copy step can always be skipped.

@fubuloubu fubuloubu removed the for rc label Aug 8, 2019
@fubuloubu fubuloubu added VIP: Approved VIP Approved and removed VIP: Discussion Used to denote VIPs and more complex issues that are waiting discussion in a meeting labels Jan 6, 2020
@charles-cooper
Copy link
Member Author

Superseded by #2447

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
VIP: Approved VIP Approved
Projects
None yet
Development

No branches or pull requests

3 participants