Skip to content

Ideas for AST-level optimizations #1972

Open
@iamdefinitelyahuman

Description

@iamdefinitelyahuman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OptimizationIssues related to compiler optimization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions