-
Notifications
You must be signed in to change notification settings - Fork 181
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
Conversation
…that will access it
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
||
function __init__() | ||
Threads.resize_nthreads!(default_cookiejar) | ||
resize!(empty!(default_cookiejar), Threads.nthreads()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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:
After: