Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Inline constant expressions that are only read once #284

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

nielstron
Copy link
Contributor

@nielstron nielstron commented Nov 1, 2023

This enables optimizations that concern making more readable code more efficient. For example the following

def validator(x: int):
  y = x
  z = y * 2
  w = z + 4
  return w

will now be computationally as cheap as the spaghetti-ized version

def validator(x: int):
   return (x*2)+4

The optimization is only applied to variables that are read once (at this moment there is no setting to change this). In the case of reading and writing exactly once, this optimization will alway lead to less CPU/Mem steps and smaller script size. When applying the optimization to values read more than once, it may lead to a tradeoff of less steps but larger size (depending on the size of the expression that needs to be re-computed it might also increase the steps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant