lazily allocate the threaded buffers and allocate them on the thread that will access it #704
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: