Open
Description
This is a list of ideas for optimizations that could be implemented via AST modification. Some of these ideas are probably bad. This is a living list, in no way finalized, and will likely change in the future.
- in
__init__
, remove any assignments ofself.var = [zero value]
- when a storage variable is referenced more than once without being written to, create a memory variable
- remove memory variables that are initialized but never used
- for an
if
statement where both theif
andelse
blocks end in a return, move the else block logic into the body of the parent block (note: potential scoping concerns) - convert
> 0
to!= 0
for unsigned integer comparisons - if a memory variable is initialized and only referenced once, replace the reference with the right-hand side of the initialization
- if the final node in a function body is a for loop, and the function returns
None
, replace anyreturn
statements inside the function withbreak
- if constant folding results in
if True:
orif False:
remove the block or the else block (consider scoping here) - within the context of a for loop, if there are multiple lookups of
some_long_array[i]
without any assignments, copy the value to a new memory value to save on lookups