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 of self.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 the if and else 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 any return statements inside the function with break
- if constant folding results in
if True: or if 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
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.
__init__, remove any assignments ofself.var = [zero value]ifstatement where both theifandelseblocks end in a return, move the else block logic into the body of the parent block (note: potential scoping concerns)> 0to!= 0for unsigned integer comparisonsNone, replace anyreturnstatements inside the function withbreakif True:orif False:remove the block or the else block (consider scoping here)some_long_array[i]without any assignments, copy the value to a new memory value to save on lookups