Symbolics.jl: Speed of derivative computations vs. SymEngine.jl

I benchmarked some derivative computations using Symbolics.jl, SymEngine.jl, and SymPy.jl. As expected, SymPy.jl was the slowest solution in my case. However, SymEngine.jl was significantly faster than Symbolics.jl. Here is an example:

julia> using Pkg; Pkg.activate(temp=true); Pkg.add(["SymEngine", "Symbolics", "BenchmarkTools"])

julia> using SymEngine, Symbolics, BenchmarkTools

julia> f(u) = u[2] / (u[1]^2 + u[2]^2)
f (generic function with 1 method)

julia> u_symbolics = @variables u1 u2

julia> expand_derivatives(( Differential(u_symbolics[1])(f(u_symbolics)) ))
-2u1*(u2 / ((u1^2 + u2^2)^2))

julia> @benchmark expand_derivatives($( Differential(u_symbolics[1])(f(u_symbolics)) ))
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
 Range (min … max):  19.477 ΞΌs …  4.431 ms  β”Š GC (min … max): 0.00% … 99.14%
 Time  (median):     21.305 ΞΌs              β”Š GC (median):    0.00%
 Time  (mean Β± Οƒ):   22.915 ΞΌs Β± 61.455 ΞΌs  β”Š GC (mean Β± Οƒ):  3.78% Β±  1.40%

     β–ƒβ–ˆβ–‡β–„                                                      
  β–‚β–ƒβ–…β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–†β–†β–…β–…β–„β–„β–ƒβ–ƒβ–ƒβ–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–β–‚β–β–‚β–‚β–β–β–β–β–‚β–β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚β–‚ β–ƒ
  19.5 ΞΌs         Histogram: frequency by time        37.5 ΞΌs <

 Memory estimate: 10.97 KiB, allocs estimate: 233.

julia> u_symengine = @vars u1 u2
(u1, u2)

julia> diff((f(u_symengine)), (u_symengine[1]))
-2*u2*u1/(u1^2 + u2^2)^2

julia> @benchmark diff($(f(u_symengine)), $(u_symengine[1]))
BenchmarkTools.Trial: 10000 samples with 7 evaluations.
 Range (min … max):  4.198 ΞΌs …  35.084 ΞΌs  β”Š GC (min … max): 0.00% … 0.00%
 Time  (median):     4.268 ΞΌs               β”Š GC (median):    0.00%
 Time  (mean Β± Οƒ):   4.320 ΞΌs Β± 510.445 ns  β”Š GC (mean Β± Οƒ):  0.00% Β± 0.00%

  β–„β–ˆβ–‡β–†β–…β–‚β–β–β–β–                                                  β–‚
  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–†β–†β–…β–ƒβ–…β–ƒβ–ƒβ–β–β–β–β–β–β–β–β–β–ƒβ–β–β–β–β–β–β–ƒβ–β–β–β–ƒβ–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–β–†β–… β–ˆ
  4.2 ΞΌs       Histogram: log(frequency) by time       6.1 ΞΌs <

 Memory estimate: 336 bytes, allocs estimate: 20.
  1. Am I doing something wrong with Symbolics.jl?
  2. Is there a way for me to get better performance of such derivative calculations using Symbolics.jl?

Open an issue. Worth profiling.

Done