1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
require_relative "helper"
benchmark_allocations do
1000.times do |i|
RSpec.describe "group #{i}" do
it "has one example" do
end
end
end
end
__END__
Original allocations:
class_plus count
---------------------------------------- -----
String 28000
Array 15000
RubyVM::Env 9000
Proc 9000
Hash 9000
RSpec::Core::Hooks::HookCollection 6000
Array<String> 5000
MatchData 3000
Array<String,Fixnum> 2000
Array<Module> 2000
Module 2000
RSpec::Core::Example::ExecutionResult 2000
RSpec::Core::Metadata::ExampleGroupHash 1000
Class 1000
Array<Hash> 1000
RSpec::Core::Hooks::AroundHookCollection 1000
RSpec::Core::Hooks::HookCollections 1000
RSpec::Core::Metadata::ExampleHash 1000
RSpec::Core::Example 1000
Array<RSpec::Core::Example> 1000
After removing `:suite` support from `Hooks` module,
it cut Array and RSpec::Core::Hooks::HookCollection
allocations by 2000 each:
class_plus count
---------------------------------------- -----
String 28000
Array 13000
Proc 9000
RubyVM::Env 9000
Hash 9000
Array<String> 5000
RSpec::Core::Hooks::HookCollection 4000
MatchData 3000
Array<Module> 2000
RSpec::Core::Example::ExecutionResult 2000
Module 2000
Array<String,Fixnum> 2000
RSpec::Core::Hooks::HookCollections 1000
RSpec::Core::Example 1000
Array<RSpec::Core::Example> 1000
RSpec::Core::Metadata::ExampleHash 1000
RSpec::Core::Hooks::AroundHookCollection 1000
RSpec::Core::Metadata::ExampleGroupHash 1000
Class 1000
Array<Hash> 1000
....
Later, our allocations were:
class_plus count
--------------------------------------- -----
String 26000
Hash 19000
Array 18000
Set 10000
Proc 9000
RubyVM::Env 9000
RSpec::Core::Hooks::HookCollection 5000
RSpec::Core::FilterableItemRepository 5000
Array<String> 5000
MatchData 3000
RSpec::Core::Example::ExecutionResult 2000
Array<String,Fixnum> 2000
Module 2000
Array<Module> 2000
RSpec::Core::Metadata::ExampleGroupHash 1000
Class 1000
RSpec::Core::Metadata::ExampleHash 1000
RSpec::Core::Example 1000
Array<RSpec::Core::Example> 1000
Array<Hash> 1000
RSpec::Core::Hooks::HookCollections 1000
After changing the hooks implementation to lazily
instantiate `HookCollection` instances, it dropped
our allocations by:
- 8K hashes
- 10K arrays
- 10K sets
- 5K FilterableItemRepository
- 5K HookCollecion
class_plus count
--------------------------------------- -----
String 26000
Hash 11000
Array 8000
Proc 5000
RubyVM::Env 5000
Array<String> 5000
MatchData 3000
Array<Module> 2000
Array<String,Fixnum> 2000
RSpec::Core::Example::ExecutionResult 2000
Module 2000
Array<Hash> 1000
RSpec::Core::Metadata::ExampleGroupHash 1000
Class 1000
RSpec::Core::Metadata::ExampleHash 1000
RSpec::Core::Example 1000
Array<RSpec::Core::Example> 1000
RSpec::Core::Hooks::HookCollections 1000
|