Extract UNSAFE regex in utilities uri to reduce memory usage #1706
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.
While benchmarking my app (using
derailed
), I noticed a an unusual memory usage in theCarrierwave::Utilities::Uri
module. The action benchmarked is serializing 60 records each containing a field with an uploader that has 3 versions. The memory usage is not critical and this is not a huge gain in performance so merge it if you think the code respect the guideline of the repository 😄Here is my benchmarks results:
allocated memory by gem
Before
2399180
carrierwave/lib
1470695
activesupport-4.2.0
1444700
activerecord-4.2.0
After
1708780
carrierwave/lib
1470695
activesupport-4.2.0
1444700
activerecord-4.2.0
allocated memory by file
Before
989475
/Users/simonprev/.rbenv/versions/2.2.2/.../active_support/json/encoding.rb
817070
/Users/simonprev/Code/carrierwave/lib/carrierwave/utilities/uri.rb
<-- This is unusual509070
/Users/simonprev/Code/carrierwave/lib/carrierwave/uploader/url.rb
507460
/Users/simonprev/.rbenv/versions/2.2.2/.../json/common.rb
After
989475
/Users/simonprev/.rbenv/versions/2.2.2/.../active_support/json/encoding.rb
509070
/Users/simonprev/Code/carrierwave/lib/carrierwave/uploader/url.rb
507460
/Users/simonprev/.rbenv/versions/2.2.2/.../json/common.rb
...
126670
/Users/simonprev/Code/carrierwave/lib/carrierwave/utilities/uri.rb
<-- Ahh