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

lazily allocate the threaded buffers and allocate them on the thread that will access it #704

Merged
merged 1 commit into from
May 1, 2021

Conversation

KristofferC
Copy link
Contributor

@KristofferC KristofferC commented Apr 28, 2021

This package does quite a bit of work on load time since it allocates and compiles some regular expressions. That code needs to be inferred and run which causes some penalty to the load time of the package. In particular, the function Threads.resize_nthreads! seems to be slow to infer (JuliaLang/julia#40630). In addition, it is generally better to allocate objects on the actual thread that they will be used. The pattern used in this PR is the same as the Random stdlib uses to allocate thread local RNGs: https://github.com/JuliaLang/julia/blob/e4fcdf5b04fd9751ce48b0afc700330475b42443/stdlib/Random/src/RNGs.jl#L369-L385.

Together with JuliaWeb/URIs.jl#27 the timings for loading the package are:

Before:

julia> @time using HTTP
  0.428206 seconds (1.05 M allocations: 63.117 MiB, 2.00% gc time, 0.89% compilation time)

After:

julia> @time using HTTP
  0.113877 seconds (64.19 k allocations: 5.825 MiB, 7.65% compilation time)

@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2021

Codecov Report

Merging #704 (8b4a9e5) into master (255a759) will increase coverage by 0.11%.
The diff coverage is 97.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
+ Coverage   75.24%   75.36%   +0.11%     
==========================================
  Files          36       36              
  Lines        2347     2358      +11     
==========================================
+ Hits         1766     1777      +11     
  Misses        581      581              
Impacted Files Coverage Δ
src/HTTP.jl 97.82% <88.88%> (-2.18%) ⬇️
src/CookieRequest.jl 87.09% <100.00%> (ø)
src/Parsers.jl 97.91% <100.00%> (+0.02%) ⬆️
src/Servers.jl 80.89% <100.00%> (+0.12%) ⬆️
src/parseutils.jl 73.33% <0.00%> (+6.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 255a759...8b4a9e5. Read the comment docs.

@fredrikekre fredrikekre requested a review from quinnj April 30, 2021 12:28

function __init__()
Threads.resize_nthreads!(default_cookiejar)
resize!(empty!(default_cookiejar), Threads.nthreads())
Copy link
Member

Choose a reason for hiding this comment

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

curious why the empty! call here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just in case some garbage is left in it from the precompilation process that ends up getting serialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants