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

fast path for dists in the PointMass constraint #145

Merged
merged 2 commits into from
Aug 28, 2023

Conversation

bvdmitri
Copy link
Member

Previously the PointMass form constraint called slow optimization routine for <: Distribution objects, even though it is easier and faster to return the mode of the distribution. This PR fixes that. Found by @bartvanerp

@bvdmitri bvdmitri added the Performance Improve code speed label Aug 25, 2023
@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.09% 🎉

Comparison is base (6ad864e) 81.22% compared to head (287aa85) 81.32%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
+ Coverage   81.22%   81.32%   +0.09%     
==========================================
  Files          11       11              
  Lines        1209     1210       +1     
==========================================
+ Hits          982      984       +2     
+ Misses        227      226       -1     
Files Changed Coverage Δ
src/constraints/form/form_point_mass.jl 78.37% <100.00%> (+3.37%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bartvanerp
Copy link
Member

Before:

BenchmarkTools.Trial: 6 samples with 1 evaluation.
 Range (min  max):  929.941 ms    1.077 s  ┊ GC (min  max):  9.92%  11.26%
 Time  (median):     957.682 ms              ┊ GC (median):    11.08%
 Time  (mean ± σ):   987.136 ms ± 64.681 ms  ┊ GC (mean ± σ):  11.12% ±  0.82%

  █  █      █ █                                        █     █  
  █▁▁█▁▁▁▁▁▁█▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁█ ▁
  930 ms          Histogram: frequency by time          1.08 s <

 Memory estimate: 528.79 MiB, allocs estimate: 4246814.

After

BenchmarkTools.Trial: 7 samples with 1 evaluation.
 Range (min  max):  668.098 ms  845.756 ms  ┊ GC (min  max):  9.63%  12.63%
 Time  (median):     725.226 ms               ┊ GC (median):    11.92%
 Time  (mean ± σ):   739.858 ms ±  55.859 ms  ┊ GC (mean ± σ):  11.65% ±  1.28%

  █             █   ██  █            █                        █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁██▁▁█▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  668 ms           Histogram: frequency by time          846 ms <

 Memory estimate: 485.53 MiB, allocs estimate: 3522721.

Copy link
Member

@bartvanerp bartvanerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great oneliner! :)

@bvdmitri bvdmitri merged commit 47618a7 into main Aug 28, 2023
14 checks passed
@bvdmitri bvdmitri deleted the dev-pointmass-dist-fix branch August 28, 2023 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Improve code speed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants