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

perf: optimize IF THEN ELSE for cases where condition expression resolves to a constant #103

Merged
merged 6 commits into from
Aug 17, 2021

Conversation

chrispcampbell
Copy link
Contributor

Fixes #102

See issue for more details. I updated the existing prune test (which is used to verify the unused reference elimination code) with new cases to cover the IF THEN ELSE optimizations.

At some point I'd like to reimplement the equation reader phase to produce objects that are AST-like, and then have the code gen phase use those objects instead of revisiting the whole model structure. That way optimizations like this and the dead code elimination (and others we could do, like constant folding) could be expressed as AST transforms. But that's for another day (probably way down the road). For now, I think this gets the job done, and wasn't too terribly invasive.

Copy link
Collaborator

@ToddFincannon ToddFincannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a surprisingly effective optimization. Because ExprReader is specifically oriented to analyzing constants, I might have named it something less general. But it also makes sense to keep expanding its capability as necessary under the more general name.

@chrispcampbell
Copy link
Contributor Author

That's a surprisingly effective optimization. Because ExprReader is specifically oriented to analyzing constants, I might have named it something less general. But it also makes sense to keep expanding its capability as necessary under the more general name.

That was my thinking as well, so I left it with the more general name. Easy to change later if we find a need for different kinds of expression readers.

@chrispcampbell chrispcampbell merged commit f9ef675 into develop Aug 17, 2021
@chrispcampbell chrispcampbell deleted the chris/102-optimize-if-then-else branch August 17, 2021 18:21
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.

Optimize IF THEN ELSE for cases where condition expression resolves to a constant
2 participants