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

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

Merged
merged 2 commits into from
Mar 26, 2023

Conversation

jishnub
Copy link
Contributor

@jishnub jishnub commented Mar 24, 2023

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
Copy link

codecov-commenter commented Mar 24, 2023

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 smishr assigned smishr and unassigned smishr Mar 25, 2023
@smishr smishr added the softeng Software engineering and integration related label Mar 25, 2023
@smishr
Copy link
Contributor

smishr commented Mar 25, 2023

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 smishr changed the base branch from main to v0.1.1 March 25, 2023 11:41
@smishr
Copy link
Contributor

smishr commented Mar 25, 2023

I changed merging branch from main to v0.1.1

@@ -24,27 +24,18 @@ replicates: 1000
function bootweights(design::SurveyDesign; replicates = 4000, rng = MersenneTwister(1234))
Copy link
Member

Choose a reason for hiding this comment

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

Kind of unrelated, but why is the function named bootweights? Could it be refactored to ReplicateDesign(design::SurveyDesign, ...)? This would make the #292 approach a lot easier to implement. If it's an R function you want to wrap, there is always const bootweights = ReplicateDesign or similar.

Copy link
Member

Choose a reason for hiding this comment

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

There are several ways of making replicate weights. This is the first one that we have implemented.

We may choose your approach, we are thinking about the design in #292 and a couple of other issues.

@ayushpatnaikgit ayushpatnaikgit merged commit 13d7b0a into xKDR:v0.1.1 Mar 26, 2023
@jishnub jishnub deleted the bootweights branch March 26, 2023 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
softeng Software engineering and integration related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants