JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems
Other
330 stars 66 forks source link

Fix alloc #139

Closed pkofod closed 6 years ago

pkofod commented 6 years ago
Pre-compilation
  2.770035 seconds (1.56 M allocations: 78.844 MiB, 0.99% gc time)
  0.000505 seconds (397 allocations: 213.391 KiB)
  0.007813 seconds (659 allocations: 364.178 KiB)
  0.000740 seconds (406 allocations: 219.844 KiB)
Post-compilation
OnceDifferentiable not pre-allocated
... cache not pre-allocated
  0.001764 seconds (421 allocations: 349.500 KiB)
... cache pre-allocated
  0.001279 seconds (412 allocations: 343.047 KiB)
OnceDifferentiable pre-allocated
... cache not pre-allocated
  0.000656 seconds (406 allocations: 219.844 KiB)
... cache pre-allocated
  0.000595 seconds (397 allocations: 213.391 KiB)
Test case: Already converged (not yet)
  0.007949 seconds (398 allocations: 213.438 KiB)
Test case: Already converged (ok, now it has)
  0.000019 seconds (10 allocations: 1.234 KiB)

cc @ChrisRackauckas

update Newton is allocating a lot. We'll have to look into that.

NewtonTrustRegion
Pre-compilation
  2.734943 seconds (1.56 M allocations: 78.332 MiB, 0.97% gc time)
  0.003495 seconds (398 allocations: 214.188 KiB)
  0.016047 seconds (660 allocations: 364.975 KiB)
  0.000544 seconds (407 allocations: 220.641 KiB)
Post-compilation
OnceDifferentiable not pre-allocated
... cache not pre-allocated
  0.000699 seconds (422 allocations: 350.297 KiB)
... cache pre-allocated
  0.000735 seconds (413 allocations: 343.844 KiB)
OnceDifferentiable pre-allocated
... cache not pre-allocated
  0.000602 seconds (407 allocations: 220.641 KiB)
... cache pre-allocated
  0.000573 seconds (398 allocations: 214.188 KiB)
Test case: Already converged (not yet)
  0.000597 seconds (399 allocations: 214.234 KiB)
Test case: Already converged (ok, now it has)
  0.000013 seconds (10 allocations: 1.234 KiB)
Newton
Pre-compilation
  1.373772 seconds (1.32 M allocations: 83.732 MiB, 2.48% gc time)
  0.131266 seconds (112.02 k allocations: 18.555 MiB, 4.28% gc time)
  0.124618 seconds (112.27 k allocations: 18.702 MiB, 2.36% gc time)
  0.109619 seconds (112.02 k allocations: 18.558 MiB, 1.70% gc time)
Post-compilation
OnceDifferentiable not pre-allocated
... cache not pre-allocated
  0.104028 seconds (112.04 k allocations: 18.685 MiB)
... cache pre-allocated
  0.107153 seconds (112.03 k allocations: 18.681 MiB, 1.71% gc time)
OnceDifferentiable pre-allocated
... cache not pre-allocated
  0.107416 seconds (112.02 k allocations: 18.558 MiB, 1.22% gc time)
... cache pre-allocated
  0.107353 seconds (112.02 k allocations: 18.555 MiB, 1.41% gc time)
Test case: Already converged (not yet)
  0.120350 seconds (112.02 k allocations: 18.555 MiB, 1.12% gc time)
Test case: Already converged (ok, now it has)
  0.000080 seconds (25 allocations: 5.078 KiB)
pkofod commented 6 years ago

Lesson learned here: if you're going to reuse the same objective pre-allocate OnceDifferentiable :) and if you supply the cache variables then you can fail super cheaply if it's already converged (a use-case @ChrisRackauckas et al has)

pkofod commented 6 years ago

Large allocations in Newton came from problems related to the definition of the LineSearch objective.