xKDR / Survey.jl

Analysis of complex surveys
https://xkdr.github.io/Survey.jl/
GNU General Public License v3.0
50 stars 19 forks source link

Speed-up in `bootweights` by using a function barrier #290

Closed jishnub closed 1 year ago

jishnub commented 1 year ago

Separating out the type-unstable and the type-stable parts leads to a moderate speed-up and a slight reduction in allocation. Using the example from the docstring of bootweights on the main branch, we obtain:

julia> using Random, Survey, BenchmarkTools

julia> apiclus1 = load_data("apiclus1");

julia> dclus1 = SurveyDesign(apiclus1; clusters = :dnum, popsize=:fpc);

julia> @btime bootweights($dclus1; replicates=1000, rng=MersenneTwister(111));
  9.535 ms (49257 allocations: 8.93 MiB)

This PR

julia> @btime bootweights($dclus1; replicates=1000, rng=MersenneTwister(111));
  8.235 ms (44213 allocations: 8.89 MiB)

A speedup of 13%

codecov-commenter commented 1 year ago

Codecov Report

Merging #290 (c204a14) into v0.1.1 (f9aa828) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            v0.1.1      #290   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          187       200   +13     
=========================================
+ Hits           187       200   +13     
Impacted Files Coverage Δ
src/bootstrap.jl 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

smishr commented 1 year ago

Hi @jishnub. Thanks for contributing to improve type stability in the package! We have been planning to overhaul the entire package for improving type stability issues.

@ayushpatnaikgit and I will do a few more speed tests on some other datasets, but I think PR should be good to merge soon

smishr commented 1 year ago

I changed merging branch from main to v0.1.1