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

AST: Allow children of commutative nodes to be reordered cost-wise. #800

Open
wants to merge 4 commits into
base: feat/ast-boolean-lazy-evaluation
Choose a base branch
from

Conversation

apognu
Copy link

@apognu apognu commented Jan 16, 2025

This adds several things:

  • Commutative functions are marked as such.
  • AST functions now have an associated cost depending on their computational complexity.
  • Evaluation will now reorder the children of a commutative node to execute the cheapest first.

This would have the benefit, thanks to the lazy evaluation of AST nodes (circuit breaking), to improve overall performance for those scenarii.

@apognu apognu self-assigned this Jan 16, 2025
@apognu apognu requested a review from Pascal-Delange January 16, 2025 10:11
@apognu apognu marked this pull request as draft January 16, 2025 10:12
@apognu apognu force-pushed the feat/ast-reorder-weighted-ast-nodes branch from aa29fa4 to 47f3847 Compare January 16, 2025 15:23
Copy link
Contributor

@Pascal-Delange Pascal-Delange left a comment

Choose a reason for hiding this comment

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

looks good !

selfCost = attrs.Cost
}

for _, ch := range node.Children {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also gotta do the same on name children (for keeping generality at least, not sure if the case can be seen currently)

Copy link
Author

Choose a reason for hiding this comment

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

Aren't named children already order-agnostic? They're both stored in a map, which does not have a reproducible order, and I assume are used out-of-order?

Will look into it tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes they are, however for cost computation the named child nodes should also have their cost taken into account

func (environment AstEvaluationEnvironment) WithoutCircuitBreaking() AstEvaluationEnvironment {
environment.disableCircuitBreaking = true

return environment
}

func (environment AstEvaluationEnvironment) WithoutCostOptimizations() AstEvaluationEnvironment {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking my understanding here: this is necessary so we don't have to reorder error results that we return to the frontend, correct?

Copy link
Author

Choose a reason for hiding this comment

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

The Without* methods are mostly for testing (when you're testing one of the two optimizations, so the other one does not bother the test), and for validation of scenario (so optimizations do not change the given scenario).

Copy link
Author

Choose a reason for hiding this comment

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

Now that I think about it, was your comment on the right line?

If it was about the whole re-ordering / de-re-ordering instead, yes, it is done to ensure the tree results are sent in the order the frontend expects it to be, since it relies on that specific structure to match results with their node.

That would not be necessary if every node had a unique ID, but since that is not the case, we need this.

@@ -7,6 +7,13 @@ import (
)

type NodeEvaluation struct {
// Index of the initial node in the AST tree, used to reorder the results as they were.
Copy link
Contributor

Choose a reason for hiding this comment

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

just to clarify the comment: this is the index in the initial array of children, correct ? not a tree-global index of nodes

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, this is the original index at that level of the tree. I will clarify the comment.

@apognu
Copy link
Author

apognu commented Jan 26, 2025

This could benefit, before merging, of adding some new costs for other functions accessing the database.

@apognu apognu marked this pull request as ready for review January 27, 2025 08:01
@apognu apognu requested a review from Pascal-Delange January 27, 2025 08:01
@apognu apognu force-pushed the feat/ast-boolean-lazy-evaluation branch from d0d3c04 to d78abc6 Compare January 27, 2025 11:04
Antoine Popineau added 4 commits January 27, 2025 12:09
This adds several things:

 * Commutative functions are marked as such.
 * AST functions now have an associated cost depending on their computational complexity.
 * Evaluation will now reorder the children of a commutative node to execute the cheapest first.

This would have the benefit, thanks to the lazy evaluation of AST nodes (circuit breaking), to
improve overall performance for those scenarii.
@apognu apognu force-pushed the feat/ast-reorder-weighted-ast-nodes branch from bad8dd4 to 2726621 Compare January 27, 2025 11:10
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.

2 participants