JuliaSymbolics / SymbolicUtils.jl

Symbolic expressions, rewriting and simplification
https://docs.sciml.ai/SymbolicUtils/stable/
Other
524 stars 99 forks source link

Enhancement: avoid applying canonicalizing rules on canonical form #524

Closed shashi closed 1 year ago

shashi commented 1 year ago

fixes #347

Before

julia> @btime simplify(z*x)
  41.083 μs (511 allocations: 27.11 KiB)
x*z

julia> @btime simplify(z*x+z*y)
  252.292 μs (3063 allocations: 159.59 KiB)
z*(x + y)

After

julia> @btime simplify(z*x)
  27.458 μs (294 allocations: 16.25 KiB)
x*z

julia> @btime simplify(z*x+z*y)
  151.834 μs (1724 allocations: 92.55 KiB)
z*(x + y)
github-actions[bot] commented 1 year ago

Benchmark Results

master 7169244e587d15... t[master]/t[7169244e587d15...]
overhead/acrule/a+2 1.31 ± 0.3 μs 1.24 ± 0.27 μs 1.06
overhead/acrule/a+2+b 1.27 ± 0.31 μs 1.22 ± 0.29 μs 1.04
overhead/acrule/a+b 0.505 ± 0.057 μs 0.486 ± 0.055 μs 1.04
overhead/acrule/noop:Int 29.8 ± 1 ns 30.1 ± 2.1 ns 0.99
overhead/acrule/noop:Sym 0.0533 ± 0.0061 μs 0.0542 ± 0.0093 μs 0.983
overhead/rule/noop:Int 0.0454 ± 0.0063 μs 0.0463 ± 0.0048 μs 0.979
overhead/rule/noop:Sym 0.0756 ± 0.011 μs 0.0782 ± 0.011 μs 0.966
overhead/rule/noop:Term 0.0732 ± 0.0099 μs 0.0792 ± 0.011 μs 0.924
overhead/ruleset/noop:Int 0.188 ± 0.017 μs 0.18 ± 0.019 μs 1.04
overhead/ruleset/noop:Sym 0.248 ± 0.031 μs 0.23 ± 0.022 μs 1.08
overhead/ruleset/noop:Term 6.52 ± 0.83 μs 6.4 ± 0.63 μs 1.02
overhead/simplify/noop:Int 0.247 ± 0.031 μs 0.243 ± 0.025 μs 1.01
overhead/simplify/noop:Sym 0.278 ± 0.03 μs 0.281 ± 0.033 μs 0.989
overhead/simplify/noop:Term 0.15 ± 0.015 ms 0.0929 ± 0.011 ms 1.61
overhead/simplify/randterm (+, *):serial 0.346 ± 0.013 s 0.204 ± 0.0061 s 1.7
overhead/simplify/randterm (+, *):thread 0.216 ± 0.015 s 0.136 ± 0.016 s 1.59
overhead/simplify/randterm (/, *):serial 0.798 ± 0.062 ms 0.497 ± 0.043 ms 1.61
overhead/simplify/randterm (/, *):thread 0.881 ± 0.069 ms 0.617 ± 0.055 ms 1.43
overhead/substitute/a 0.148 ± 0.015 ms 0.147 ± 0.017 ms 1.01
overhead/substitute/a,b 0.143 ± 0.013 ms 0.136 ± 0.015 ms 1.05
overhead/substitute/a,b,c 0.0566 ± 0.0052 ms 0.0539 ± 0.0063 ms 1.05
polyform/easy_iszero 0.0822 ± 0.013 ms 0.0802 ± 0.01 ms 1.02
polyform/isone 3.6 ± 0.1 ns 3.3 ± 0.2 ns 1.09
polyform/iszero 2.8 ± 0.27 ms 2.67 ± 0.25 ms 1.05
polyform/simplify_fractions 4.1 ± 0.37 ms 3.86 ± 0.32 ms 1.06
time_to_load 5.98 ± 0.11 s 6.07 ± 0.021 s 0.984

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).