SciML / Optimization.jl

Mathematical Optimization in Julia. Local, global, gradient-based and derivative-free. Linear, Quadratic, Convex, Mixed-Integer, and Nonlinear Optimization in one simple, fast, and differentiable interface.
https://docs.sciml.ai/Optimization/stable/
MIT License
704 stars 77 forks source link

Improve Performance for OptimizationBBO #600

Closed Zentrik closed 10 months ago

Zentrik commented 10 months ago

This fixes a performance regression due to 92974b8526ca031f9c6ed295462b8a9ba45eeacb. The regression is because the defaults for callback and data were changed without changing the code that branched on whether they were set to their defaults.

I removed fieldnames as that seems to not run at compile time (it was taking about 50% of the time for my use case due to having to iterate over it), probably because its effects are (!c,!e,!n,!t,!s,!m,+i)′. I believe you could fix this by using generated functions but I don't know how to. Cthulhu complains that calling getproperty with u0 and p has an Any return type, though I don't see it in the profiler so maybe Cthulhu is wrong here? If this is an issue, I'm not sure how to fix it, perhaps this feature should be removed.

Some tests should be added to prevent this regression in the future, I've added a test to check for how many bytes are allocated.

codecov[bot] commented 10 months ago

Codecov Report

Merging #600 (87f72a9) into master (5a4517d) will increase coverage by 0.14%. The diff coverage is 18.18%.

@@            Coverage Diff            @@
##           master    #600      +/-   ##
=========================================
+ Coverage    8.89%   9.03%   +0.14%     
=========================================
  Files          40      40              
  Lines        2688    2690       +2     
=========================================
+ Hits          239     243       +4     
+ Misses       2449    2447       -2     
Files Coverage Δ
src/cache.jl 37.03% <100.00%> (ø)
src/utils.jl 35.55% <50.00%> (+0.67%) :arrow_up:
lib/OptimizationOptimisers/src/sophia.jl 0.00% <0.00%> (ø)
lib/OptimizationBBO/src/OptimizationBBO.jl 5.40% <0.00%> (ø)

... and 1 file with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more