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

fixed bug in is_variable. Was recursing through the graph for each call. Asymptotically slower than it should have been. #101

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

brianguenter
Copy link
Owner

@brianguenter brianguenter commented Oct 31, 2024

A long time ago changed is_variable to allow for q(t) types, even though support for these was never completed. This inadvertently caused the code to become asymptotically slower, because it recursed through the graph for every is_variable call:

tmp = (value(a) isa Symbol)
   tmp2 = (arity(a) == 0) || all(is_variable.(children(a))) #this allows q(t) types

For graphs with 1e4 nodes was roughly 100x slower, for graphs with 1e6 nodes it was maybe 2000x slower. Don't know because it took too long to run.

is_variable is called by is_constant, and these two functions are called in various places in simplify_check_cache functions.

Changed simplification rules for unary -. Previously the conditionals in the if statements were creating Node instances, which caused allocations even if the condition proved false. Changed to remove all Node creation in conditions. Over 2x speed improvement.

…ll. Made code asymptotically slower than it should have been. Now much faster for large graphs.

changed simplification rules for unary -. Previously the conditionals in the if statements were creating node, which caused allocations even if the condition proved false. Changed to removed all Node create in conditions. over 2x speed improvement.
@brianguenter brianguenter merged commit f65fd7c into main Oct 31, 2024
3 checks passed
@brianguenter brianguenter deleted the performance_fix branch October 31, 2024 22:01
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