Feature #14410
closedReduce allocations and retained objects in the uri common module
Description
Patch at:
https://github.com/ruby/ruby/pull/1801
require 'memory_profiler'
MemoryProfiler.report do
require 'uri'
end.pretty_print
Before:
Total allocated: 986643 bytes (15159 objects)
Total retained: 246370 bytes (2532 objects)
After:
Total allocated: 926903 bytes (13665 objects)
Total retained: 208570 bytes (1587 objects)
Quite a significant change, almost 1000 less RVALUEs around when you require 'uri' which almost every web app does.
To explain [-i.chr]
Files
Updated by sam.saffron (Sam Saffron) over 6 years ago
Updated by normalperson (Eric Wong) over 6 years ago
sam.saffron@gmail.com wrote:
https://bugs.ruby-lang.org/issues/14410
https://github.com/ruby/ruby/pull/1801
diff.txt (1.03 KB)
Careful with "frozen_string_literal: true".
Even with tired eyes I see self.decode_www_form uses literals
which get modified, and maybe other places.
Did you try "make test-all"?
Updated by sam.saffron (Sam Saffron) over 6 years ago
Yes, tests appear to be passing.
I went with the atomic version here cause there is a giant string Hash and it is way cleaner to apply it to the entire file then work through every string in the Hash
Updated by Anonymous over 6 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r62081.
uri/common: reduce allocations and retained objects
Thanks to Sam Saffron for this patch, it shows
a nice reduction which affects many web applications:
require 'memory_profiler'
MemoryProfiler.report do
require 'uri'
end.pretty_print
Before:
Total allocated: 986643 bytes (15159 objects)
Total retained: 246370 bytes (2532 objects)
After:
Total allocated: 926903 bytes (13665 objects)
Total retained: 208570 bytes (1587 objects)
- lib/uri/common.rb: reduce allocations and retained objects
[ruby-core:85161] [Feature #14410]
Updated by normalperson (Eric Wong) over 6 years ago
sam.saffron@gmail.com wrote:
I went with the atomic version here cause there is a giant string Hash and it is way cleaner to apply it to the entire file then work through every string in the Hash
Thanks, I looked over it again and committed as r62081