From 9c7d97af0af8acf643d5cc7bb34e40d6d999fb91 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 05:11:15 +0300 Subject: [PATCH 01/25] Add case study --- case-study.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 case-study.md diff --git a/case-study.md b/case-study.md new file mode 100644 index 00000000..d41034d9 --- /dev/null +++ b/case-study.md @@ -0,0 +1,56 @@ +# Case-study оптимизации + +## Актуальная проблема +В нашем проекте возникла серьёзная проблема. + +Необходимо было обработать файл с данными, чуть больше ста мегабайт. + +У нас уже была программа на `ruby`, которая умела делать нужную обработку. + +Она успешно работала на файлах размером пару мегабайт, но для большого файла она работала слишком долго, и не было понятно, закончит ли она вообще работу за какое-то разумное время. + +Я решил исправить эту проблему, оптимизировав эту программу. + +## Формирование метрики +Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: *тут ваша метрика* + +## Гарантия корректности работы оптимизированной программы +Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. + +## Feedback-Loop +Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за *время, которое у вас получилось* + +Вот как я построил `feedback_loop`: *как вы построили feedback_loop* + +## Вникаем в детали системы, чтобы найти главные точки роста +Для того, чтобы найти "точки роста" для оптимизации я воспользовался *инструментами, которыми вы воспользовались* + +Вот какие проблемы удалось найти и решить + +### Ваша находка №1 +- какой отчёт показал главную точку роста +- как вы решили её оптимизировать +- как изменилась метрика +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +### Ваша находка №2 +- какой отчёт показал главную точку роста +- как вы решили её оптимизировать +- как изменилась метрика +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +### Ваша находка №X +- какой отчёт показал главную точку роста +- как вы решили её оптимизировать +- как изменилась метрика +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +## Результаты +В результате проделанной оптимизации наконец удалось обработать файл с данными. +Удалось улучшить метрику системы с *того, что у вас было в начале, до того, что получилось в конце* и уложиться в заданный бюджет. + +*Какими ещё результами можете поделиться* + +## Защита от регрессии производительности +Для защиты от потери достигнутого прогресса при дальнейших изменениях программы *о performance-тестах, которые вы написали* + From bad4afee9f35094e618b88f55bf43119ad6e8415 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 05:12:29 +0300 Subject: [PATCH 02/25] Init rspec --- .rspec | 1 + spec/spec_helper.rb | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .rspec create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 00000000..c99d2e73 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..c80d44b9 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,98 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 776b4434c9ad34044ee411265e44b54f9b6fd7cb Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 05:19:28 +0300 Subject: [PATCH 03/25] Add correctness test --- .rspec | 1 + result.json | 1 + spec/correctness_spec.rb | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 result.json create mode 100644 spec/correctness_spec.rb diff --git a/.rspec b/.rspec index c99d2e73..5be63fcb 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ --require spec_helper +--format documentation diff --git a/result.json b/result.json new file mode 100644 index 00000000..ad485631 --- /dev/null +++ b/result.json @@ -0,0 +1 @@ +{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}} diff --git a/spec/correctness_spec.rb b/spec/correctness_spec.rb new file mode 100644 index 00000000..91b0d237 --- /dev/null +++ b/spec/correctness_spec.rb @@ -0,0 +1,41 @@ +require_relative '../task-1' + +RSpec.describe 'Work' do + subject { work } + + let(:expected_result) do + '{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}}' + "\n" + end + let(:data) do + <<~HEREDOC + user,0,Leida,Cira,0 + session,0,0,Safari 29,87,2016-10-23 + session,0,1,Firefox 12,118,2017-02-27 + session,0,2,Internet Explorer 28,31,2017-03-28 + session,0,3,Internet Explorer 28,109,2016-09-15 + session,0,4,Safari 39,104,2017-09-27 + session,0,5,Internet Explorer 35,6,2016-09-01 + user,1,Palmer,Katrina,65 + session,1,0,Safari 17,12,2016-10-21 + session,1,1,Firefox 32,3,2016-12-20 + session,1,2,Chrome 6,59,2016-11-11 + session,1,3,Internet Explorer 10,28,2017-04-29 + session,1,4,Chrome 13,116,2016-12-28 + user,2,Gregory,Santos,86 + session,2,0,Chrome 35,6,2018-09-21 + session,2,1,Safari 49,85,2017-05-22 + session,2,2,Firefox 47,17,2018-02-02 + session,2,3,Chrome 20,84,2016-11-25 + HEREDOC + end + + before do + File.write('result.json', '') + File.write('data.txt', data) + end + + it 'generates correct result json' do + subject + expect(File.read('result.json')).to eq(expected_result) + end +end From a101beda258cc7245acfab150033468fa2081ba0 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 05:39:55 +0300 Subject: [PATCH 04/25] Add complexity test --- .gitignore | 2 ++ spec/spec_helper.rb | 7 +++++++ spec/support/fixtures.rb | 13 +++++++++++++ spec/{ => work}/correctness_spec.rb | 2 +- spec/work/performance_spec.rb | 26 ++++++++++++++++++++++++++ task-1.rb | 4 ++-- 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 spec/support/fixtures.rb rename spec/{ => work}/correctness_spec.rb (98%) create mode 100644 spec/work/performance_spec.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..63f55fe8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +data_large.txt +spec/fixtures/ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c80d44b9..87740aae 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,8 +12,15 @@ # the additional setup, and require it from the spec files that actually need # it. # +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration + +require 'rspec-benchmark' +Dir[File.expand_path('spec/support/**/*.rb')].each { |f| require_relative(f) } + # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + config.include RSpec::Benchmark::Matchers + # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/fixtures.rb b/spec/support/fixtures.rb new file mode 100644 index 00000000..96309f21 --- /dev/null +++ b/spec/support/fixtures.rb @@ -0,0 +1,13 @@ +def fixture(size) + full_path("spec/fixtures/data#{size}.txt") +end + +def full_path(path, base = '/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1') + File.expand_path(path, base) +end + +def ensure_test_data_exists(n) + test_file = fixture(n) + source_file = full_path("data_large.txt") + `if [ ! -f #{test_file} ]; then head -n #{n} #{source_file} > #{test_file}; fi` +end diff --git a/spec/correctness_spec.rb b/spec/work/correctness_spec.rb similarity index 98% rename from spec/correctness_spec.rb rename to spec/work/correctness_spec.rb index 91b0d237..aeba9445 100644 --- a/spec/correctness_spec.rb +++ b/spec/work/correctness_spec.rb @@ -1,4 +1,4 @@ -require_relative '../task-1' +require_relative '../../task-1' RSpec.describe 'Work' do subject { work } diff --git a/spec/work/performance_spec.rb b/spec/work/performance_spec.rb new file mode 100644 index 00000000..873c50e6 --- /dev/null +++ b/spec/work/performance_spec.rb @@ -0,0 +1,26 @@ +require_relative '../../task-1' + +RSpec.describe 'Work' do + describe 'performance' do + let(:from) { 8 } + let(:to) { 10_000 } + let(:benchmark_range) { bench_range(from, to) } + let(:file_path) { full_path("spec/fixtures/data#{size}.txt") } + + describe 'complexity' do + before {benchmark_range.each { |i| ensure_test_data_exists(i) }} + + # it 'performs linear' do + # expect { |n, _i| work(fixture(n)) }.to perform_linear.in_range(from, to) + # end + + # it 'performs logarithmic' do + # expect { |n, _i| work(fixture(n)) }.to perform_logarithmic.in_range(from, to) + # end + + it 'performs power' do + expect { |n, _i| work(fixture(n)) }.not_to perform_power.in_range(from, to) + end + end + end +end diff --git a/task-1.rb b/task-1.rb index 778672df..7d0ec010 100644 --- a/task-1.rb +++ b/task-1.rb @@ -43,8 +43,8 @@ def collect_stats_from_users(report, users_objects, &block) end end -def work - file_lines = File.read('data.txt').split("\n") +def work(file_path = 'data.txt') + file_lines = File.read(file_path).split("\n") users = [] sessions = [] From 55be6f2be9fc785bd9fbcea91f248b7315cd0083 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 05:56:02 +0300 Subject: [PATCH 05/25] Expand performance tests --- .gitignore | 1 + result.json | 1 - spec/spec_helper.rb | 1 + spec/work/correctness_spec.rb | 2 -- spec/work/performance/budget_spec.rb | 20 +++++++++++++++++ .../complexity_spec.rb} | 12 +++++----- spec/work/performance/speed_spec.rb | 22 +++++++++++++++++++ 7 files changed, 49 insertions(+), 10 deletions(-) delete mode 100644 result.json create mode 100644 spec/work/performance/budget_spec.rb rename spec/work/{performance_spec.rb => performance/complexity_spec.rb} (69%) create mode 100644 spec/work/performance/speed_spec.rb diff --git a/.gitignore b/.gitignore index 63f55fe8..e1f16b3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data_large.txt spec/fixtures/ +result.json diff --git a/result.json b/result.json deleted file mode 100644 index ad485631..00000000 --- a/result.json +++ /dev/null @@ -1 +0,0 @@ -{"totalUsers":3,"uniqueBrowsersCount":14,"totalSessions":15,"allBrowsers":"CHROME 13,CHROME 20,CHROME 35,CHROME 6,FIREFOX 12,FIREFOX 32,FIREFOX 47,INTERNET EXPLORER 10,INTERNET EXPLORER 28,INTERNET EXPLORER 35,SAFARI 17,SAFARI 29,SAFARI 39,SAFARI 49","usersStats":{"Leida Cira":{"sessionsCount":6,"totalTime":"455 min.","longestSession":"118 min.","browsers":"FIREFOX 12, INTERNET EXPLORER 28, INTERNET EXPLORER 28, INTERNET EXPLORER 35, SAFARI 29, SAFARI 39","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-09-27","2017-03-28","2017-02-27","2016-10-23","2016-09-15","2016-09-01"]},"Palmer Katrina":{"sessionsCount":5,"totalTime":"218 min.","longestSession":"116 min.","browsers":"CHROME 13, CHROME 6, FIREFOX 32, INTERNET EXPLORER 10, SAFARI 17","usedIE":true,"alwaysUsedChrome":false,"dates":["2017-04-29","2016-12-28","2016-12-20","2016-11-11","2016-10-21"]},"Gregory Santos":{"sessionsCount":4,"totalTime":"192 min.","longestSession":"85 min.","browsers":"CHROME 20, CHROME 35, FIREFOX 47, SAFARI 49","usedIE":false,"alwaysUsedChrome":false,"dates":["2018-09-21","2018-02-02","2017-05-22","2016-11-25"]}}} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 87740aae..0f0a1212 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,6 +15,7 @@ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration require 'rspec-benchmark' +require_relative '../task-1' Dir[File.expand_path('spec/support/**/*.rb')].each { |f| require_relative(f) } # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration diff --git a/spec/work/correctness_spec.rb b/spec/work/correctness_spec.rb index aeba9445..d9bb4b3b 100644 --- a/spec/work/correctness_spec.rb +++ b/spec/work/correctness_spec.rb @@ -1,5 +1,3 @@ -require_relative '../../task-1' - RSpec.describe 'Work' do subject { work } diff --git a/spec/work/performance/budget_spec.rb b/spec/work/performance/budget_spec.rb new file mode 100644 index 00000000..80ca3586 --- /dev/null +++ b/spec/work/performance/budget_spec.rb @@ -0,0 +1,20 @@ +RSpec.describe 'Work' do + describe 'performance' do + subject { work(file_path) } + + let(:file_path) { fixture(size) } + let(:warmup_seconds) { 1 } + let(:size) { 10_000 } + let(:ms) { 2_800 } + + before { ensure_test_data_exists(size) } + + xdescribe 'budget' do + let(:file_path) { 'data_large.txt' } + + it 'is fast as hell' do + expect { work(file_path) }.to perform_under(30).sec.warmup(warmup_seconds).times.sample(2).times + end + end + end +end diff --git a/spec/work/performance_spec.rb b/spec/work/performance/complexity_spec.rb similarity index 69% rename from spec/work/performance_spec.rb rename to spec/work/performance/complexity_spec.rb index 873c50e6..e2bf7390 100644 --- a/spec/work/performance_spec.rb +++ b/spec/work/performance/complexity_spec.rb @@ -1,5 +1,3 @@ -require_relative '../../task-1' - RSpec.describe 'Work' do describe 'performance' do let(:from) { 8 } @@ -7,18 +5,18 @@ let(:benchmark_range) { bench_range(from, to) } let(:file_path) { full_path("spec/fixtures/data#{size}.txt") } - describe 'complexity' do - before {benchmark_range.each { |i| ensure_test_data_exists(i) }} + xdescribe 'complexity' do + before { benchmark_range.each { |i| ensure_test_data_exists(i) } } - # it 'performs linear' do + # it 'is linear' do # expect { |n, _i| work(fixture(n)) }.to perform_linear.in_range(from, to) # end - # it 'performs logarithmic' do + # it 'is logarithmic' do # expect { |n, _i| work(fixture(n)) }.to perform_logarithmic.in_range(from, to) # end - it 'performs power' do + it 'is not power' do expect { |n, _i| work(fixture(n)) }.not_to perform_power.in_range(from, to) end end diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb new file mode 100644 index 00000000..cf469cb9 --- /dev/null +++ b/spec/work/performance/speed_spec.rb @@ -0,0 +1,22 @@ +RSpec.describe 'Work' do + describe 'performance' do + subject { work(file_path) } + + let(:file_path) { fixture(size) } + let(:warmup_seconds) { 1 } + let(:size) { 10_000 } + let(:ms) { 2_800 } + + before { ensure_test_data_exists(size) } + + describe 'ms' do + it 'is equals or better that current implementation' do + expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times + end + + it 'is trying to be better ' do + expect { work(file_path) }.to perform_under(ms/2).ms.warmup(warmup_seconds).times.sample(10).times + end + end + end +end From 86c8fb31c8e843ed7632eaa0b5562d4ac48a9455 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 08:10:08 +0300 Subject: [PATCH 06/25] Update case study --- case-study.md | 22 ++++++++++++++++++---- spec/work/performance/speed_spec.rb | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/case-study.md b/case-study.md index d41034d9..40612a41 100644 --- a/case-study.md +++ b/case-study.md @@ -12,15 +12,30 @@ Я решил исправить эту проблему, оптимизировав эту программу. ## Формирование метрики -Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: *тут ваша метрика* +Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: ms / 10к записей ## Гарантия корректности работы оптимизированной программы Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. +```ruby + describe 'ms' do + it 'is equals or better that current implementation' do + expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times + end + + it 'is trying to be better ' do + expect { work(file_path) }.to perform_under(ms/2).ms.warmup(warmup_seconds).times.sample(10).times + end + end +``` + ## Feedback-Loop -Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за *время, которое у вас получилось* +Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за несколько секунд. -Вот как я построил `feedback_loop`: *как вы построили feedback_loop* +Вот как я построил `feedback_loop`: +- вношу изменение +- выполняю тест который проверяет, стала ли программа в 2 раза быстрее +- смотрю на новое время, если оно меня устраивает, коммичу изменение и обновляю значение защитной метрики. ## Вникаем в детали системы, чтобы найти главные точки роста Для того, чтобы найти "точки роста" для оптимизации я воспользовался *инструментами, которыми вы воспользовались* @@ -53,4 +68,3 @@ ## Защита от регрессии производительности Для защиты от потери достигнутого прогресса при дальнейших изменениях программы *о performance-тестах, которые вы написали* - diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index cf469cb9..f805a241 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -10,7 +10,7 @@ before { ensure_test_data_exists(size) } describe 'ms' do - it 'is equals or better that current implementation' do + xit 'is equals or better that current implementation' do expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times end From b12172d1adb6b94190b7eb9f5a41541b19630aea Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 08:29:55 +0300 Subject: [PATCH 07/25] Add ruby-prof flat report --- profiling/ruby_prof_flat.rb | 12 +++++ profiling/ruby_prof_reports/flat.txt | 66 ++++++++++++++++++++++++++++ profiling/setup.rb | 7 +++ task-1.rb | 6 ++- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 profiling/ruby_prof_flat.rb create mode 100644 profiling/ruby_prof_reports/flat.txt create mode 100644 profiling/setup.rb diff --git a/profiling/ruby_prof_flat.rb b/profiling/ruby_prof_flat.rb new file mode 100644 index 00000000..f0a0a558 --- /dev/null +++ b/profiling/ruby_prof_flat.rb @@ -0,0 +1,12 @@ +require_relative 'setup' + +# RubyProf Flat report +# ruby 12-ruby-prof-flat.rb +# cat ruby_prof_reports/flat.txt +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile { work(Setup::FILE_PATH, disable_gc: true) } +printer = RubyProf::FlatPrinter.new(result) +file_path = File.join(Setup::REPORTS_PATH, 'flat.txt') +file = File.open(file_path, "w+") +printer.print(file) diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt new file mode 100644 index 00000000..92347d48 --- /dev/null +++ b/profiling/ruby_prof_reports/flat.txt @@ -0,0 +1,66 @@ +Measure Mode: wall_time +Thread ID: 260 +Fiber ID: 240 +Total: 4.884640 +Sort by: self_time + + %self total self wait child calls name location + 87.54 4.276 4.276 0.000 0.000 1536 Array#select + 5.07 4.864 0.248 0.000 4.617 10 Array#each + 3.27 0.161 0.160 0.000 0.001 10000 Array#all? + 1.03 0.125 0.050 0.000 0.075 16898 Array#map + 0.59 0.062 0.029 0.000 0.033 8464 #parse + 0.50 0.025 0.025 0.000 0.000 20001 String#split + 0.28 0.014 0.014 0.000 0.000 16928 Regexp#match + 0.20 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:27 + 0.15 0.011 0.007 0.000 0.004 3073 Array#sort + 0.15 0.007 0.007 0.000 0.000 8464 String#gsub! + 0.14 0.007 0.007 0.000 0.000 23399 String#upcase + 0.13 0.007 0.007 0.000 0.000 10752 Hash#merge + 0.12 0.006 0.006 0.000 0.000 8464 MatchData#begin + 0.10 0.005 0.005 0.000 0.000 8464 Date#iso8601 + 0.09 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 0.08 0.004 0.004 0.000 0.000 17169 Date#<=> + 0.08 0.005 0.004 0.000 0.001 1536 Array#any? + 0.07 0.005 0.004 0.000 0.001 1536 Class#new + 0.07 0.003 0.003 0.000 0.000 16928 String#to_i + 0.06 0.003 0.003 0.000 0.000 8464 String#[]= + 0.04 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:17 + 0.04 0.002 0.002 0.000 0.000 8464 Integer#div + 0.03 0.002 0.002 0.000 0.000 1537 Array#join + 0.03 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.03 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 0.02 0.001 0.001 0.000 0.000 1 #read + 0.02 0.001 0.001 0.000 0.000 3072 String#+ + 0.02 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.01 0.001 0.001 0.000 0.000 1 Array#uniq + 0.01 0.001 0.001 0.000 0.000 1 #write + 0.01 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.01 0.000 0.000 0.000 0.000 1536 Array#max + 0.01 0.000 0.000 0.000 0.000 1536 Array#sum + 0.01 0.000 0.000 0.000 0.000 1539 Array#count + 0.00 4.885 0.000 0.000 4.884 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:46 + 0.00 0.181 0.000 0.000 0.181 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:38 + 0.00 4.885 0.000 0.000 4.885 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize + +* recursively called methods + +Columns are: + + %self - The percentage of time spent in this method, derived from self_time/total_time. + total - The time spent in this method and its children. + self - The time spent in this method. + wait - The amount of time this method waited for other threads. + child - The time spent in this method's children. + calls - The number of times this method was called. + name - The name of the method. + location - The location of the method. + +The interpretation of method names is: + + * MyObject#test - An instance method "test" of the class "MyObject" + * #test - The <> characters indicate a method on a singleton class. + diff --git a/profiling/setup.rb b/profiling/setup.rb new file mode 100644 index 00000000..bf158031 --- /dev/null +++ b/profiling/setup.rb @@ -0,0 +1,7 @@ +require 'ruby-prof' +require_relative '../task-1' + +class Setup + FILE_PATH = '/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/spec/fixtures/data10000.txt' + REPORTS_PATH = '/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_reports' +end diff --git a/task-1.rb b/task-1.rb index 7d0ec010..a6ab0637 100644 --- a/task-1.rb +++ b/task-1.rb @@ -43,7 +43,9 @@ def collect_stats_from_users(report, users_objects, &block) end end -def work(file_path = 'data.txt') +def work(file_path = 'data.txt', **options) + GC.disable if options[:disable_gc] + file_lines = File.read(file_path).split("\n") users = [] @@ -141,6 +143,8 @@ def work(file_path = 'data.txt') end File.write('result.json', "#{report.to_json}\n") +ensure + GC.enable end class TestMe < Minitest::Test From 48c910f46b7a0832d5be0ab1b8ab845cbf2a3be6 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 08:58:59 +0300 Subject: [PATCH 08/25] Update Array#select --- case-study.md | 23 ++++++++ profiling/ruby_prof_reports/flat.txt | 78 ++++++++++++++-------------- spec/work/performance/speed_spec.rb | 4 +- task-1.rb | 35 ++++++++----- 4 files changed, 86 insertions(+), 54 deletions(-) diff --git a/case-study.md b/case-study.md index 40612a41..6e06154e 100644 --- a/case-study.md +++ b/case-study.md @@ -44,10 +44,33 @@ ### Ваша находка №1 - какой отчёт показал главную точку роста + + %self total self wait child calls name location + 87.54 4.276 4.276 0.000 0.000 1536 Array#select + 5.07 4.864 0.248 0.000 4.617 10 Array#each + 3.27 0.161 0.160 0.000 0.001 10000 Array#all? + +Array#select - единственный в программе + - как вы решили её оптимизировать + +Во-первых, мы будем выбирать сессии пользователя не по каждому пользователю снова и снова - а пробежимся с этой целью по сессиям только один раз, при этом раскидывая сессии по пользователям. +Во-вторых, для каждой сессии нам нужно будет находить подходящего пользователя. Вместо того, чтобы выбирать нужного из массива, мы будем хранить пользователей в виде хэша, с ключом по 'id'. +В-третьих, мы начнем хранить данные пользователя в отдельных переменных, а не скопом в 'attributes'. + - как изменилась метрика + +2_800ms -> 480ms + - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + %self total self wait child calls name location + 39.74 0.567 0.233 0.000 0.334 11 Array#each + 27.07 0.159 0.159 0.000 0.001 10000 Array#all? + 8.15 0.123 0.048 0.000 0.075 16898 Array#map + +Да, перестала + ### Ваша находка №2 - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index 92347d48..0a6db3aa 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,49 +1,49 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 4.884640 +Total: 0.586489 Sort by: self_time %self total self wait child calls name location - 87.54 4.276 4.276 0.000 0.000 1536 Array#select - 5.07 4.864 0.248 0.000 4.617 10 Array#each - 3.27 0.161 0.160 0.000 0.001 10000 Array#all? - 1.03 0.125 0.050 0.000 0.075 16898 Array#map - 0.59 0.062 0.029 0.000 0.033 8464 #parse - 0.50 0.025 0.025 0.000 0.000 20001 String#split - 0.28 0.014 0.014 0.000 0.000 16928 Regexp#match - 0.20 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:27 - 0.15 0.011 0.007 0.000 0.004 3073 Array#sort - 0.15 0.007 0.007 0.000 0.000 8464 String#gsub! - 0.14 0.007 0.007 0.000 0.000 23399 String#upcase - 0.13 0.007 0.007 0.000 0.000 10752 Hash#merge - 0.12 0.006 0.006 0.000 0.000 8464 MatchData#begin - 0.10 0.005 0.005 0.000 0.000 8464 Date#iso8601 - 0.09 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 0.08 0.004 0.004 0.000 0.000 17169 Date#<=> - 0.08 0.005 0.004 0.000 0.001 1536 Array#any? - 0.07 0.005 0.004 0.000 0.001 1536 Class#new - 0.07 0.003 0.003 0.000 0.000 16928 String#to_i - 0.06 0.003 0.003 0.000 0.000 8464 String#[]= - 0.04 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:17 - 0.04 0.002 0.002 0.000 0.000 8464 Integer#div - 0.03 0.002 0.002 0.000 0.000 1537 Array#join - 0.03 0.002 0.002 0.000 0.000 8464 MatchData#end - 0.03 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 - 0.02 0.001 0.001 0.000 0.000 1 #read - 0.02 0.001 0.001 0.000 0.000 3072 String#+ - 0.02 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.01 0.001 0.001 0.000 0.000 1 Array#uniq - 0.01 0.001 0.001 0.000 0.000 1 #write - 0.01 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.01 0.000 0.000 0.000 0.000 1536 Array#max - 0.01 0.000 0.000 0.000 0.000 1536 Array#sum - 0.01 0.000 0.000 0.000 0.000 1539 Array#count - 0.00 4.885 0.000 0.000 4.884 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:46 - 0.00 0.181 0.000 0.000 0.181 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:38 - 0.00 4.885 0.000 0.000 4.885 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 39.74 0.567 0.233 0.000 0.334 11 Array#each + 27.07 0.159 0.159 0.000 0.001 10000 Array#all? + 8.15 0.123 0.048 0.000 0.075 16898 Array#map + 4.91 0.062 0.029 0.000 0.033 8464 #parse + 4.34 0.025 0.025 0.000 0.000 20001 String#split + 2.31 0.014 0.014 0.000 0.000 16928 Regexp#match + 1.67 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 1.22 0.011 0.007 0.000 0.003 3073 Array#sort + 1.20 0.007 0.007 0.000 0.000 8464 String#gsub! + 1.19 0.007 0.007 0.000 0.000 23399 String#upcase + 1.06 0.006 0.006 0.000 0.000 8464 MatchData#begin + 1.01 0.006 0.006 0.000 0.000 10752 Hash#merge + 0.79 0.005 0.005 0.000 0.000 8464 Date#iso8601 + 0.74 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 0.62 0.005 0.004 0.000 0.001 1536 Array#any? + 0.60 0.004 0.004 0.000 0.000 16928 String#to_i + 0.58 0.003 0.003 0.000 0.000 17169 Date#<=> + 0.47 0.003 0.003 0.000 0.000 8464 String#[]= + 0.29 0.002 0.002 0.000 0.000 8464 Integer#div + 0.28 0.002 0.002 0.000 0.000 1537 Array#join + 0.27 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.26 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.22 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 0.18 0.002 0.001 0.000 0.001 1536 Class#new + 0.15 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.12 0.001 0.001 0.000 0.000 3072 String#+ + 0.11 0.001 0.001 0.000 0.000 1 Array#uniq + 0.08 0.000 0.000 0.000 0.000 1 #write + 0.08 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.08 0.000 0.000 0.000 0.000 1536 Array#max + 0.06 0.000 0.000 0.000 0.000 1536 Array#sum + 0.06 0.000 0.000 0.000 0.000 1 #read + 0.05 0.000 0.000 0.000 0.000 1539 Array#count + 0.03 0.586 0.000 0.000 0.586 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 + 0.00 0.174 0.000 0.000 0.174 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 + 0.00 0.586 0.000 0.000 0.586 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.00 0.000 0.000 0.000 0.000 1 Hash#values 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.000 0.000 0.000 0.000 1 #disable :84 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize * recursively called methods diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index f805a241..590cdf66 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -5,12 +5,12 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } let(:size) { 10_000 } - let(:ms) { 2_800 } + let(:ms) { 480 } before { ensure_test_data_exists(size) } describe 'ms' do - xit 'is equals or better that current implementation' do + it 'is equals or better that current implementation' do expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times end diff --git a/task-1.rb b/task-1.rb index a6ab0637..110f746c 100644 --- a/task-1.rb +++ b/task-1.rb @@ -6,10 +6,14 @@ require 'minitest/autorun' class User - attr_reader :attributes, :sessions - - def initialize(attributes:, sessions:) - @attributes = attributes + attr_reader :id, :first_name, :last_name, :age + attr_accessor :sessions + + def initialize(id:, first_name:, last_name:, age:, sessions: []) + @id = id + @first_name = first_name + @last_name = last_name + @age = age @sessions = sessions end end @@ -17,10 +21,10 @@ def initialize(attributes:, sessions:) def parse_user(user) fields = user.split(',') parsed_result = { - 'id' => fields[1], - 'first_name' => fields[2], - 'last_name' => fields[3], - 'age' => fields[4], + id: fields[1], + first_name: fields[2], + last_name: fields[3], + age: fields[4], } end @@ -37,7 +41,7 @@ def parse_session(session) def collect_stats_from_users(report, users_objects, &block) users_objects.each do |user| - user_key = "#{user.attributes['first_name']}" + ' ' + "#{user.attributes['last_name']}" + user_key = "#{user.first_name}" + ' ' + "#{user.last_name}" report['usersStats'][user_key] ||= {} report['usersStats'][user_key] = report['usersStats'][user_key].merge(block.call(user)) end @@ -96,17 +100,22 @@ def work(file_path = 'data.txt', **options) .join(',') # Статистика по пользователям - users_objects = [] + users_objects_by_id = {} users.each do |user| attributes = user - user_sessions = sessions.select { |session| session['user_id'] == user['id'] } - user_object = User.new(attributes: attributes, sessions: user_sessions) - users_objects = users_objects + [user_object] + user_object = User.new(**attributes) + users_objects_by_id[user_object.id] = user_object + end + + sessions.each do |session| + users_objects_by_id[session['user_id']].sessions << session end report['usersStats'] = {} + users_objects = users_objects_by_id.values + # Собираем количество сессий по пользователям collect_stats_from_users(report, users_objects) do |user| { 'sessionsCount' => user.sessions.count } From 3d98d4be2dfa8ab5bbf57d23d89548aa99ffa41d Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 09:07:05 +0300 Subject: [PATCH 09/25] Add graph report --- .DS_Store | Bin 0 -> 6148 bytes profiling/ruby_prof_graph.rb | 13 + profiling/ruby_prof_reports/flat.txt | 64 +- profiling/ruby_prof_reports/graph.html | 2797 ++++++++++++++++++++++++ 4 files changed, 2842 insertions(+), 32 deletions(-) create mode 100644 .DS_Store create mode 100644 profiling/ruby_prof_graph.rb create mode 100644 profiling/ruby_prof_reports/graph.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a1aa4490fe2cafc8e58c9dcef3125b2d018fa27d GIT binary patch literal 6148 zcmeHK!A`?441Ijb3Vf}S*(Br%APZZTSuXhPz@^$0b8*+yxMkN|m{E8t) zXFPdc;|)+G`X2p8jRbt?3*FhX5|L6<_S-C7m;`aqJB%o$*R1#z8=J2@3^& GLxE4mS0zmV literal 0 HcmV?d00001 diff --git a/profiling/ruby_prof_graph.rb b/profiling/ruby_prof_graph.rb new file mode 100644 index 00000000..0027ac1f --- /dev/null +++ b/profiling/ruby_prof_graph.rb @@ -0,0 +1,13 @@ +require_relative 'setup' + +# RubyProf Graph report +# ruby 13-ruby-prof-graph.rb +# open ruby_prof_reports/graph.html + +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile { work(Setup::FILE_PATH, disable_gc: true) } + +printer = RubyProf::GraphHtmlPrinter.new(result) +file_path = File.join(Setup::REPORTS_PATH, 'graph.html') +printer.print(File.open(file_path, "w+")) diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index 0a6db3aa..df7461e5 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,46 +1,46 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.586489 +Total: 0.611087 Sort by: self_time %self total self wait child calls name location - 39.74 0.567 0.233 0.000 0.334 11 Array#each - 27.07 0.159 0.159 0.000 0.001 10000 Array#all? - 8.15 0.123 0.048 0.000 0.075 16898 Array#map - 4.91 0.062 0.029 0.000 0.033 8464 #parse - 4.34 0.025 0.025 0.000 0.000 20001 String#split - 2.31 0.014 0.014 0.000 0.000 16928 Regexp#match - 1.67 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 1.22 0.011 0.007 0.000 0.003 3073 Array#sort - 1.20 0.007 0.007 0.000 0.000 8464 String#gsub! - 1.19 0.007 0.007 0.000 0.000 23399 String#upcase - 1.06 0.006 0.006 0.000 0.000 8464 MatchData#begin + 40.92 0.591 0.250 0.000 0.341 11 Array#each + 26.37 0.162 0.161 0.000 0.001 10000 Array#all? + 7.97 0.123 0.049 0.000 0.075 16898 Array#map + 4.65 0.028 0.028 0.000 0.000 20001 String#split + 4.64 0.061 0.028 0.000 0.033 8464 #parse + 2.20 0.013 0.013 0.000 0.000 16928 Regexp#match + 1.61 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 1.22 0.007 0.007 0.000 0.000 8464 String#gsub! + 1.20 0.011 0.007 0.000 0.004 3073 Array#sort + 1.12 0.007 0.007 0.000 0.000 23399 String#upcase 1.01 0.006 0.006 0.000 0.000 10752 Hash#merge - 0.79 0.005 0.005 0.000 0.000 8464 Date#iso8601 - 0.74 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 0.62 0.005 0.004 0.000 0.001 1536 Array#any? - 0.60 0.004 0.004 0.000 0.000 16928 String#to_i - 0.58 0.003 0.003 0.000 0.000 17169 Date#<=> - 0.47 0.003 0.003 0.000 0.000 8464 String#[]= - 0.29 0.002 0.002 0.000 0.000 8464 Integer#div - 0.28 0.002 0.002 0.000 0.000 1537 Array#join - 0.27 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.98 0.006 0.006 0.000 0.000 8464 MatchData#begin + 0.76 0.005 0.005 0.000 0.000 8464 Date#iso8601 + 0.65 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 0.63 0.004 0.004 0.000 0.000 17169 Date#<=> + 0.61 0.005 0.004 0.000 0.001 1536 Array#any? + 0.61 0.004 0.004 0.000 0.000 16928 String#to_i + 0.43 0.003 0.003 0.000 0.000 8464 String#[]= + 0.30 0.002 0.002 0.000 0.000 8464 Integer#div 0.26 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.26 0.002 0.002 0.000 0.000 1537 Array#join + 0.25 0.004 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 0.22 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.18 0.002 0.001 0.000 0.001 1536 Class#new - 0.15 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.12 0.001 0.001 0.000 0.000 3072 String#+ - 0.11 0.001 0.001 0.000 0.000 1 Array#uniq - 0.08 0.000 0.000 0.000 0.000 1 #write - 0.08 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.08 0.000 0.000 0.000 0.000 1536 Array#max + 0.19 0.001 0.001 0.000 0.000 1 #read + 0.17 0.002 0.001 0.000 0.001 1536 Class#new + 0.14 0.001 0.001 0.000 0.000 1 Array#uniq + 0.13 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.13 0.001 0.001 0.000 0.000 3072 String#+ + 0.08 0.001 0.001 0.000 0.000 1536 Array#reverse + 0.07 0.000 0.000 0.000 0.000 1 #write + 0.07 0.000 0.000 0.000 0.000 1536 Array#max 0.06 0.000 0.000 0.000 0.000 1536 Array#sum - 0.06 0.000 0.000 0.000 0.000 1 #read 0.05 0.000 0.000 0.000 0.000 1539 Array#count - 0.03 0.586 0.000 0.000 0.586 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 0.00 0.174 0.000 0.000 0.174 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 - 0.00 0.586 0.000 0.000 0.586 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.03 0.611 0.000 0.000 0.611 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 + 0.00 0.611 0.000 0.000 0.611 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.00 0.176 0.000 0.000 0.176 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.00 0.000 0.000 0.000 0.000 1 Hash#values 0.00 0.000 0.000 0.000 0.000 1 #enable :72 0.00 0.000 0.000 0.000 0.000 1 #disable :84 diff --git a/profiling/ruby_prof_reports/graph.html b/profiling/ruby_prof_reports/graph.html new file mode 100644 index 00000000..337765df --- /dev/null +++ b/profiling/ruby_prof_reports/graph.html @@ -0,0 +1,2797 @@ + + + + + + +
+
+
+
Profile Report
+

Wall_time

+
+
+
Wednesday, October 18 at 9:02:59 AM (MSK)
+ +
+
+
+
+ + + + + + + + + + + + + +
Thread IDFiber IDTotal
2602400.5796185110229999
+ + + +

Thread 260, Fiber: 240

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
%Total%SelfTotalSelfWaitChildCallsNameLine
100.00%0.00%0.580.000.000.581 + + [global]# + + 9
  0.580.000.000.581/1Object#work9 +
  0.580.000.000.581/1[global]#9
100.00%0.03%0.580.000.000.581 + + Object#work + + 50
  0.390.200.000.194/11Array#each58 +
  0.170.000.000.177/7Object#collect_stats_from_users120 +
  0.010.010.000.002/16898Array#map94 +
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json154 +
  0.000.000.000.001/20001String#split53 +
  0.000.000.000.001/3073Array#sort94 +
  0.000.000.000.001/1Array#uniq94 +
  0.000.000.000.001/1<Class::IO>#write154 +
  0.000.000.000.001/1<Class::IO>#read53 +
  0.000.000.000.001/1537Array#join94 +
  0.000.000.000.003/1539Array#count81 +
  0.000.000.000.001/1<Module::GC>#disable51 +
  0.000.000.000.001/1Hash#values117 +
  0.000.000.000.001/1<Module::GC>#enable156 +
  0.170.030.000.147/11Object#collect_stats_from_users43
  0.390.200.000.194/11Object#work58
96.87%40.12%0.560.230.000.3311 + + Array#each + +
  0.160.160.000.0010000/10000Array#all?87 +
  0.110.040.000.0716896/16898Array#map126 +
  0.020.010.000.018464/8464Object#parse_session61 +
  0.010.010.000.0010000/20001String#split59 +
  0.010.010.000.003072/3073Array#sort136 +
  0.010.010.000.0010752/10752Hash#merge121 +
  0.000.000.000.001536/1536Array#any?141 +
  0.000.000.000.001536/1536Object#parse_user60 +
  0.000.000.000.001536/1536Class#new107 +
  0.000.000.000.001536/1537Array#join136 +
  0.000.000.000.003072/3072Integer#to_s126 +
  0.000.000.000.003072/3072String#+126 +
  0.000.000.000.001536/1536Array#reverse151 +
  0.000.000.000.001536/1536Array#max131 +
  0.000.000.000.001536/1536Array#sum126 +
  0.000.000.000.001536/1539Array#count121 +
  0.170.000.000.177/7Object#work120
29.38%0.00%0.170.000.000.177 + + Object#collect_stats_from_users + + 42
  0.170.030.000.147/11Array#each43 +
  0.160.160.000.0010000/10000Array#each
27.44%27.34%0.160.160.000.0010000 + + Array#all? + +
  0.000.000.000.001979/23399String#upcase146 +
  0.010.010.000.002/16898Object#work94
  0.110.040.000.0716896/16898Array#each
20.38%8.03%0.120.050.000.0716898 + + Array#map + +
  0.060.030.000.038464/8464<Class::Date>#parse151 +
  0.000.000.000.0016928/23399String#upcase97 +
  0.000.000.000.008464/8464Date#iso8601151 +
  0.000.000.000.0016928/16928String#to_i126 +
  0.060.030.000.038464/8464Array#map
10.22%4.79%0.060.030.000.038464 + + <Class::Date>#parse + +
  0.010.010.000.0016928/16928Regexp#match +
  0.010.010.000.008464/8464String#gsub! +
  0.010.010.000.008464/8464MatchData#begin +
  0.000.000.000.008464/8464String#[]= +
  0.000.000.000.008464/8464Integer#div +
  0.000.000.000.008464/8464MatchData#end +
  0.000.000.000.001536/20001Object#parse_user22
  0.000.000.000.001/20001Object#work53
  0.010.010.000.008464/20001Object#parse_session32
  0.010.010.000.0010000/20001Array#each
4.25%4.25%0.020.020.000.0020001 + + String#split + +
  0.020.010.000.018464/8464Array#each
3.21%1.69%0.020.010.000.018464 + + Object#parse_session + + 31
  0.010.010.000.008464/20001String#split32 +
  0.010.010.000.0016928/16928<Class::Date>#parse
2.21%2.21%0.010.010.000.0016928 + + Regexp#match + +
  0.000.000.000.001/3073Object#work94
  0.010.010.000.003072/3073Array#each
1.84%1.20%0.010.010.000.003073 + + Array#sort + +
  0.000.000.000.0017169/17169Date#<=> +
  0.010.010.000.008464/8464<Class::Date>#parse
1.18%1.18%0.010.010.000.008464 + + String#gsub! + +
  0.000.000.000.001979/23399Array#all?
  0.000.000.000.004492/23399Array#any?
  0.000.000.000.0016928/23399Array#map
1.08%1.08%0.010.010.000.0023399 + + String#upcase + +
  0.010.010.000.008464/8464<Class::Date>#parse
1.05%1.05%0.010.010.000.008464 + + MatchData#begin + +
  0.010.010.000.0010752/10752Array#each
1.02%1.02%0.010.010.000.0010752 + + Hash#merge + +
  0.000.000.000.001536/1536Array#each
0.84%0.64%0.000.000.000.001536 + + Array#any? + +
  0.000.000.000.004492/23399String#upcase141 +
  0.000.000.000.008464/8464Array#map
0.76%0.76%0.000.000.000.008464 + + Date#iso8601 + +
  0.000.000.000.001/1Object#work154
0.69%0.69%0.000.000.000.001 + + JSON::Ext::Generator::GeneratorMethods::Hash#to_json + +
  0.000.000.000.001/1JSON::Ext::Generator::State#initialize +
  0.000.000.000.0017169/17169Array#sort
0.63%0.63%0.000.000.000.0017169 + + Date#<=> + +
  0.000.000.000.0016928/16928Array#map
0.60%0.60%0.000.000.000.0016928 + + String#to_i + +
  0.000.000.000.001536/1536Array#each
0.52%0.27%0.000.000.000.001536 + + Object#parse_user + + 21
  0.000.000.000.001536/20001String#split22 +
  0.000.000.000.008464/8464<Class::Date>#parse
0.43%0.43%0.000.000.000.008464 + + String#[]= + +
  0.000.000.000.001536/1536Array#each
0.38%0.17%0.000.000.000.001536 + + Class#new + +
  0.000.000.000.001536/1536User#initialize +
  0.000.000.000.008464/8464<Class::Date>#parse
0.29%0.29%0.000.000.000.008464 + + Integer#div + +
  0.000.000.000.008464/8464<Class::Date>#parse
0.27%0.27%0.000.000.000.008464 + + MatchData#end + +
  0.000.000.000.001/1537Object#work94
  0.000.000.000.001536/1537Array#each
0.26%0.26%0.000.000.000.001537 + + Array#join + +
  0.000.000.000.001536/1536Class#new
0.21%0.21%0.000.000.000.001536 + + User#initialize + + 12
  0.000.000.000.003072/3072Array#each
0.15%0.15%0.000.000.000.003072 + + Integer#to_s + +
  0.000.000.000.003072/3072Array#each
0.14%0.14%0.000.000.000.003072 + + String#+ + +
  0.000.000.000.001/1Object#work94
0.11%0.11%0.000.000.000.001 + + Array#uniq + +
  0.000.000.000.001536/1536Array#each
0.09%0.09%0.000.000.000.001536 + + Array#reverse + +
  0.000.000.000.001/1Object#work154
0.08%0.08%0.000.000.000.001 + + <Class::IO>#write + +
  0.000.000.000.001536/1536Array#each
0.06%0.06%0.000.000.000.001536 + + Array#max + +
  0.000.000.000.001536/1536Array#each
0.06%0.06%0.000.000.000.001536 + + Array#sum + +
  0.000.000.000.001/1Object#work53
0.06%0.06%0.000.000.000.001 + + <Class::IO>#read + +
  0.000.000.000.003/1539Object#work81
  0.000.000.000.001536/1539Array#each
0.05%0.05%0.000.000.000.001539 + + Array#count + +
  0.000.000.000.001/1Object#work51
0.00%0.00%0.000.000.000.001 + + <Module::GC>#disable + + 84
  0.000.000.000.001/1Object#work117
0.00%0.00%0.000.000.000.001 + + Hash#values + +
  0.000.000.000.001/1Object#work156
0.00%0.00%0.000.000.000.001 + + <Module::GC>#enable + + 72
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json
0.00%0.00%0.000.000.000.001 + + JSON::Ext::Generator::State#initialize + +
* indicates recursively called methods
+ +
+ + + + From 78ce3df5b5f332abbd54f8b17e058e8c4e1c9722 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 09:26:17 +0300 Subject: [PATCH 10/25] Extract methods from work --- case-study.md | 7 +++++++ task-1.rb | 54 +++++++++++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/case-study.md b/case-study.md index 6e06154e..5572db93 100644 --- a/case-study.md +++ b/case-study.md @@ -73,7 +73,14 @@ Array#select - единственный в программе ### Ваша находка №2 - какой отчёт показал главную точку роста + +Смотрим flat + graph. Array#each остается одним из лидеров. +Прежде чем приступать к оптимизации, попробуем выделить фрагменты программы в отдельные методы, чтобы было удобнее профилировать. + - как вы решили её оптимизировать + + + - как изменилась метрика - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? diff --git a/task-1.rb b/task-1.rb index 110f746c..edf4ef2d 100644 --- a/task-1.rb +++ b/task-1.rb @@ -47,11 +47,7 @@ def collect_stats_from_users(report, users_objects, &block) end end -def work(file_path = 'data.txt', **options) - GC.disable if options[:disable_gc] - - file_lines = File.read(file_path).split("\n") - +def split_users_and_sessions(file_lines) users = [] sessions = [] @@ -61,6 +57,30 @@ def work(file_path = 'data.txt', **options) sessions = sessions + [parse_session(line)] if cols[0] == 'session' end + [users, sessions] +end + +def initialize_users(users) + users_objects_by_id = {} + + users.each do |user| + attributes = user + user_object = User.new(**attributes) + users_objects_by_id[user_object.id] = user_object + end + + users_objects_by_id +end + +def assign_sessions_to_users(users_objects_by_id, sessions) + sessions.each do |session| + users_objects_by_id[session['user_id']].sessions << session + end +end + +def build_report(users_objects_by_id, sessions) + users = users_objects_by_id.values + # Отчёт в json # - Сколько всего юзеров + # - Сколько всего уникальных браузеров + @@ -100,18 +120,6 @@ def work(file_path = 'data.txt', **options) .join(',') # Статистика по пользователям - users_objects_by_id = {} - - users.each do |user| - attributes = user - user_object = User.new(**attributes) - users_objects_by_id[user_object.id] = user_object - end - - sessions.each do |session| - users_objects_by_id[session['user_id']].sessions << session - end - report['usersStats'] = {} users_objects = users_objects_by_id.values @@ -151,6 +159,18 @@ def work(file_path = 'data.txt', **options) { 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } end + report +end + +def work(file_path = 'data.txt', **options) + GC.disable if options[:disable_gc] + + file_lines = File.read(file_path).split("\n") + users, sessions = split_users_and_sessions(file_lines) + users_objects_by_id = initialize_users(users) + assign_sessions_to_users(users_objects_by_id, sessions) + report = build_report(users_objects_by_id, sessions) + File.write('result.json', "#{report.to_json}\n") ensure GC.enable From 4e1830d441b2d5dc04a39156a97da4510d13f38a Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 09:37:41 +0300 Subject: [PATCH 11/25] Use << in split_users_and_sessions --- case-study.md | 12 +- profiling/ruby_prof_reports/flat.txt | 70 ++- profiling/ruby_prof_reports/graph.html | 822 +++++++++++++++++-------- spec/work/performance/speed_spec.rb | 2 +- task-1.rb | 4 +- 5 files changed, 617 insertions(+), 293 deletions(-) diff --git a/case-study.md b/case-study.md index 5572db93..fc4df112 100644 --- a/case-study.md +++ b/case-study.md @@ -76,12 +76,22 @@ Array#select - единственный в программе Смотрим flat + graph. Array#each остается одним из лидеров. Прежде чем приступать к оптимизации, попробуем выделить фрагменты программы в отдельные методы, чтобы было удобнее профилировать. +После выделения методов, в graph видно, что значительный вес приходится на split_users_and_sessions: + 0.01 0.00 0.00 0.00 1/11 Object#initialize_users 66 + 0.01 0.01 0.00 0.00 1/11 Object#assign_sessions_to_users 76 + 0.16 0.01 0.00 0.16 1/11 Object#build_report 105 + 0.18 0.04 0.00 0.14 7/11 Object#collect_stats_from_users 43 + 0.22 0.19 0.00 0.03 1/11 Object#split_users_and_sessions 54 + 96.96% 40.00% 0.57 0.24 0.00 0.34 11 Array#each - как вы решили её оптимизировать - +Изменили способ пополнения массивов с `+= []` на `<<`. - как изменилась метрика + +480ms -> 245ms + - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? ### Ваша находка №X diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index df7461e5..513758bf 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,49 +1,53 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.611087 +Total: 0.600390 Sort by: self_time %self total self wait child calls name location - 40.92 0.591 0.250 0.000 0.341 11 Array#each - 26.37 0.162 0.161 0.000 0.001 10000 Array#all? - 7.97 0.123 0.049 0.000 0.075 16898 Array#map - 4.65 0.028 0.028 0.000 0.000 20001 String#split - 4.64 0.061 0.028 0.000 0.033 8464 #parse - 2.20 0.013 0.013 0.000 0.000 16928 Regexp#match - 1.61 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 1.22 0.007 0.007 0.000 0.000 8464 String#gsub! - 1.20 0.011 0.007 0.000 0.004 3073 Array#sort - 1.12 0.007 0.007 0.000 0.000 23399 String#upcase - 1.01 0.006 0.006 0.000 0.000 10752 Hash#merge - 0.98 0.006 0.006 0.000 0.000 8464 MatchData#begin + 40.28 0.580 0.242 0.000 0.338 11 Array#each + 26.88 0.162 0.161 0.000 0.001 10000 Array#all? + 8.05 0.123 0.048 0.000 0.075 16898 Array#map + 4.90 0.062 0.029 0.000 0.033 8464 #parse + 4.15 0.025 0.025 0.000 0.000 20001 String#split + 2.28 0.014 0.014 0.000 0.000 16928 Regexp#match + 1.66 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 1.18 0.007 0.007 0.000 0.000 8464 String#gsub! + 1.15 0.011 0.007 0.000 0.004 3073 Array#sort + 1.07 0.006 0.006 0.000 0.000 23399 String#upcase + 1.03 0.006 0.006 0.000 0.000 10752 Hash#merge + 1.01 0.006 0.006 0.000 0.000 8464 MatchData#begin 0.76 0.005 0.005 0.000 0.000 8464 Date#iso8601 - 0.65 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 0.63 0.004 0.004 0.000 0.000 17169 Date#<=> - 0.61 0.005 0.004 0.000 0.001 1536 Array#any? - 0.61 0.004 0.004 0.000 0.000 16928 String#to_i + 0.64 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 0.63 0.005 0.004 0.000 0.001 1536 Array#any? + 0.61 0.004 0.004 0.000 0.000 17169 Date#<=> + 0.58 0.003 0.003 0.000 0.000 16928 String#to_i 0.43 0.003 0.003 0.000 0.000 8464 String#[]= - 0.30 0.002 0.002 0.000 0.000 8464 Integer#div - 0.26 0.002 0.002 0.000 0.000 8464 MatchData#end - 0.26 0.002 0.002 0.000 0.000 1537 Array#join - 0.25 0.004 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.40 0.002 0.002 0.000 0.000 1 #write + 0.28 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.27 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.27 0.002 0.002 0.000 0.000 1537 Array#join + 0.25 0.002 0.002 0.000 0.000 8464 Integer#div 0.22 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.19 0.001 0.001 0.000 0.000 1 #read - 0.17 0.002 0.001 0.000 0.001 1536 Class#new - 0.14 0.001 0.001 0.000 0.000 1 Array#uniq - 0.13 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.18 0.002 0.001 0.000 0.001 1536 Class#new + 0.17 0.001 0.001 0.000 0.000 1 #read + 0.14 0.001 0.001 0.000 0.000 3072 Integer#to_s 0.13 0.001 0.001 0.000 0.000 3072 String#+ - 0.08 0.001 0.001 0.000 0.000 1536 Array#reverse - 0.07 0.000 0.000 0.000 0.000 1 #write - 0.07 0.000 0.000 0.000 0.000 1536 Array#max + 0.11 0.001 0.001 0.000 0.000 1 Array#uniq + 0.08 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.06 0.000 0.000 0.000 0.000 1536 Array#max 0.06 0.000 0.000 0.000 0.000 1536 Array#sum - 0.05 0.000 0.000 0.000 0.000 1539 Array#count - 0.03 0.611 0.000 0.000 0.611 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 0.00 0.611 0.000 0.000 0.611 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.00 0.176 0.000 0.000 0.176 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 - 0.00 0.000 0.000 0.000 0.000 1 Hash#values + 0.06 0.000 0.000 0.000 0.000 1539 Array#count + 0.02 0.600 0.000 0.000 0.600 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 + 0.01 0.353 0.000 0.000 0.353 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 + 0.00 0.600 0.000 0.000 0.600 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.00 0.000 0.000 0.000 0.000 2 Hash#values + 0.00 0.177 0.000 0.000 0.177 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 + 0.00 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.228 0.000 0.000 0.228 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 0.00 0.005 0.000 0.000 0.005 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize * recursively called methods diff --git a/profiling/ruby_prof_reports/graph.html b/profiling/ruby_prof_reports/graph.html index 337765df..fdb55e32 100644 --- a/profiling/ruby_prof_reports/graph.html +++ b/profiling/ruby_prof_reports/graph.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 9:02:59 AM (MSK)
+
Wednesday, October 18 at 9:30:28 AM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.5796185110229999 + 0.5890249020012561 @@ -209,10 +209,10 @@

Thread 260, Fiber: 240

100.00% 0.00% - 0.58 + 0.59 0.00 0.00 - 0.58 + 0.59 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.58 + 0.59 0.00 0.00 - 0.58 + 0.59 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.58 + 0.59 0.00 0.00 - 0.58 + 0.59 1/1 [global]# @@ -266,11 +266,11 @@

Thread 260, Fiber: 240

100.00% - 0.03% - 0.58 + 0.02% + 0.59 0.00 0.00 - 0.58 + 0.59 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 50 + 165 @@ -290,66 +290,53 @@

Thread 260, Fiber: 240

    - 0.39 - 0.20 + 0.35 0.00 - 0.19 - 4/11 - Array#each - - 58 - - - -   -   - 0.17 0.00 - 0.00 - 0.17 - 7/7 - Object#collect_stats_from_users + 0.35 + 1/1 + Object#build_report - 120 + 172     - 0.01 - 0.01 + 0.22 0.00 0.00 - 2/16898 - Array#map + 0.22 + 1/1 + Object#split_users_and_sessions - 94 + 169     + 0.01 0.00 0.00 - 0.00 - 0.00 + 0.01 1/1 - JSON::Ext::Generator::GeneratorMethods::Hash#to_json + Object#assign_sessions_to_users - 154 + 171     + 0.01 0.00 0.00 - 0.00 - 0.00 - 1/20001 - String#split + 0.01 + 1/1 + Object#initialize_users - 53 + 170 @@ -359,10 +346,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/3073 - Array#sort + 1/1 + JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 94 + 174 @@ -372,10 +359,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Array#uniq + 1/20001 + String#split - 94 + 168 @@ -388,7 +375,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#write - 154 + 174 @@ -401,7 +388,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#read - 53 + 168 @@ -411,10 +398,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1537 - Array#join + 1/1 + <Module::GC>#enable - 94 + 176 @@ -424,65 +411,65 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 - Array#count + 1/1 + <Module::GC>#disable - 81 + 166 + + + + + + + + +     + 0.01 0.00 0.00 0.00 - 0.00 - 1/1 - <Module::GC>#disable + 1/11 + Object#initialize_users - 51 + 66     + 0.01 + 0.01 0.00 0.00 - 0.00 - 0.00 - 1/1 - Hash#values + 1/11 + Object#assign_sessions_to_users - 117 + 76     + 0.16 + 0.01 0.00 - 0.00 - 0.00 - 0.00 - 1/1 - <Module::GC>#enable + 0.16 + 1/11 + Object#build_report - 156 + 105 - - - - - - - - -     - 0.17 - 0.03 + 0.18 + 0.04 0.00 0.14 7/11 @@ -494,23 +481,23 @@

Thread 260, Fiber: 240

    - 0.39 - 0.20 - 0.00 + 0.22 0.19 - 4/11 - Object#work + 0.00 + 0.03 + 1/11 + Object#split_users_and_sessions - 58 + 54 - 96.87% - 40.12% - 0.56 - 0.23 + 96.96% + 40.00% + 0.57 + 0.24 0.00 - 0.33 + 0.34 11 @@ -537,7 +524,7 @@

Thread 260, Fiber: 240

10000/10000 Array#all? - 87 + 107 @@ -550,7 +537,7 @@

Thread 260, Fiber: 240

16896/16898 Array#map - 126 + 134 @@ -563,7 +550,7 @@

Thread 260, Fiber: 240

8464/8464 Object#parse_session - 61 + 57 @@ -576,7 +563,7 @@

Thread 260, Fiber: 240

10000/20001 String#split - 59 + 55 @@ -589,7 +576,7 @@

Thread 260, Fiber: 240

3072/3073 Array#sort - 136 + 144 @@ -602,20 +589,20 @@

Thread 260, Fiber: 240

10752/10752 Hash#merge - 121 + 129     - 0.00 + 0.01 0.00 0.00 0.00 1536/1536 Array#any? - 141 + 149 @@ -628,7 +615,7 @@

Thread 260, Fiber: 240

1536/1536 Object#parse_user - 60 + 56 @@ -641,7 +628,7 @@

Thread 260, Fiber: 240

1536/1536 Class#new - 107 + 68 @@ -654,7 +641,7 @@

Thread 260, Fiber: 240

1536/1537 Array#join - 136 + 144 @@ -667,7 +654,7 @@

Thread 260, Fiber: 240

3072/3072 Integer#to_s - 126 + 134 @@ -680,7 +667,7 @@

Thread 260, Fiber: 240

3072/3072 String#+ - 126 + 134 @@ -693,7 +680,7 @@

Thread 260, Fiber: 240

1536/1536 Array#reverse - 151 + 159 @@ -706,7 +693,7 @@

Thread 260, Fiber: 240

1536/1536 Array#max - 131 + 139 @@ -719,7 +706,7 @@

Thread 260, Fiber: 240

1536/1536 Array#sum - 126 + 134 @@ -732,7 +719,7 @@

Thread 260, Fiber: 240

1536/1539 Array#count - 121 + 129 @@ -747,23 +734,230 @@

Thread 260, Fiber: 240

    - 0.17 + 0.35 + 0.00 + 0.00 + 0.35 + 1/1 + Object#work + + 172 + + + + 59.61% + 0.01% + 0.35 + 0.00 + 0.00 + 0.35 + 1 + + + Object#build_report + + + + + + 81 + + + + + + + +   +   + 0.18 0.00 0.00 - 0.17 + 0.18 7/7 + Object#collect_stats_from_users + + 128 + + + +   +   + 0.16 + 0.01 + 0.00 + 0.16 + 1/11 + Array#each + + 105 + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 2/16898 + Array#map + + 114 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/3073 + Array#sort + + 114 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + Array#uniq + + 114 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 2/2 + Hash#values + + 82 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1537 + Array#join + + 114 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 3/1539 + Array#count + + 101 + + + + + + + + + + + + +   +   + 0.22 + 0.00 + 0.00 + 0.22 + 1/1 Object#work - 120 + 169 - 29.38% + 37.50% 0.00% - 0.17 + 0.22 0.00 0.00 - 0.17 + 0.22 + 1 + + + Object#split_users_and_sessions + + + + + + 50 + + + + + + + +   +   + 0.22 + 0.19 + 0.00 + 0.03 + 1/11 + Array#each + + 54 + + + + + + + + + + + + +   +   + 0.18 + 0.00 + 0.00 + 0.18 + 7/7 + Object#build_report + + 128 + + + + 30.05% + 0.00% + 0.18 + 0.00 + 0.00 + 0.18 7 @@ -783,8 +977,8 @@

Thread 260, Fiber: 240

    - 0.17 - 0.03 + 0.18 + 0.04 0.00 0.14 7/11 @@ -816,8 +1010,8 @@

Thread 260, Fiber: 240

- 27.44% - 27.34% + 27.11% + 27.01% 0.16 0.16 0.00 @@ -848,7 +1042,7 @@

Thread 260, Fiber: 240

1979/23399 String#upcase - 146 + 154 @@ -868,9 +1062,9 @@

Thread 260, Fiber: 240

0.00 0.00 2/16898 - Object#work + Object#build_report - 94 + 114 @@ -887,8 +1081,8 @@

Thread 260, Fiber: 240

- 20.38% - 8.03% + 20.77% + 8.28% 0.12 0.05 0.00 @@ -919,7 +1113,7 @@

Thread 260, Fiber: 240

8464/8464 <Class::Date>#parse - 151 + 159 @@ -932,7 +1126,7 @@

Thread 260, Fiber: 240

16928/23399 String#upcase - 97 + 117 @@ -945,7 +1139,7 @@

Thread 260, Fiber: 240

8464/8464 Date#iso8601 - 151 + 159 @@ -958,7 +1152,7 @@

Thread 260, Fiber: 240

16928/16928 String#to_i - 126 + 134 @@ -984,8 +1178,8 @@

Thread 260, Fiber: 240

- 10.22% - 4.79% + 10.37% + 4.85% 0.06 0.03 0.00 @@ -1116,7 +1310,7 @@

Thread 260, Fiber: 240

1/20001 Object#work - 53 + 168 @@ -1146,10 +1340,10 @@

Thread 260, Fiber: 240

- 4.25% - 4.25% - 0.02 - 0.02 + 4.28% + 4.28% + 0.03 + 0.03 0.00 0.00 20001 @@ -1191,8 +1385,8 @@

Thread 260, Fiber: 240

- 3.21% - 1.69% + 3.19% + 1.65% 0.02 0.01 0.00 @@ -1249,8 +1443,8 @@

Thread 260, Fiber: 240

- 2.21% - 2.21% + 2.32% + 2.32% 0.01 0.01 0.00 @@ -1288,9 +1482,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/3073 - Object#work + Object#build_report - 94 + 114 @@ -1307,7 +1501,7 @@

Thread 260, Fiber: 240

- 1.84% + 1.83% 1.20% 0.01 0.01 @@ -1436,8 +1630,8 @@

Thread 260, Fiber: 240

- 1.08% - 1.08% + 1.10% + 1.10% 0.01 0.01 0.00 @@ -1474,23 +1668,23 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 10752/10752 + Array#each - 1.05% - 1.05% + 1.04% + 1.04% 0.01 0.01 0.00 0.00 - 8464 + 10752 - - MatchData#begin + + Hash#merge @@ -1519,8 +1713,8 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 10752/10752 - Array#each + 8464/8464 + <Class::Date>#parse @@ -1532,10 +1726,10 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 10752 + 8464 - - Hash#merge + + MatchData#begin @@ -1560,8 +1754,66 @@

Thread 260, Fiber: 240

    + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Object#work + + 171 + + + + 0.89% + 0.00% + 0.01 + 0.00 + 0.00 + 0.01 + 1 + + + Object#assign_sessions_to_users + + + + + + 75 + + + + + + + +   +   + 0.01 + 0.01 0.00 0.00 + 1/11 + Array#each + + 76 + + + + + + + + + + + + +   +   + 0.01 + 0.00 0.00 0.00 1536/1536 @@ -1571,9 +1823,9 @@

Thread 260, Fiber: 240

- 0.84% - 0.64% - 0.00 + 0.87% + 0.65% + 0.01 0.00 0.00 0.00 @@ -1603,7 +1855,65 @@

Thread 260, Fiber: 240

4492/23399 String#upcase - 141 + 149 + + + + + + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Object#work + + 170 + + + + 0.86% + 0.00% + 0.01 + 0.00 + 0.00 + 0.01 + 1 + + + Object#initialize_users + + + + + + 63 + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.00 + 1/11 + Array#each + + 66 @@ -1629,8 +1939,8 @@

Thread 260, Fiber: 240

- 0.76% - 0.76% + 0.74% + 0.74% 0.00 0.00 0.00 @@ -1670,12 +1980,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 154 + 174 - 0.69% - 0.69% + 0.65% + 0.65% 0.00 0.00 0.00 @@ -1777,8 +2087,8 @@

Thread 260, Fiber: 240

- 0.60% - 0.60% + 0.62% + 0.62% 0.00 0.00 0.00 @@ -1822,7 +2132,7 @@

Thread 260, Fiber: 240

- 0.52% + 0.53% 0.27% 0.00 0.00 @@ -1880,8 +2190,8 @@

Thread 260, Fiber: 240

- 0.43% - 0.43% + 0.44% + 0.44% 0.00 0.00 0.00 @@ -1925,8 +2235,8 @@

Thread 260, Fiber: 240

- 0.38% - 0.17% + 0.43% + 0.19% 0.00 0.00 0.00 @@ -1983,8 +2293,8 @@

Thread 260, Fiber: 240

- 0.29% - 0.29% + 0.30% + 0.30% 0.00 0.00 0.00 @@ -2021,8 +2331,21 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1/1537 + Object#build_report + + 114 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1537 + Array#each @@ -2034,10 +2357,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464 + 1537 - - MatchData#end + + Array#join @@ -2066,36 +2389,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1537 - Object#work - - 94 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1537 - Array#each + 8464/8464 + <Class::Date>#parse - 0.26% - 0.26% + 0.27% + 0.27% 0.00 0.00 0.00 0.00 - 1537 + 8464 - - Array#join + + MatchData#end @@ -2131,8 +2441,8 @@

Thread 260, Fiber: 240

- 0.21% - 0.21% + 0.24% + 0.24% 0.00 0.00 0.00 @@ -2176,8 +2486,8 @@

Thread 260, Fiber: 240

- 0.15% - 0.15% + 0.14% + 0.14% 0.00 0.00 0.00 @@ -2260,9 +2570,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - Object#work + Object#build_report - 94 + 114 @@ -2352,12 +2662,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 154 + 174 - 0.08% - 0.08% + 0.07% + 0.07% 0.00 0.00 0.00 @@ -2439,7 +2749,20 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 + 3/1539 + Object#build_report + + 101 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1539 Array#each @@ -2452,10 +2775,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536 + 1539 - - Array#sum + + Array#count @@ -2484,10 +2807,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 53 + @@ -2497,10 +2820,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1 + 1536 - - <Class::IO>#read + + Array#sum @@ -2529,36 +2852,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 + 1/1 Object#work - 81 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1539 - Array#each - - + 168 - 0.05% - 0.05% + 0.06% + 0.06% 0.00 0.00 0.00 0.00 - 1539 + 1 - - Array#count + + <Class::IO>#read @@ -2587,10 +2897,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 2/2 + Object#build_report - 51 + 82 @@ -2600,16 +2910,16 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1 + 2 - - <Module::GC>#disable + + Hash#values - 84 + @@ -2635,7 +2945,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 117 + 176 @@ -2647,14 +2957,14 @@

Thread 260, Fiber: 240

0.00 1 - - Hash#values + + <Module::GC>#enable - + 72 @@ -2680,7 +2990,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 156 + 166 @@ -2692,14 +3002,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#enable + + <Module::GC>#disable - 72 + 84 diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index 590cdf66..7e53584e 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -5,7 +5,7 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } let(:size) { 10_000 } - let(:ms) { 480 } + let(:ms) { 245 } before { ensure_test_data_exists(size) } diff --git a/task-1.rb b/task-1.rb index edf4ef2d..e5031d37 100644 --- a/task-1.rb +++ b/task-1.rb @@ -53,8 +53,8 @@ def split_users_and_sessions(file_lines) file_lines.each do |line| cols = line.split(',') - users = users + [parse_user(line)] if cols[0] == 'user' - sessions = sessions + [parse_session(line)] if cols[0] == 'session' + users << parse_user(line) if cols[0] == 'user' + sessions << parse_session(line) if cols[0] == 'session' end [users, sessions] From 22acabfcdebce12ef9a72ee490a1c8a78d88c2da Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 09:39:21 +0300 Subject: [PATCH 12/25] Updat case study --- case-study.md | 9 + profiling/ruby_prof_reports/flat.txt | 80 ++-- profiling/ruby_prof_reports/graph.html | 570 ++++++++++++------------- 3 files changed, 334 insertions(+), 325 deletions(-) diff --git a/case-study.md b/case-study.md index fc4df112..25744783 100644 --- a/case-study.md +++ b/case-study.md @@ -94,6 +94,15 @@ Array#select - единственный в программе - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? +перестала: +94.94% 14.52% 0.39 0.06 0.00 0.33 11 Array#each + + %self total self wait child calls name location + 39.45 0.161 0.161 0.000 0.001 10000 Array#all? + 14.00 0.386 0.057 0.000 0.329 11 Array#each + 11.56 0.118 0.047 0.000 0.071 16898 Array#map + 6.80 0.059 0.028 0.000 0.031 8464 #parse + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index 513758bf..bccce963 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,53 +1,53 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.600390 +Total: 0.406904 Sort by: self_time %self total self wait child calls name location - 40.28 0.580 0.242 0.000 0.338 11 Array#each - 26.88 0.162 0.161 0.000 0.001 10000 Array#all? - 8.05 0.123 0.048 0.000 0.075 16898 Array#map - 4.90 0.062 0.029 0.000 0.033 8464 #parse - 4.15 0.025 0.025 0.000 0.000 20001 String#split - 2.28 0.014 0.014 0.000 0.000 16928 Regexp#match - 1.66 0.019 0.010 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 1.18 0.007 0.007 0.000 0.000 8464 String#gsub! - 1.15 0.011 0.007 0.000 0.004 3073 Array#sort - 1.07 0.006 0.006 0.000 0.000 23399 String#upcase - 1.03 0.006 0.006 0.000 0.000 10752 Hash#merge - 1.01 0.006 0.006 0.000 0.000 8464 MatchData#begin - 0.76 0.005 0.005 0.000 0.000 8464 Date#iso8601 - 0.64 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 0.63 0.005 0.004 0.000 0.001 1536 Array#any? - 0.61 0.004 0.004 0.000 0.000 17169 Date#<=> - 0.58 0.003 0.003 0.000 0.000 16928 String#to_i - 0.43 0.003 0.003 0.000 0.000 8464 String#[]= - 0.40 0.002 0.002 0.000 0.000 1 #write - 0.28 0.002 0.002 0.000 0.000 8464 MatchData#end - 0.27 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 0.27 0.002 0.002 0.000 0.000 1537 Array#join - 0.25 0.002 0.002 0.000 0.000 8464 Integer#div - 0.22 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.18 0.002 0.001 0.000 0.001 1536 Class#new - 0.17 0.001 0.001 0.000 0.000 1 #read - 0.14 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.13 0.001 0.001 0.000 0.000 3072 String#+ - 0.11 0.001 0.001 0.000 0.000 1 Array#uniq - 0.08 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.06 0.000 0.000 0.000 0.000 1536 Array#max - 0.06 0.000 0.000 0.000 0.000 1536 Array#sum - 0.06 0.000 0.000 0.000 0.000 1539 Array#count - 0.02 0.600 0.000 0.000 0.600 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 - 0.01 0.353 0.000 0.000 0.353 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 - 0.00 0.600 0.000 0.000 0.600 1 [global]# profiling/ruby_prof_flat.rb:8 + 39.45 0.161 0.161 0.000 0.001 10000 Array#all? + 14.00 0.386 0.057 0.000 0.329 11 Array#each + 11.56 0.118 0.047 0.000 0.071 16898 Array#map + 6.80 0.059 0.028 0.000 0.031 8464 #parse + 5.63 0.023 0.023 0.000 0.000 20001 String#split + 3.13 0.013 0.013 0.000 0.000 16928 Regexp#match + 2.30 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 1.78 0.011 0.007 0.000 0.004 3073 Array#sort + 1.71 0.007 0.007 0.000 0.000 8464 String#gsub! + 1.52 0.006 0.006 0.000 0.000 23399 String#upcase + 1.43 0.006 0.006 0.000 0.000 8464 MatchData#begin + 1.43 0.006 0.006 0.000 0.000 10752 Hash#merge + 1.08 0.004 0.004 0.000 0.000 8464 Date#iso8601 + 1.03 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 0.97 0.004 0.004 0.000 0.000 17169 Date#<=> + 0.87 0.005 0.004 0.000 0.001 1536 Array#any? + 0.87 0.004 0.004 0.000 0.000 16928 String#to_i + 0.65 0.003 0.003 0.000 0.000 1 #write + 0.61 0.002 0.002 0.000 0.000 8464 String#[]= + 0.43 0.002 0.002 0.000 0.000 8464 Integer#div + 0.38 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.38 0.002 0.002 0.000 0.000 1537 Array#join + 0.36 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.31 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 0.25 0.002 0.001 0.000 0.001 1536 Class#new + 0.21 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.20 0.001 0.001 0.000 0.000 3072 String#+ + 0.16 0.001 0.001 0.000 0.000 1 Array#uniq + 0.10 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.10 0.000 0.000 0.000 0.000 1536 Array#sum + 0.09 0.000 0.000 0.000 0.000 1536 Array#max + 0.08 0.000 0.000 0.000 0.000 1 #read + 0.07 0.000 0.000 0.000 0.000 1539 Array#count + 0.04 0.407 0.000 0.000 0.407 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 + 0.01 0.346 0.000 0.000 0.346 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 + 0.00 0.407 0.000 0.000 0.407 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.00 0.170 0.000 0.000 0.170 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.00 0.000 0.000 0.000 0.000 2 Hash#values - 0.00 0.177 0.000 0.000 0.177 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.00 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 0.00 0.000 0.000 0.000 0.000 1 #enable :72 - 0.00 0.228 0.000 0.000 0.228 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 + 0.00 0.043 0.000 0.000 0.043 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 0.00 0.000 0.000 0.000 0.000 1 #disable :84 - 0.00 0.005 0.000 0.000 0.005 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 + 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize * recursively called methods diff --git a/profiling/ruby_prof_reports/graph.html b/profiling/ruby_prof_reports/graph.html index fdb55e32..81c2c968 100644 --- a/profiling/ruby_prof_reports/graph.html +++ b/profiling/ruby_prof_reports/graph.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 9:30:28 AM (MSK)
+
Wednesday, October 18 at 9:37:59 AM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.5890249020012561 + 0.4150142199941911 @@ -209,10 +209,10 @@

Thread 260, Fiber: 240

100.00% 0.00% - 0.59 + 0.42 0.00 0.00 - 0.59 + 0.42 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.59 + 0.42 0.00 0.00 - 0.59 + 0.41 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.59 + 0.42 0.00 0.00 - 0.59 + 0.41 1/1 [global]# @@ -266,11 +266,11 @@

Thread 260, Fiber: 240

100.00% - 0.02% - 0.59 + 0.03% + 0.42 0.00 0.00 - 0.59 + 0.41 1 @@ -303,10 +303,10 @@

Thread 260, Fiber: 240

    - 0.22 + 0.04 0.00 0.00 - 0.22 + 0.04 1/1 Object#split_users_and_sessions @@ -329,10 +329,10 @@

Thread 260, Fiber: 240

    - 0.01 0.00 0.00 - 0.01 + 0.00 + 0.00 1/1 Object#initialize_users @@ -359,10 +359,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/20001 - String#split + 1/1 + <Class::IO>#write - 168 + 174 @@ -372,10 +372,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - <Class::IO>#write + 1/20001 + String#split - 174 + 168 @@ -429,7 +429,7 @@

Thread 260, Fiber: 240

    - 0.01 + 0.00 0.00 0.00 0.00 @@ -452,6 +452,19 @@

Thread 260, Fiber: 240

76 + +   +   + 0.04 + 0.01 + 0.00 + 0.03 + 1/11 + Object#split_users_and_sessions + + 54 + +     @@ -478,26 +491,13 @@

Thread 260, Fiber: 240

43 - -   -   - 0.22 - 0.19 - 0.00 - 0.03 - 1/11 - Object#split_users_and_sessions - - 54 - - - 96.96% - 40.00% - 0.57 - 0.24 + 94.94% + 14.52% + 0.39 + 0.06 0.00 - 0.34 + 0.33 11 @@ -595,7 +595,7 @@

Thread 260, Fiber: 240

    - 0.01 + 0.00 0.00 0.00 0.00 @@ -745,7 +745,7 @@

Thread 260, Fiber: 240

- 59.61% + 84.77% 0.01% 0.35 0.00 @@ -878,64 +878,6 @@

Thread 260, Fiber: 240

- - - -   -   - 0.22 - 0.00 - 0.00 - 0.22 - 1/1 - Object#work - - 169 - - - - 37.50% - 0.00% - 0.22 - 0.00 - 0.00 - 0.22 - 1 - - - Object#split_users_and_sessions - - - - - - 50 - - - - - - - -   -   - 0.22 - 0.19 - 0.00 - 0.03 - 1/11 - Array#each - - 54 - - - - - - - - - @@ -952,7 +894,7 @@

Thread 260, Fiber: 240

- 30.05% + 42.69% 0.00% 0.18 0.00 @@ -1010,8 +952,8 @@

Thread 260, Fiber: 240

- 27.11% - 27.01% + 38.48% + 38.35% 0.16 0.16 0.00 @@ -1081,8 +1023,8 @@

Thread 260, Fiber: 240

- 20.77% - 8.28% + 29.69% + 11.68% 0.12 0.05 0.00 @@ -1123,10 +1065,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 16928/23399 - String#upcase + 8464/8464 + Date#iso8601 - 117 + 159 @@ -1136,10 +1078,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - Date#iso8601 + 16928/23399 + String#upcase - 159 + 117 @@ -1178,8 +1120,8 @@

Thread 260, Fiber: 240

- 10.37% - 4.85% + 14.90% + 6.96% 0.06 0.03 0.00 @@ -1285,6 +1227,64 @@

Thread 260, Fiber: 240

+ + + +   +   + 0.04 + 0.00 + 0.00 + 0.04 + 1/1 + Object#work + + 169 + + + + 10.49% + 0.00% + 0.04 + 0.00 + 0.00 + 0.04 + 1 + + + Object#split_users_and_sessions + + + + + + 50 + + + + + + + +   +   + 0.04 + 0.01 + 0.00 + 0.03 + 1/11 + Array#each + + 54 + + + + + + + + + @@ -1340,10 +1340,10 @@

Thread 260, Fiber: 240

- 4.28% - 4.28% - 0.03 - 0.03 + 5.63% + 5.63% + 0.02 + 0.02 0.00 0.00 20001 @@ -1385,8 +1385,8 @@

Thread 260, Fiber: 240

- 3.19% - 1.65% + 4.48% + 2.29% 0.02 0.01 0.00 @@ -1443,8 +1443,8 @@

Thread 260, Fiber: 240

- 2.32% - 2.32% + 3.22% + 3.22% 0.01 0.01 0.00 @@ -1501,8 +1501,8 @@

Thread 260, Fiber: 240

+ 2.70% 1.83% - 1.20% 0.01 0.01 0.00 @@ -1559,8 +1559,8 @@

Thread 260, Fiber: 240

- 1.18% - 1.18% + 1.78% + 1.78% 0.01 0.01 0.00 @@ -1630,8 +1630,8 @@

Thread 260, Fiber: 240

- 1.10% - 1.10% + 1.53% + 1.53% 0.01 0.01 0.00 @@ -1668,23 +1668,23 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 10752/10752 - Array#each + 8464/8464 + <Class::Date>#parse - 1.04% - 1.04% + 1.51% + 1.51% 0.01 0.01 0.00 0.00 - 10752 + 8464 - - Hash#merge + + MatchData#begin @@ -1713,23 +1713,23 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 10752/10752 + Array#each - 1.02% - 1.02% + 1.41% + 1.41% 0.01 0.01 0.00 0.00 - 8464 + 10752 - - MatchData#begin + + Hash#merge @@ -1765,7 +1765,7 @@

Thread 260, Fiber: 240

- 0.89% + 1.35% 0.00% 0.01 0.00 @@ -1812,7 +1812,7 @@

Thread 260, Fiber: 240

    - 0.01 + 0.00 0.00 0.00 0.00 @@ -1823,9 +1823,9 @@

Thread 260, Fiber: 240

+ 1.16% 0.87% - 0.65% - 0.01 + 0.00 0.00 0.00 0.00 @@ -1870,52 +1870,39 @@

Thread 260, Fiber: 240

    - 0.01 0.00 0.00 - 0.01 - 1/1 - Object#work + 0.00 + 0.00 + 8464/8464 + Array#map - 170 + - 0.86% - 0.00% - 0.01 + 1.14% + 1.14% 0.00 0.00 - 0.01 - 1 + 0.00 + 0.00 + 8464 - - Object#initialize_users + + Date#iso8601 - 63 + - -   -   - 0.01 - 0.00 - 0.00 - 0.00 - 1/11 - Array#each - - 66 - - @@ -1932,35 +1919,48 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - Array#map + 1/1 + Object#work - + 170 - 0.74% - 0.74% + 1.13% + 0.00% 0.00 0.00 0.00 0.00 - 8464 + 1 - - Date#iso8601 + + Object#initialize_users - + 63 + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/11 + Array#each + + 66 + + @@ -1984,8 +1984,8 @@

Thread 260, Fiber: 240

- 0.65% - 0.65% + 0.89% + 0.89% 0.00 0.00 0.00 @@ -2042,8 +2042,8 @@

Thread 260, Fiber: 240

- 0.63% - 0.63% + 0.87% + 0.87% 0.00 0.00 0.00 @@ -2087,8 +2087,8 @@

Thread 260, Fiber: 240

- 0.62% - 0.62% + 0.86% + 0.86% 0.00 0.00 0.00 @@ -2107,6 +2107,51 @@

Thread 260, Fiber: 240

+ + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + Object#work + + 174 + + + + 0.75% + 0.75% + 0.00 + 0.00 + 0.00 + 0.00 + 1 + + + <Class::IO>#write + + + + + + + + + + @@ -2132,8 +2177,8 @@

Thread 260, Fiber: 240

- 0.53% - 0.27% + 0.72% + 0.38% 0.00 0.00 0.00 @@ -2190,8 +2235,8 @@

Thread 260, Fiber: 240

- 0.44% - 0.44% + 0.64% + 0.64% 0.00 0.00 0.00 @@ -2235,8 +2280,8 @@

Thread 260, Fiber: 240

- 0.43% - 0.19% + 0.57% + 0.26% 0.00 0.00 0.00 @@ -2293,8 +2338,8 @@

Thread 260, Fiber: 240

- 0.30% - 0.30% + 0.42% + 0.42% 0.00 0.00 0.00 @@ -2351,8 +2396,8 @@

Thread 260, Fiber: 240

- 0.27% - 0.27% + 0.41% + 0.41% 0.00 0.00 0.00 @@ -2396,8 +2441,8 @@

Thread 260, Fiber: 240

- 0.27% - 0.27% + 0.36% + 0.36% 0.00 0.00 0.00 @@ -2441,8 +2486,8 @@

Thread 260, Fiber: 240

- 0.24% - 0.24% + 0.31% + 0.31% 0.00 0.00 0.00 @@ -2486,8 +2531,8 @@

Thread 260, Fiber: 240

- 0.14% - 0.14% + 0.21% + 0.21% 0.00 0.00 0.00 @@ -2531,8 +2576,8 @@

Thread 260, Fiber: 240

- 0.14% - 0.14% + 0.20% + 0.20% 0.00 0.00 0.00 @@ -2576,8 +2621,8 @@

Thread 260, Fiber: 240

- 0.11% - 0.11% + 0.16% + 0.16% 0.00 0.00 0.00 @@ -2621,8 +2666,8 @@

Thread 260, Fiber: 240

- 0.09% - 0.09% + 0.12% + 0.12% 0.00 0.00 0.00 @@ -2659,23 +2704,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 174 + - 0.07% - 0.07% + 0.10% + 0.10% 0.00 0.00 0.00 0.00 - 1 + 1536 - - <Class::IO>#write + + Array#max @@ -2711,16 +2756,16 @@

Thread 260, Fiber: 240

- 0.06% - 0.06% + 0.09% + 0.09% 0.00 0.00 0.00 0.00 1536 - - Array#max + + Array#sum @@ -2749,36 +2794,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 - Object#build_report - - 101 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1539 - Array#each + 1/1 + Object#work - + 168 - 0.06% - 0.06% + 0.09% + 0.09% 0.00 0.00 0.00 0.00 - 1539 + 1 - - Array#count + + <Class::IO>#read @@ -2807,44 +2839,12 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 3/1539 + Object#build_report - + 101 - - 0.06% - 0.06% - 0.00 - 0.00 - 0.00 - 0.00 - 1536 - - - Array#sum - - - - - - - - - - - - - - - - - - - - -     @@ -2852,23 +2852,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1539 + Array#each - 168 + - 0.06% - 0.06% + 0.08% + 0.08% 0.00 0.00 0.00 0.00 - 1 + 1539 - - <Class::IO>#read + + Array#count @@ -2904,8 +2904,8 @@

Thread 260, Fiber: 240

- 0.00% - 0.00% + 0.01% + 0.01% 0.00 0.00 0.00 From 7920b4c1285f31d993f1d0f6b547847dee47686c Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 09:54:19 +0300 Subject: [PATCH 13/25] Use #uniq to count unique browsers --- case-study.md | 22 + profiling/ruby_prof_callgrind.rb | 12 + profiling/ruby_prof_callstack.rb | 13 + .../ruby_prof_reports/callgrind.out.59703 | 402 +++ profiling/ruby_prof_reports/callstack.html | 3107 +++++++++++++++++ profiling/ruby_prof_reports/flat.txt | 86 +- task-1.rb | 7 +- 7 files changed, 3600 insertions(+), 49 deletions(-) create mode 100644 profiling/ruby_prof_callgrind.rb create mode 100644 profiling/ruby_prof_callstack.rb create mode 100644 profiling/ruby_prof_reports/callgrind.out.59703 create mode 100644 profiling/ruby_prof_reports/callstack.html diff --git a/case-study.md b/case-study.md index 25744783..43188b83 100644 --- a/case-study.md +++ b/case-study.md @@ -103,6 +103,28 @@ Array#select - единственный в программе 11.56 0.118 0.047 0.000 0.071 16898 Array#map 6.80 0.059 0.028 0.000 0.031 8464 #parse +### Ваша находка №X +- какой отчёт показал главную точку роста + +flat + +- как вы решили её оптимизировать + +Осуществлять поиск кол-ва никальных браузеров с помощью uniq + +- как изменилась метрика + +245ms -> 180 + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +перестала: + + %self total self wait child calls name location + 21.41 0.234 0.055 0.000 0.179 10 Array#each + 19.68 0.127 0.050 0.000 0.076 16899 Array#map + 11.45 0.063 0.029 0.000 0.034 8464 #parse + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/ruby_prof_callgrind.rb b/profiling/ruby_prof_callgrind.rb new file mode 100644 index 00000000..4dea1666 --- /dev/null +++ b/profiling/ruby_prof_callgrind.rb @@ -0,0 +1,12 @@ +require_relative 'setup' + +# RubyProf CallGrind report +# ruby 15-ruby-prof-callgrind.rb +# brew install qcachegrind +# qcachegrind ruby_prof_reports/... + +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile { work(Setup::FILE_PATH, disable_gc: true) } +printer4 = RubyProf::CallTreePrinter.new(result) +printer4.print(:path => Setup::REPORTS_PATH, :profile => 'callgrind') diff --git a/profiling/ruby_prof_callstack.rb b/profiling/ruby_prof_callstack.rb new file mode 100644 index 00000000..4b9ba34a --- /dev/null +++ b/profiling/ruby_prof_callstack.rb @@ -0,0 +1,13 @@ +require_relative 'setup' + +# RubyProf CallStack report +# ruby 14-ruby-prof-callstack.rb +# open ruby_prof_reports/callstack.html +RubyProf.measure_mode = RubyProf::WALL_TIME + +result = RubyProf.profile { work(Setup::FILE_PATH, disable_gc: true) } +printer = RubyProf::GraphHtmlPrinter.new(result) +file_path = File.join(Setup::REPORTS_PATH, 'callstack.html') +printer.print(File.open(file_path, 'w+')) + +# не заметил разницы с graph diff --git a/profiling/ruby_prof_reports/callgrind.out.59703 b/profiling/ruby_prof_reports/callgrind.out.59703 new file mode 100644 index 00000000..d09654fe --- /dev/null +++ b/profiling/ruby_prof_reports/callgrind.out.59703 @@ -0,0 +1,402 @@ +events: wall_time + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +fn=GC::enable^ +72 5 + +fl= +fn=IO::write^ +0 574 + +fl= +fn=JSON/Ext/Generator/State::initialize +0 1 + +fl= +fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +0 3645 +cfl= +cfn=JSON/Ext/Generator/State::initialize +calls=1 0 +0 1 + +fl= +fn=Date::iso8601 +0 4549 + +fl= +fn=Array::reverse +0 488 + +fl= +fn=Date::<=> +0 3371 + +fl= +fn=Integer::div +0 1716 + +fl= +fn=String::[]= +0 2640 + +fl= +fn=MatchData::end +0 1454 + +fl= +fn=MatchData::begin +0 6146 + +fl= +fn=Regexp::match +0 13076 + +fl= +fn=String::gsub! +0 7083 + +fl= +fn=Date::parse^ +0 27793 +cfl= +cfn=String::gsub! +calls=8464 0 +0 7083 +cfl= +cfn=Regexp::match +calls=16928 0 +0 13076 +cfl= +cfn=MatchData::begin +calls=8464 0 +0 6146 +cfl= +cfn=MatchData::end +calls=8464 0 +0 1454 +cfl= +cfn=String::[]= +calls=8464 0 +0 2640 +cfl= +cfn=Integer::div +calls=8464 0 +0 1716 + +fl= +fn=Array::any? +0 3744 +cfl= +cfn=String::upcase +calls=4492 149 +149 1275 + +fl= +fn=Array::max +0 385 + +fl= +fn=String::+ +0 893 + +fl= +fn=Integer::to_s +0 843 + +fl= +fn=Array::sum +0 338 + +fl= +fn=String::to_i +0 3505 + +fl= +fn=Hash::merge +0 5716 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +42 12 +cfl= +cfn=Array::each +calls=7 43 +43 170641 + +fl= +fn=Array::join +0 1612 + +fl= +fn=Array::uniq +0 643 + +fl= +fn=Array::sort +0 7044 +cfl= +cfn=Date::<=> +calls=17169 0 +0 3371 + +fl= +fn=String::upcase +0 6560 + +fl= +fn=Array::map +0 46801 +cfl= +cfn=String::upcase +calls=16928 117 +117 4732 +cfl= +cfn=String::to_i +calls=16928 134 +134 3505 +cfl= +cfn=Date::parse^ +calls=8464 159 +159 59908 +cfl= +cfn=Date::iso8601 +calls=8464 159 +159 4549 + +fl= +fn=Array::all? +0 162413 +cfl= +cfn=String::upcase +calls=1979 154 +154 554 + +fl= +fn=Array::count +0 296 + +fl= +fn=Hash::values +0 16 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::build_report +81 44 +cfl= +cfn=Hash::values +calls=2 82 +82 16 +cfl= +cfn=Array::count +calls=3 101 +101 3 +cfl= +cfn=Array::each +calls=1 105 +105 166652 +cfl= +cfn=Array::map +calls=2 114 +114 9288 +cfl= +cfn=Array::sort +calls=1 114 +114 1528 +cfl= +cfn=Array::uniq +calls=1 114 +114 643 +cfl= +cfn=Array::join +calls=1 114 +114 21 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=7 128 +128 170653 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::assign_sessions_to_users +75 4 +cfl= +cfn=Array::each +calls=1 76 +76 4570 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=User::initialize +12 1319 + +fl= +fn=Class::new +0 1071 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=1536 0 +0 1319 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::initialize_users +63 8 +cfl= +cfn=Array::each +calls=1 66 +66 4673 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_session +31 9378 +cfl= +cfn=String::split +calls=8464 32 +32 9230 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_user +21 1600 +cfl= +cfn=String::split +calls=1536 22 +22 1485 + +fl= +fn=Array::each +0 57948 +cfl= +cfn=String::split +calls=10000 55 +55 11029 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=1536 56 +56 3085 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=8464 57 +57 18608 +cfl= +cfn=Class::new +calls=1536 68 +68 2390 +cfl= +cfn=Array::all? +calls=10000 107 +107 162967 +cfl= +cfn=Array::count +calls=1536 129 +129 293 +cfl= +cfn=Hash::merge +calls=10752 129 +129 5716 +cfl= +cfn=Array::map +calls=16896 134 +134 110206 +cfl= +cfn=Array::sum +calls=1536 134 +134 338 +cfl= +cfn=Integer::to_s +calls=3072 134 +134 843 +cfl= +cfn=String::+ +calls=3072 134 +134 893 +cfl= +cfn=Array::max +calls=1536 139 +139 385 +cfl= +cfn=Array::sort +calls=3072 144 +144 8887 +cfl= +cfn=Array::join +calls=1536 144 +144 1592 +cfl= +cfn=Array::any? +calls=1536 149 +149 5019 +cfl= +cfn=Array::reverse +calls=1536 159 +159 488 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::split_users_and_sessions +50 7 +cfl= +cfn=Array::each +calls=1 54 +54 44152 + +fl= +fn=String::split +0 23742 + +fl= +fn=IO::read^ +0 387 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +fn=GC::disable^ +84 4 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::work +165 117 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::disable^ +calls=1 166 +166 4 +cfl= +cfn=IO::read^ +calls=1 168 +168 387 +cfl= +cfn=String::split +calls=1 168 +168 1998 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::split_users_and_sessions +calls=1 169 +169 44159 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::initialize_users +calls=1 170 +170 4681 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::assign_sessions_to_users +calls=1 171 +171 4574 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::build_report +calls=1 172 +172 348848 +cfl= +cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +calls=1 174 +174 3646 +cfl= +cfn=IO::write^ +calls=1 174 +174 574 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::enable^ +calls=1 176 +176 5 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb +fn=[global]:: +10 14 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 10 +10 408992 + diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html new file mode 100644 index 00000000..447492dd --- /dev/null +++ b/profiling/ruby_prof_reports/callstack.html @@ -0,0 +1,3107 @@ + + + + + + +
+
+
+
Profile Report
+

Wall_time

+
+
+
Wednesday, October 18 at 9:44:09 AM (MSK)
+ +
+
+
+
+ + + + + + + + + + + + + +
Thread IDFiber IDTotal
2602400.4151799130195286
+ + + +

Thread 260, Fiber: 240

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
%Total%SelfTotalSelfWaitChildCallsNameLine
100.00%0.00%0.420.000.000.421 + + [global]# + + 8
  0.420.000.000.421/1Object#work8 +
  0.420.000.000.421/1[global]#8
100.00%0.04%0.420.000.000.421 + + Object#work + + 165
  0.350.000.000.351/1Object#build_report172 +
  0.040.000.000.041/1Object#split_users_and_sessions169 +
  0.010.000.000.011/1Object#assign_sessions_to_users171 +
  0.000.000.000.001/1Object#initialize_users170 +
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json174 +
  0.000.000.000.001/1<Class::IO>#write174 +
  0.000.000.000.001/20001String#split168 +
  0.000.000.000.001/1<Class::IO>#read168 +
  0.000.000.000.001/1<Module::GC>#enable176 +
  0.000.000.000.001/1<Module::GC>#disable166 +
  0.000.000.000.001/11Object#initialize_users66
  0.010.010.000.001/11Object#assign_sessions_to_users76
  0.040.010.000.031/11Object#split_users_and_sessions54
  0.170.010.000.161/11Object#build_report105
  0.170.030.000.147/11Object#collect_stats_from_users43
94.82%14.77%0.390.060.000.3311 + + Array#each + +
  0.160.160.000.0010000/10000Array#all?107 +
  0.110.040.000.0716896/16898Array#map134 +
  0.020.010.000.018464/8464Object#parse_session57 +
  0.010.010.000.0010000/20001String#split55 +
  0.010.010.000.003072/3073Array#sort144 +
  0.010.010.000.0010752/10752Hash#merge129 +
  0.010.000.000.001536/1536Array#any?149 +
  0.000.000.000.001536/1536Object#parse_user56 +
  0.000.000.000.001536/1536Class#new68 +
  0.000.000.000.001536/1537Array#join144 +
  0.000.000.000.003072/3072Integer#to_s134 +
  0.000.000.000.003072/3072String#+134 +
  0.000.000.000.001536/1536Array#reverse159 +
  0.000.000.000.001536/1536Array#max139 +
  0.000.000.000.001536/1536Array#sum134 +
  0.000.000.000.001536/1539Array#count129 +
  0.350.000.000.351/1Object#work172
84.36%0.01%0.350.000.000.351 + + Object#build_report + + 81
  0.170.000.000.177/7Object#collect_stats_from_users128 +
  0.170.010.000.161/11Array#each105 +
  0.010.010.000.002/16898Array#map114 +
  0.000.000.000.001/3073Array#sort114 +
  0.000.000.000.001/1Array#uniq114 +
  0.000.000.000.001/1537Array#join114 +
  0.000.000.000.002/2Hash#values82 +
  0.000.000.000.003/1539Array#count101 +
  0.170.000.000.177/7Object#build_report128
41.66%0.00%0.170.000.000.177 + + Object#collect_stats_from_users + + 42
  0.170.030.000.147/11Array#each43 +
  0.160.160.000.0010000/10000Array#each
39.15%39.00%0.160.160.000.0010000 + + Array#all? + +
  0.000.000.000.001979/23399String#upcase154 +
  0.010.010.000.002/16898Object#build_report114
  0.110.040.000.0716896/16898Array#each
28.98%11.53%0.120.050.000.0716898 + + Array#map + +
  0.060.030.000.038464/8464<Class::Date>#parse159 +
  0.000.000.000.0016928/23399String#upcase117 +
  0.000.000.000.008464/8464Date#iso8601159 +
  0.000.000.000.0016928/16928String#to_i134 +
  0.060.030.000.038464/8464Array#map
14.39%6.79%0.060.030.000.038464 + + <Class::Date>#parse + +
  0.010.010.000.0016928/16928Regexp#match +
  0.010.010.000.008464/8464String#gsub! +
  0.010.010.000.008464/8464MatchData#begin +
  0.000.000.000.008464/8464String#[]= +
  0.000.000.000.008464/8464Integer#div +
  0.000.000.000.008464/8464MatchData#end +
  0.040.000.000.041/1Object#work169
10.10%0.00%0.040.000.000.041 + + Object#split_users_and_sessions + + 50
  0.040.010.000.031/11Array#each54 +
  0.000.000.000.001536/20001Object#parse_user22
  0.000.000.000.001/20001Object#work168
  0.010.010.000.008464/20001Object#parse_session32
  0.010.010.000.0010000/20001Array#each
5.55%5.55%0.020.020.000.0020001 + + String#split + +
  0.020.010.000.018464/8464Array#each
4.27%2.19%0.020.010.000.018464 + + Object#parse_session + + 31
  0.010.010.000.008464/20001String#split32 +
  0.010.010.000.0016928/16928<Class::Date>#parse
3.10%3.10%0.010.010.000.0016928 + + Regexp#match + +
  0.000.000.000.001/3073Object#build_report114
  0.010.010.000.003072/3073Array#each
2.55%1.71%0.010.010.000.003073 + + Array#sort + +
  0.000.000.000.0017169/17169Date#<=> +
  0.010.000.000.011/1Object#work171
2.01%0.00%0.010.000.000.011 + + Object#assign_sessions_to_users + + 75
  0.010.010.000.001/11Array#each76 +
  0.010.010.000.008464/8464<Class::Date>#parse
1.66%1.66%0.010.010.000.008464 + + String#gsub! + +
  0.000.000.000.001979/23399Array#all?
  0.000.000.000.004492/23399Array#any?
  0.000.000.000.0016928/23399Array#map
1.61%1.61%0.010.010.000.0023399 + + String#upcase + +
  0.010.010.000.0010752/10752Array#each
1.42%1.42%0.010.010.000.0010752 + + Hash#merge + +
  0.010.010.000.008464/8464<Class::Date>#parse
1.41%1.41%0.010.010.000.008464 + + MatchData#begin + +
  0.010.000.000.001536/1536Array#each
1.30%0.97%0.010.000.000.001536 + + Array#any? + +
  0.000.000.000.004492/23399String#upcase149 +
  0.000.000.000.001/1Object#work170
1.09%0.00%0.000.000.000.001 + + Object#initialize_users + + 63
  0.000.000.000.001/11Array#each66 +
  0.000.000.000.008464/8464Array#map
1.09%1.09%0.000.000.000.008464 + + Date#iso8601 + +
  0.000.000.000.001/1Object#work174
0.90%0.89%0.000.000.000.001 + + JSON::Ext::Generator::GeneratorMethods::Hash#to_json + +
  0.000.000.000.001/1JSON::Ext::Generator::State#initialize +
  0.000.000.000.0016928/16928Array#map
0.85%0.85%0.000.000.000.0016928 + + String#to_i + +
  0.000.000.000.0017169/17169Array#sort
0.84%0.84%0.000.000.000.0017169 + + Date#<=> + +
  0.000.000.000.001536/1536Array#each
0.70%0.37%0.000.000.000.001536 + + Object#parse_user + + 21
  0.000.000.000.001536/20001String#split22 +
  0.000.000.000.008464/8464<Class::Date>#parse
0.67%0.67%0.000.000.000.008464 + + String#[]= + +
  0.000.000.000.001/1Object#work174
0.63%0.63%0.000.000.000.001 + + <Class::IO>#write + +
  0.000.000.000.001536/1536Array#each
0.56%0.25%0.000.000.000.001536 + + Class#new + +
  0.000.000.000.001536/1536User#initialize +
  0.000.000.000.008464/8464<Class::Date>#parse
0.39%0.39%0.000.000.000.008464 + + Integer#div + +
  0.000.000.000.001/1537Object#build_report114
  0.000.000.000.001536/1537Array#each
0.38%0.38%0.000.000.000.001537 + + Array#join + +
  0.000.000.000.008464/8464<Class::Date>#parse
0.36%0.36%0.000.000.000.008464 + + MatchData#end + +
  0.000.000.000.001536/1536Class#new
0.31%0.31%0.000.000.000.001536 + + User#initialize + + 12
  0.000.000.000.001/1Object#work168
0.26%0.26%0.000.000.000.001 + + <Class::IO>#read + +
  0.000.000.000.003072/3072Array#each
0.21%0.21%0.000.000.000.003072 + + Integer#to_s + +
  0.000.000.000.003072/3072Array#each
0.19%0.19%0.000.000.000.003072 + + String#+ + +
  0.000.000.000.001/1Object#build_report114
0.16%0.16%0.000.000.000.001 + + Array#uniq + +
  0.000.000.000.001536/1536Array#each
0.11%0.11%0.000.000.000.001536 + + Array#reverse + +
  0.000.000.000.001536/1536Array#each
0.09%0.09%0.000.000.000.001536 + + Array#max + +
  0.000.000.000.001536/1536Array#each
0.09%0.09%0.000.000.000.001536 + + Array#sum + +
  0.000.000.000.003/1539Object#build_report101
  0.000.000.000.001536/1539Array#each
0.08%0.08%0.000.000.000.001539 + + Array#count + +
  0.000.000.000.002/2Object#build_report82
0.00%0.00%0.000.000.000.002 + + Hash#values + +
  0.000.000.000.001/1Object#work176
0.00%0.00%0.000.000.000.001 + + <Module::GC>#enable + + 72
  0.000.000.000.001/1Object#work166
0.00%0.00%0.000.000.000.001 + + <Module::GC>#disable + + 84
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json
0.00%0.00%0.000.000.000.001 + + JSON::Ext::Generator::State#initialize + +
* indicates recursively called methods
+ +
+ + + + diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index bccce963..be5c7548 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,53 +1,53 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.406904 +Total: 0.256290 Sort by: self_time %self total self wait child calls name location - 39.45 0.161 0.161 0.000 0.001 10000 Array#all? - 14.00 0.386 0.057 0.000 0.329 11 Array#each - 11.56 0.118 0.047 0.000 0.071 16898 Array#map - 6.80 0.059 0.028 0.000 0.031 8464 #parse - 5.63 0.023 0.023 0.000 0.000 20001 String#split - 3.13 0.013 0.013 0.000 0.000 16928 Regexp#match - 2.30 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 1.78 0.011 0.007 0.000 0.004 3073 Array#sort - 1.71 0.007 0.007 0.000 0.000 8464 String#gsub! - 1.52 0.006 0.006 0.000 0.000 23399 String#upcase - 1.43 0.006 0.006 0.000 0.000 8464 MatchData#begin - 1.43 0.006 0.006 0.000 0.000 10752 Hash#merge - 1.08 0.004 0.004 0.000 0.000 8464 Date#iso8601 - 1.03 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 0.97 0.004 0.004 0.000 0.000 17169 Date#<=> - 0.87 0.005 0.004 0.000 0.001 1536 Array#any? - 0.87 0.004 0.004 0.000 0.000 16928 String#to_i - 0.65 0.003 0.003 0.000 0.000 1 #write - 0.61 0.002 0.002 0.000 0.000 8464 String#[]= - 0.43 0.002 0.002 0.000 0.000 8464 Integer#div - 0.38 0.002 0.002 0.000 0.000 8464 MatchData#end - 0.38 0.002 0.002 0.000 0.000 1537 Array#join - 0.36 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 0.31 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.25 0.002 0.001 0.000 0.001 1536 Class#new - 0.21 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.20 0.001 0.001 0.000 0.000 3072 String#+ - 0.16 0.001 0.001 0.000 0.000 1 Array#uniq - 0.10 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.10 0.000 0.000 0.000 0.000 1536 Array#sum - 0.09 0.000 0.000 0.000 0.000 1536 Array#max - 0.08 0.000 0.000 0.000 0.000 1 #read - 0.07 0.000 0.000 0.000 0.000 1539 Array#count - 0.04 0.407 0.000 0.000 0.407 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 - 0.01 0.346 0.000 0.000 0.346 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 - 0.00 0.407 0.000 0.000 0.407 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.00 0.170 0.000 0.000 0.170 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 - 0.00 0.000 0.000 0.000 0.000 2 Hash#values - 0.00 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 - 0.00 0.000 0.000 0.000 0.000 1 #enable :72 - 0.00 0.043 0.000 0.000 0.043 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 21.41 0.234 0.055 0.000 0.179 10 Array#each + 19.68 0.127 0.050 0.000 0.076 16899 Array#map + 11.45 0.063 0.029 0.000 0.034 8464 #parse + 9.35 0.024 0.024 0.000 0.000 20001 String#split + 5.29 0.014 0.014 0.000 0.000 16928 Regexp#match + 3.67 0.019 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 3.05 0.011 0.008 0.000 0.004 3073 Array#sort + 2.92 0.007 0.007 0.000 0.000 8464 String#gsub! + 2.46 0.006 0.006 0.000 0.000 8464 MatchData#begin + 2.45 0.006 0.006 0.000 0.000 23399 String#upcase + 2.34 0.006 0.006 0.000 0.000 10752 Hash#merge + 2.02 0.005 0.005 0.000 0.000 8464 Date#iso8601 + 1.51 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 1.48 0.004 0.004 0.000 0.000 16928 String#to_i + 1.48 0.005 0.004 0.000 0.001 1536 Array#any? + 1.43 0.004 0.004 0.000 0.000 17169 Date#<=> + 1.09 0.003 0.003 0.000 0.000 8464 String#[]= + 0.73 0.002 0.002 0.000 0.001 1536 Array#all? + 0.70 0.002 0.002 0.000 0.000 2 Array#uniq + 0.67 0.002 0.002 0.000 0.000 8464 MatchData#end + 0.66 0.002 0.002 0.000 0.000 1537 Array#join + 0.66 0.002 0.002 0.000 0.000 8464 Integer#div + 0.61 0.003 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.54 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 0.45 0.003 0.001 0.000 0.001 1536 Class#new + 0.35 0.001 0.001 0.000 0.000 1 #write + 0.34 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.30 0.001 0.001 0.000 0.000 3072 String#+ + 0.22 0.001 0.001 0.000 0.000 1536 Array#reverse + 0.16 0.000 0.000 0.000 0.000 1536 Array#max + 0.15 0.000 0.000 0.000 0.000 1 #read + 0.15 0.000 0.000 0.000 0.000 1536 Array#sum + 0.13 0.000 0.000 0.000 0.000 1539 Array#count + 0.04 0.256 0.000 0.000 0.256 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 + 0.03 0.195 0.000 0.000 0.195 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 + 0.01 0.256 0.000 0.000 0.256 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.01 0.000 0.000 0.000 0.000 2 Hash#values + 0.01 0.180 0.000 0.000 0.180 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 + 0.00 0.044 0.000 0.000 0.044 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 + 0.00 0.006 0.000 0.000 0.006 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 + 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 0.00 0.000 0.000 0.000 0.000 1 #enable :72 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize * recursively called methods diff --git a/task-1.rb b/task-1.rb index e5031d37..fa270051 100644 --- a/task-1.rb +++ b/task-1.rb @@ -101,12 +101,7 @@ def build_report(users_objects_by_id, sessions) report[:totalUsers] = users.count # Подсчёт количества уникальных браузеров - uniqueBrowsers = [] - sessions.each do |session| - browser = session['browser'] - uniqueBrowsers += [browser] if uniqueBrowsers.all? { |b| b != browser } - end - + uniqueBrowsers = sessions.map { |s| s['browser'] }.uniq report['uniqueBrowsersCount'] = uniqueBrowsers.count report['totalSessions'] = sessions.count From f062fd4b514b400451be6d48d483870e243855b8 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 10:00:06 +0300 Subject: [PATCH 14/25] Increase check size x 5 (10k -> 50k) and metric (245ms -> 900 ms) --- case-study.md | 2 +- spec/work/performance/speed_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/case-study.md b/case-study.md index 43188b83..ca577f33 100644 --- a/case-study.md +++ b/case-study.md @@ -114,7 +114,7 @@ flat - как изменилась метрика -245ms -> 180 +245ms -> 180ms - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index 7e53584e..7187c0c0 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -4,8 +4,8 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } - let(:size) { 10_000 } - let(:ms) { 245 } + let(:size) { 50_000 } + let(:ms) { 900 } before { ensure_test_data_exists(size) } From 103aa76110325c3c9cf1e5185a8fb79888265208 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 10:01:51 +0300 Subject: [PATCH 15/25] Update case study --- case-study.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/case-study.md b/case-study.md index ca577f33..964be73d 100644 --- a/case-study.md +++ b/case-study.md @@ -125,6 +125,11 @@ flat 19.68 0.127 0.050 0.000 0.076 16899 Array#map 11.45 0.063 0.029 0.000 0.034 8464 #parse +### Увеличиваем объем тестового файла (и соответственно метрику) + +size: 10k -> 50k +ms: 180ms -> 900ms + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать From 1d3596a044f5ad2c760ebacfc047b15eb914366f Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 20:52:06 +0300 Subject: [PATCH 16/25] Remove odd Date.parse & Date#iso8601 --- case-study.md | 30 +- profiling/.DS_Store | Bin 0 -> 6148 bytes .../ruby_prof_reports/callgrind.out.67404 | 398 +++++++++ profiling/ruby_prof_reports/callstack.html | 766 +++++++++--------- profiling/ruby_prof_reports/flat.txt | 71 +- task-1.rb | 3 +- 6 files changed, 830 insertions(+), 438 deletions(-) create mode 100644 profiling/.DS_Store create mode 100644 profiling/ruby_prof_reports/callgrind.out.67404 diff --git a/case-study.md b/case-study.md index 964be73d..ce744266 100644 --- a/case-study.md +++ b/case-study.md @@ -103,7 +103,7 @@ Array#select - единственный в программе 11.56 0.118 0.047 0.000 0.071 16898 Array#map 6.80 0.059 0.028 0.000 0.031 8464 #parse -### Ваша находка №X +### Ваша находка №3 - какой отчёт показал главную точку роста flat @@ -130,6 +130,34 @@ flat size: 10k -> 50k ms: 180ms -> 900ms +### Ваша находка №4 +- какой отчёт показал главную точку роста + +flat + callstack + %self total self wait child calls name location + 21.54 0.218 0.051 0.000 0.167 10 Array#each + 19.27 0.116 0.046 0.000 0.071 16899 Array#map + 11.12 0.058 0.026 0.000 0.031 8464 #parse + +- как вы решили её оптимизировать + +При формировании 'dates' использование `Date.parse` (дорогого) с последующим переводом в `iso8601` кажется избыточным убрали (имеющийся тест проходит). + +- как изменилась метрика + +900ms -> 620ms + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +перестала. + + %self total self wait child calls name location + 30.86 0.146 0.052 0.000 0.095 10 Array#each + 24.53 0.049 0.041 0.000 0.008 13827 Array#map + 13.54 0.023 0.023 0.000 0.000 20001 String#split + 5.51 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/.DS_Store b/profiling/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..352dd4ba84b11741de65aaaaf9a35fdc2b4fc7a0 GIT binary patch literal 6148 zcmeHKJ5EC}5S)b+k!V6k=__ypD+(vz0H6@4B0ZFlg6>tEi=#37X`Y^tkRqCBR$7m} z-m&E=-o6E3>(lNYSOHkl9r5ME+*z4BAsVE;T;DIc;oDE=G8to@98orAO)m=6p#W^;0y(-m@aS5I73t^AO$W{0slTUx??XK6XVmt zAzA?9g5faEqn98y4-k9dn8*mtl1fafRf}OsXS`KjFB}t-4y)$F>Sn7B#o~6J-y$8> z6E#W!DKJ&wI+rW2{}1$E`u{0OD=8oaE=mDgY#ujjKB;Q!>~UUe8~vH?Ip1_Q&V#}s m$}us@F&AEr?; +fn=GC::enable^ +72 5 + +fl= +fn=IO::write^ +0 423 + +fl= +fn=JSON/Ext/Generator/State::initialize +0 1 + +fl= +fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +0 3508 +cfl= +cfn=JSON/Ext/Generator/State::initialize +calls=1 0 +0 1 + +fl= +fn=Date::iso8601 +0 4917 + +fl= +fn=Array::reverse +0 508 + +fl= +fn=Date::<=> +0 3741 + +fl= +fn=Integer::div +0 1749 + +fl= +fn=String::[]= +0 2796 + +fl= +fn=MatchData::end +0 1525 + +fl= +fn=MatchData::begin +0 5801 + +fl= +fn=Regexp::match +0 13492 + +fl= +fn=String::gsub! +0 7235 + +fl= +fn=Date::parse^ +0 28786 +cfl= +cfn=String::gsub! +calls=8464 0 +0 7235 +cfl= +cfn=Regexp::match +calls=16928 0 +0 13492 +cfl= +cfn=MatchData::begin +calls=8464 0 +0 5801 +cfl= +cfn=MatchData::end +calls=8464 0 +0 1525 +cfl= +cfn=String::[]= +calls=8464 0 +0 2796 +cfl= +cfn=Integer::div +calls=8464 0 +0 1749 + +fl= +fn=Array::all? +0 1949 +cfl= +cfn=String::upcase +calls=1979 149 +149 585 + +fl= +fn=Array::any? +0 3803 +cfl= +cfn=String::upcase +calls=4492 144 +144 1256 + +fl= +fn=Array::max +0 348 + +fl= +fn=String::+ +0 813 + +fl= +fn=Integer::to_s +0 771 + +fl= +fn=Array::sum +0 353 + +fl= +fn=String::to_i +0 3590 + +fl= +fn=Hash::merge +0 5585 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +42 16 +cfl= +cfn=Array::each +calls=7 43 +43 172314 + +fl= +fn=Array::join +0 1574 + +fl= +fn=Array::sort +0 7141 +cfl= +cfn=Date::<=> +calls=17169 0 +0 3741 + +fl= +fn=String::upcase +0 6203 + +fl= +fn=Array::uniq +0 2454 + +fl= +fn=Array::map +0 50682 +cfl= +cfn=String::upcase +calls=16928 112 +112 4362 +cfl= +cfn=String::to_i +calls=16928 129 +129 3590 +cfl= +cfn=Date::parse^ +calls=8464 154 +154 61384 +cfl= +cfn=Date::iso8601 +calls=8464 154 +154 4917 + +fl= +fn=Array::count +0 309 + +fl= +fn=Hash::values +0 25 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::build_report +81 58 +cfl= +cfn=Hash::values +calls=2 82 +82 25 +cfl= +cfn=Array::count +calls=3 101 +101 4 +cfl= +cfn=Array::map +calls=3 104 +104 12636 +cfl= +cfn=Array::uniq +calls=2 104 +104 2454 +cfl= +cfn=Array::sort +calls=1 109 +109 1556 +cfl= +cfn=Array::join +calls=1 109 +109 21 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=7 123 +123 172330 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::assign_sessions_to_users +75 5 +cfl= +cfn=Array::each +calls=1 76 +76 5631 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=User::initialize +12 1374 + +fl= +fn=Class::new +0 1116 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=1536 0 +0 1374 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::initialize_users +63 7 +cfl= +cfn=Array::each +calls=1 66 +66 4817 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_session +31 8962 +cfl= +cfn=String::split +calls=8464 32 +32 8743 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_user +21 1432 +cfl= +cfn=String::split +calls=1536 22 +22 1377 + +fl= +fn=Array::each +0 51568 +cfl= +cfn=String::split +calls=10000 55 +55 9977 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=1536 56 +56 2809 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=8464 57 +57 17705 +cfl= +cfn=Class::new +calls=1536 68 +68 2489 +cfl= +cfn=Array::count +calls=1536 124 +124 305 +cfl= +cfn=Hash::merge +calls=10752 124 +124 5585 +cfl= +cfn=Array::map +calls=16896 129 +129 112298 +cfl= +cfn=Array::sum +calls=1536 129 +129 353 +cfl= +cfn=Integer::to_s +calls=3072 129 +129 771 +cfl= +cfn=String::+ +calls=3072 129 +129 813 +cfl= +cfn=Array::max +calls=1536 134 +134 348 +cfl= +cfn=Array::sort +calls=3072 139 +139 9326 +cfl= +cfn=Array::join +calls=1536 139 +139 1553 +cfl= +cfn=Array::any? +calls=1536 144 +144 5059 +cfl= +cfn=Array::all? +calls=1536 149 +149 2535 +cfl= +cfn=Array::reverse +calls=1536 154 +154 508 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::split_users_and_sessions +50 5 +cfl= +cfn=Array::each +calls=1 54 +54 41239 + +fl= +fn=String::split +0 22041 + +fl= +fn=IO::read^ +0 312 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +fn=GC::disable^ +84 3 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::work +160 122 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::disable^ +calls=1 161 +161 3 +cfl= +cfn=IO::read^ +calls=1 163 +163 312 +cfl= +cfn=String::split +calls=1 163 +163 1945 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::split_users_and_sessions +calls=1 164 +164 41244 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::initialize_users +calls=1 165 +165 4824 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::assign_sessions_to_users +calls=1 166 +166 5636 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::build_report +calls=1 167 +167 189083 +cfl= +cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +calls=1 169 +169 3510 +cfl= +cfn=IO::write^ +calls=1 169 +169 423 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::enable^ +calls=1 171 +171 5 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb +fn=[global]:: +10 24 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 10 +10 247106 + diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html index 447492dd..035776fc 100644 --- a/profiling/ruby_prof_reports/callstack.html +++ b/profiling/ruby_prof_reports/callstack.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 9:44:09 AM (MSK)
+
Wednesday, October 18 at 7:58:41 PM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.4151799130195286 + 0.2523494990000472 @@ -208,11 +208,11 @@

Thread 260, Fiber: 240

100.00% - 0.00% - 0.42 + 0.01% + 0.25 0.00 0.00 - 0.42 + 0.25 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.42 + 0.25 0.00 0.00 - 0.42 + 0.25 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.42 + 0.25 0.00 0.00 - 0.42 + 0.25 1/1 [global]# @@ -265,12 +265,12 @@

Thread 260, Fiber: 240

- 100.00% - 0.04% - 0.42 + 99.99% + 0.05% + 0.25 0.00 0.00 - 0.42 + 0.25 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 165 + 160 @@ -290,14 +290,14 @@

Thread 260, Fiber: 240

    - 0.35 + 0.19 0.00 0.00 - 0.35 + 0.19 1/1 Object#build_report - 172 + 167 @@ -310,7 +310,7 @@

Thread 260, Fiber: 240

1/1 Object#split_users_and_sessions - 169 + 164 @@ -321,22 +321,22 @@

Thread 260, Fiber: 240

0.00 0.01 1/1 - Object#assign_sessions_to_users + Object#initialize_users - 171 + 165     + 0.01 0.00 0.00 - 0.00 - 0.00 + 0.01 1/1 - Object#initialize_users + Object#assign_sessions_to_users - 170 + 166 @@ -349,7 +349,7 @@

Thread 260, Fiber: 240

1/1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 174 + 169 @@ -359,10 +359,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - <Class::IO>#write + 1/20001 + String#split - 174 + 163 @@ -372,10 +372,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/20001 - String#split + 1/1 + <Class::IO>#write - 168 + 169 @@ -388,7 +388,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#read - 168 + 163 @@ -399,9 +399,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#enable + <Module::GC>#disable - 176 + 161 @@ -412,9 +412,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#disable + <Module::GC>#enable - 166 + 171 @@ -429,27 +429,27 @@

Thread 260, Fiber: 240

    + 0.01 + 0.01 0.00 0.00 - 0.00 - 0.00 - 1/11 - Object#initialize_users + 1/10 + Object#assign_sessions_to_users - 66 + 76     0.01 - 0.01 0.00 0.00 - 1/11 - Object#assign_sessions_to_users + 0.00 + 1/10 + Object#initialize_users - 76 + 66 @@ -459,7 +459,7 @@

Thread 260, Fiber: 240

0.01 0.00 0.03 - 1/11 + 1/10 Object#split_users_and_sessions 54 @@ -468,37 +468,24 @@

Thread 260, Fiber: 240

    - 0.17 - 0.01 - 0.00 - 0.16 - 1/11 - Object#build_report - - 105 - - - -   -   - 0.17 - 0.03 + 0.18 + 0.04 0.00 0.14 - 7/11 + 7/10 Object#collect_stats_from_users 43 - 94.82% - 14.77% - 0.39 + 90.48% + 21.98% + 0.23 0.06 0.00 - 0.33 - 11 + 0.17 + 10 Array#each @@ -514,19 +501,6 @@

Thread 260, Fiber: 240

- -   -   - 0.16 - 0.16 - 0.00 - 0.00 - 10000/10000 - Array#all? - - 107 - -     @@ -534,10 +508,10 @@

Thread 260, Fiber: 240

0.04 0.00 0.07 - 16896/16898 + 16896/16899 Array#map - 134 + 129 @@ -576,7 +550,7 @@

Thread 260, Fiber: 240

3072/3073 Array#sort - 144 + 139 @@ -589,20 +563,33 @@

Thread 260, Fiber: 240

10752/10752 Hash#merge - 129 + 124     - 0.01 + 0.00 0.00 0.00 0.00 1536/1536 Array#any? - 149 + 144 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1536 + Class#new + + 68 @@ -626,9 +613,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Class#new + Array#all? - 68 + 149 @@ -641,7 +628,7 @@

Thread 260, Fiber: 240

1536/1537 Array#join - 144 + 139 @@ -652,9 +639,9 @@

Thread 260, Fiber: 240

0.00 0.00 3072/3072 - Integer#to_s + String#+ - 134 + 129 @@ -665,9 +652,9 @@

Thread 260, Fiber: 240

0.00 0.00 3072/3072 - String#+ + Integer#to_s - 134 + 129 @@ -680,7 +667,7 @@

Thread 260, Fiber: 240

1536/1536 Array#reverse - 159 + 154 @@ -693,7 +680,7 @@

Thread 260, Fiber: 240

1536/1536 Array#max - 139 + 134 @@ -706,7 +693,7 @@

Thread 260, Fiber: 240

1536/1536 Array#sum - 134 + 129 @@ -719,7 +706,7 @@

Thread 260, Fiber: 240

1536/1539 Array#count - 129 + 124 @@ -734,23 +721,23 @@

Thread 260, Fiber: 240

    - 0.35 + 0.19 0.00 0.00 - 0.35 + 0.19 1/1 Object#work - 172 + 167 - 84.36% - 0.01% - 0.35 + 76.26% + 0.02% + 0.19 0.00 0.00 - 0.35 + 0.19 1 @@ -770,27 +757,14 @@

Thread 260, Fiber: 240

    - 0.17 + 0.18 0.00 0.00 - 0.17 + 0.18 7/7 Object#collect_stats_from_users - 128 - - - -   -   - 0.17 - 0.01 - 0.00 - 0.16 - 1/11 - Array#each - - 105 + 123 @@ -800,10 +774,10 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 2/16898 + 3/16899 Array#map - 114 + 104 @@ -813,10 +787,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/3073 - Array#sort + 2/2 + Array#uniq - 114 + 104 @@ -826,10 +800,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Array#uniq + 1/3073 + Array#sort - 114 + 109 @@ -842,7 +816,7 @@

Thread 260, Fiber: 240

1/1537 Array#join - 114 + 109 @@ -883,23 +857,23 @@

Thread 260, Fiber: 240

    - 0.17 + 0.18 0.00 0.00 - 0.17 + 0.18 7/7 Object#build_report - 128 + 123 - 41.66% - 0.00% - 0.17 + 69.59% + 0.01% + 0.18 0.00 0.00 - 0.17 + 0.18 7 @@ -919,11 +893,11 @@

Thread 260, Fiber: 240

    - 0.17 - 0.03 + 0.18 + 0.04 0.00 0.14 - 7/11 + 7/10 Array#each 43 @@ -936,64 +910,6 @@

Thread 260, Fiber: 240

- - - -   -   - 0.16 - 0.16 - 0.00 - 0.00 - 10000/10000 - Array#each - - - - - - 39.15% - 39.00% - 0.16 - 0.16 - 0.00 - 0.00 - 10000 - - - Array#all? - - - - - - - - - - - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1979/23399 - String#upcase - - 154 - - - - - - - - - @@ -1003,10 +919,10 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 2/16898 + 3/16899 Object#build_report - 114 + 104 @@ -1016,20 +932,20 @@

Thread 260, Fiber: 240

0.04 0.00 0.07 - 16896/16898 + 16896/16899 Array#each - 28.98% - 11.53% - 0.12 + 49.83% + 21.21% + 0.13 0.05 0.00 0.07 - 16898 + 16899 Array#map @@ -1055,20 +971,20 @@

Thread 260, Fiber: 240

8464/8464 <Class::Date>#parse - 159 + 154     - 0.00 - 0.00 + 0.01 + 0.01 0.00 0.00 16928/23399 String#upcase - 117 + 112 @@ -1081,7 +997,7 @@

Thread 260, Fiber: 240

8464/8464 Date#iso8601 - 159 + 154 @@ -1094,7 +1010,7 @@

Thread 260, Fiber: 240

16928/16928 String#to_i - 134 + 129 @@ -1120,8 +1036,8 @@

Thread 260, Fiber: 240

- 14.39% - 6.79% + 23.24% + 10.80% 0.06 0.03 0.00 @@ -1239,11 +1155,11 @@

Thread 260, Fiber: 240

1/1 Object#work - 169 + 164 - 10.10% + 15.85% 0.00% 0.04 0.00 @@ -1272,7 +1188,7 @@

Thread 260, Fiber: 240

0.01 0.00 0.03 - 1/11 + 1/10 Array#each 54 @@ -1310,7 +1226,7 @@

Thread 260, Fiber: 240

1/20001 Object#work - 168 + 163 @@ -1340,8 +1256,8 @@

Thread 260, Fiber: 240

- 5.55% - 5.55% + 8.49% + 8.49% 0.02 0.02 0.00 @@ -1385,8 +1301,8 @@

Thread 260, Fiber: 240

- 4.27% - 2.19% + 6.60% + 3.39% 0.02 0.01 0.00 @@ -1443,8 +1359,8 @@

Thread 260, Fiber: 240

- 3.10% - 3.10% + 5.02% + 5.02% 0.01 0.01 0.00 @@ -1484,7 +1400,7 @@

Thread 260, Fiber: 240

1/3073 Object#build_report - 114 + 109 @@ -1501,8 +1417,8 @@

Thread 260, Fiber: 240

- 2.55% - 1.71% + 4.16% + 2.81% 0.01 0.01 0.00 @@ -1555,26 +1471,26 @@

Thread 260, Fiber: 240

1/1 Object#work - 171 + 165 - 2.01% - 0.00% + 2.96% + 0.01% 0.01 0.00 0.00 0.01 1 - - Object#assign_sessions_to_users + + Object#initialize_users - 75 + 63 @@ -1585,13 +1501,13 @@

Thread 260, Fiber: 240

    0.01 - 0.01 0.00 0.00 - 1/11 + 0.00 + 1/10 Array#each - 76 + 66 @@ -1617,8 +1533,8 @@

Thread 260, Fiber: 240

- 1.66% - 1.66% + 2.84% + 2.84% 0.01 0.01 0.00 @@ -1677,8 +1593,8 @@

Thread 260, Fiber: 240

    - 0.00 - 0.00 + 0.01 + 0.01 0.00 0.00 16928/23399 @@ -1688,8 +1604,8 @@

Thread 260, Fiber: 240

- 1.61% - 1.61% + 2.84% + 2.84% 0.01 0.01 0.00 @@ -1733,8 +1649,8 @@

Thread 260, Fiber: 240

- 1.42% - 1.42% + 2.50% + 2.50% 0.01 0.01 0.00 @@ -1778,8 +1694,8 @@

Thread 260, Fiber: 240

- 1.41% - 1.41% + 2.35% + 2.35% 0.01 0.01 0.00 @@ -1815,30 +1731,30 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.00 - 1536/1536 - Array#each + 0.01 + 1/1 + Object#work - + 166 - 1.30% - 0.97% + 2.11% + 0.00% 0.01 0.00 0.00 - 0.00 - 1536 + 0.01 + 1 - - Array#any? + + Object#assign_sessions_to_users - + 75 @@ -1848,14 +1764,14 @@

Thread 260, Fiber: 240

    + 0.01 + 0.01 0.00 0.00 - 0.00 - 0.00 - 4492/23399 - String#upcase + 1/10 + Array#each - 149 + 76 @@ -1874,29 +1790,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 170 + - 1.09% - 0.00% + 1.91% + 1.43% 0.00 0.00 0.00 0.00 - 1 + 1536 - - Object#initialize_users + + Array#any? - 63 + @@ -1910,10 +1826,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/11 - Array#each + 4492/23399 + String#upcase - 66 + 144 @@ -1939,8 +1855,8 @@

Thread 260, Fiber: 240

- 1.09% - 1.09% + 1.76% + 1.76% 0.00 0.00 0.00 @@ -1980,12 +1896,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 174 + 169 - 0.90% - 0.89% + 1.64% + 1.64% 0.00 0.00 0.00 @@ -2042,8 +1958,8 @@

Thread 260, Fiber: 240

- 0.85% - 0.85% + 1.48% + 1.48% 0.00 0.00 0.00 @@ -2087,8 +2003,8 @@

Thread 260, Fiber: 240

- 0.84% - 0.84% + 1.34% + 1.34% 0.00 0.00 0.00 @@ -2132,22 +2048,22 @@

Thread 260, Fiber: 240

- 0.70% - 0.37% + 1.31% + 0.61% 0.00 0.00 0.00 0.00 1536 - - Object#parse_user + + Class#new - 21 + @@ -2161,10 +2077,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/20001 - String#split + 1536/1536 + User#initialize - 22 + @@ -2183,35 +2099,48 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1536/1536 + Array#each - 0.67% - 0.67% + 1.16% + 0.60% 0.00 0.00 0.00 0.00 - 8464 + 1536 - - String#[]= + + Object#parse_user - + 21 + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/20001 + String#split + + 22 + + @@ -2228,23 +2157,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 8464/8464 + <Class::Date>#parse - 174 + - 0.63% - 0.63% + 1.01% + 1.01% 0.00 0.00 0.00 0.00 - 1 + 8464 - - <Class::IO>#write + + String#[]= @@ -2280,16 +2209,16 @@

Thread 260, Fiber: 240

- 0.56% - 0.25% + 0.93% + 0.71% 0.00 0.00 0.00 0.00 1536 - - Class#new + + Array#all? @@ -2309,10 +2238,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#initialize + 1979/23399 + String#upcase - + 149 @@ -2331,23 +2260,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1/1537 + Object#build_report + + 109 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1537 + Array#each - 0.39% - 0.39% + 0.78% + 0.78% 0.00 0.00 0.00 0.00 - 8464 + 1537 - - Integer#div + + Array#join @@ -2376,42 +2318,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1537 - Object#build_report - - 114 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1537 - Array#each + 1536/1536 + Class#new - 0.38% - 0.38% + 0.70% + 0.70% 0.00 0.00 0.00 0.00 - 1537 + 1536 - - Array#join + + User#initialize - + 12 @@ -2434,23 +2363,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 2/2 + Object#build_report - + 104 - 0.36% - 0.36% + 0.66% + 0.66% 0.00 0.00 0.00 0.00 - 8464 + 2 - - MatchData#end + + Array#uniq @@ -2479,29 +2408,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Class#new + 8464/8464 + <Class::Date>#parse - 0.31% - 0.31% + 0.64% + 0.64% 0.00 0.00 0.00 0.00 - 1536 + 8464 - - User#initialize + + Integer#div - 12 + @@ -2524,23 +2453,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 8464/8464 + <Class::Date>#parse - 168 + - 0.26% - 0.26% + 0.58% + 0.58% 0.00 0.00 0.00 0.00 - 1 + 8464 - - <Class::IO>#read + + MatchData#end @@ -2576,16 +2505,16 @@

Thread 260, Fiber: 240

- 0.21% - 0.21% + 0.35% + 0.35% 0.00 0.00 0.00 0.00 3072 - - Integer#to_s + + String#+ @@ -2621,16 +2550,16 @@

Thread 260, Fiber: 240

- 0.19% - 0.19% + 0.35% + 0.35% 0.00 0.00 0.00 0.00 3072 - - String#+ + + Integer#to_s @@ -2660,22 +2589,22 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - Object#build_report + Object#work - 114 + 169 - 0.16% - 0.16% + 0.27% + 0.27% 0.00 0.00 0.00 0.00 1 - - Array#uniq + + <Class::IO>#write @@ -2711,8 +2640,8 @@

Thread 260, Fiber: 240

- 0.11% - 0.11% + 0.18% + 0.18% 0.00 0.00 0.00 @@ -2756,8 +2685,8 @@

Thread 260, Fiber: 240

- 0.09% - 0.09% + 0.17% + 0.17% 0.00 0.00 0.00 @@ -2801,8 +2730,8 @@

Thread 260, Fiber: 240

- 0.09% - 0.09% + 0.16% + 0.16% 0.00 0.00 0.00 @@ -2821,6 +2750,51 @@

Thread 260, Fiber: 240

+ + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + Object#work + + 163 + + + + 0.13% + 0.13% + 0.00 + 0.00 + 0.00 + 0.00 + 1 + + + <Class::IO>#read + + + + + + + + + + @@ -2859,8 +2833,8 @@

Thread 260, Fiber: 240

- 0.08% - 0.08% + 0.12% + 0.12% 0.00 0.00 0.00 @@ -2904,8 +2878,8 @@

Thread 260, Fiber: 240

- 0.00% - 0.00% + 0.01% + 0.01% 0.00 0.00 0.00 @@ -2945,7 +2919,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 176 + 161 @@ -2957,14 +2931,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#enable + + <Module::GC>#disable - 72 + 84 @@ -2990,7 +2964,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 166 + 171 @@ -3002,14 +2976,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#disable + + <Module::GC>#enable - 84 + 72 diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index be5c7548..b0dcf7b0 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,51 +1,42 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.256290 +Total: 0.167349 Sort by: self_time %self total self wait child calls name location - 21.41 0.234 0.055 0.000 0.179 10 Array#each - 19.68 0.127 0.050 0.000 0.076 16899 Array#map - 11.45 0.063 0.029 0.000 0.034 8464 #parse - 9.35 0.024 0.024 0.000 0.000 20001 String#split - 5.29 0.014 0.014 0.000 0.000 16928 Regexp#match - 3.67 0.019 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 3.05 0.011 0.008 0.000 0.004 3073 Array#sort - 2.92 0.007 0.007 0.000 0.000 8464 String#gsub! - 2.46 0.006 0.006 0.000 0.000 8464 MatchData#begin - 2.45 0.006 0.006 0.000 0.000 23399 String#upcase - 2.34 0.006 0.006 0.000 0.000 10752 Hash#merge - 2.02 0.005 0.005 0.000 0.000 8464 Date#iso8601 - 1.51 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 1.48 0.004 0.004 0.000 0.000 16928 String#to_i - 1.48 0.005 0.004 0.000 0.001 1536 Array#any? - 1.43 0.004 0.004 0.000 0.000 17169 Date#<=> - 1.09 0.003 0.003 0.000 0.000 8464 String#[]= - 0.73 0.002 0.002 0.000 0.001 1536 Array#all? - 0.70 0.002 0.002 0.000 0.000 2 Array#uniq - 0.67 0.002 0.002 0.000 0.000 8464 MatchData#end - 0.66 0.002 0.002 0.000 0.000 1537 Array#join - 0.66 0.002 0.002 0.000 0.000 8464 Integer#div - 0.61 0.003 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 0.54 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.45 0.003 0.001 0.000 0.001 1536 Class#new - 0.35 0.001 0.001 0.000 0.000 1 #write - 0.34 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.30 0.001 0.001 0.000 0.000 3072 String#+ - 0.22 0.001 0.001 0.000 0.000 1536 Array#reverse - 0.16 0.000 0.000 0.000 0.000 1536 Array#max - 0.15 0.000 0.000 0.000 0.000 1 #read - 0.15 0.000 0.000 0.000 0.000 1536 Array#sum - 0.13 0.000 0.000 0.000 0.000 1539 Array#count - 0.04 0.256 0.000 0.000 0.256 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:165 - 0.03 0.195 0.000 0.000 0.195 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 - 0.01 0.256 0.000 0.000 0.256 1 [global]# profiling/ruby_prof_flat.rb:8 + 30.86 0.146 0.052 0.000 0.095 10 Array#each + 24.53 0.049 0.041 0.000 0.008 13827 Array#map + 13.54 0.023 0.023 0.000 0.000 20001 String#split + 5.51 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 3.74 0.006 0.006 0.000 0.000 23399 String#upcase + 3.55 0.006 0.006 0.000 0.000 10752 Hash#merge + 2.72 0.005 0.005 0.000 0.000 3073 Array#sort + 2.57 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.26 0.005 0.004 0.000 0.001 1536 Array#any? + 2.08 0.003 0.003 0.000 0.000 16928 String#to_i + 1.25 0.003 0.002 0.000 0.001 1536 Array#all? + 0.99 0.002 0.002 0.000 0.000 1537 Array#join + 0.93 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.89 0.001 0.001 0.000 0.000 2 Array#uniq + 0.81 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 0.67 0.002 0.001 0.000 0.001 1536 Class#new + 0.59 0.001 0.001 0.000 0.000 1 #read + 0.49 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.49 0.001 0.001 0.000 0.000 1 #write + 0.48 0.001 0.001 0.000 0.000 3072 String#+ + 0.28 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.23 0.000 0.000 0.000 0.000 1536 Array#max + 0.21 0.000 0.000 0.000 0.000 1536 Array#sum + 0.17 0.000 0.000 0.000 0.000 1539 Array#count + 0.08 0.167 0.000 0.000 0.167 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:161 + 0.03 0.107 0.000 0.000 0.107 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 + 0.01 0.167 0.000 0.000 0.167 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.01 0.095 0.000 0.000 0.094 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.180 0.000 0.000 0.180 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 + 0.01 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 + 0.00 0.042 0.000 0.000 0.042 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 - 0.00 0.044 0.000 0.000 0.044 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 0.00 0.006 0.000 0.000 0.006 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 0.00 0.000 0.000 0.000 0.000 1 #disable :84 0.00 0.000 0.000 0.000 0.000 1 #enable :72 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize diff --git a/task-1.rb b/task-1.rb index fa270051..f5d239a9 100644 --- a/task-1.rb +++ b/task-1.rb @@ -151,7 +151,8 @@ def build_report(users_objects_by_id, sessions) # Даты сессий через запятую в обратном порядке в формате iso8601 collect_stats_from_users(report, users_objects) do |user| - { 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } + # { 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } + { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } end report From 5d76305322d0b50832daf204913be24559bcd268 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 21:33:58 +0300 Subject: [PATCH 17/25] Update collect_stats_from_users --- case-study.md | 25 + profiling/ruby_prof_reports/callstack.html | 1370 ++++++-------------- profiling/ruby_prof_reports/flat.txt | 64 +- spec/work/performance/speed_spec.rb | 2 +- task-1.rb | 127 +- 5 files changed, 573 insertions(+), 1015 deletions(-) diff --git a/case-study.md b/case-study.md index ce744266..2f6a4c85 100644 --- a/case-study.md +++ b/case-study.md @@ -157,6 +157,31 @@ flat + callstack 13.54 0.023 0.023 0.000 0.000 20001 String#split 5.51 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 +### Ваша находка №5 +- какой отчёт показал главную точку роста + +callstack + + 0.10 0.03 0.00 0.06 7/10 Object#collect_stats_from_users 43 +84.71% 29.32% 0.15 0.05 0.00 0.10 10 Array#each + 0.04 0.03 0.00 0.01 13824/13827 Array#map 129 + +- как вы решили её оптимизировать + +`collect_stats_from_users` повторно пробегается по каждому из пользователей для формирования отдельных метрик. Попробуем сменить подход - пробегать пользователей один раз, но собирать сразу все метрики по нему. + +Кроме того, обратим внимание, что некоторые данные (время, браузеры) собираются по несколько раз. + +- как изменилась метрика + +620ms -> 460ms + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + + 0.05 0.01 0.00 0.04 1/4 Object#collect_stats_from_users 43 +82.70% 23.50% 0.11 0.03 0.00 0.08 4 Array#each + 0.02 0.02 0.00 0.00 7680/7683 Array#map 47 + ### Ваша находка №X - какой отчёт показал главную точку роста diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html index 035776fc..f509281c 100644 --- a/profiling/ruby_prof_reports/callstack.html +++ b/profiling/ruby_prof_reports/callstack.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 7:58:41 PM (MSK)
+
Wednesday, October 18 at 9:32:54 PM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.2523494990000472 + 0.12930498400055512 @@ -209,10 +209,10 @@

Thread 260, Fiber: 240

100.00% 0.01% - 0.25 + 0.13 0.00 0.00 - 0.25 + 0.13 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.25 + 0.13 0.00 0.00 - 0.25 + 0.13 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.25 + 0.13 0.00 0.00 - 0.25 + 0.13 1/1 [global]# @@ -266,11 +266,11 @@

Thread 260, Fiber: 240

99.99% - 0.05% - 0.25 + 0.08% + 0.13 0.00 0.00 - 0.25 + 0.13 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 160 + 216 @@ -290,14 +290,14 @@

Thread 260, Fiber: 240

    - 0.19 + 0.07 0.00 0.00 - 0.19 + 0.07 1/1 Object#build_report - 167 + 223 @@ -310,33 +310,33 @@

Thread 260, Fiber: 240

1/1 Object#split_users_and_sessions - 164 + 220     - 0.01 0.00 0.00 - 0.01 + 0.00 + 0.00 1/1 - Object#initialize_users + Object#assign_sessions_to_users - 165 + 222     - 0.01 0.00 0.00 - 0.01 + 0.00 + 0.00 1/1 - Object#assign_sessions_to_users + Object#initialize_users - 166 + 221 @@ -349,7 +349,7 @@

Thread 260, Fiber: 240

1/1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 169 + 225 @@ -362,7 +362,7 @@

Thread 260, Fiber: 240

1/20001 String#split - 163 + 219 @@ -375,7 +375,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#write - 169 + 225 @@ -388,7 +388,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#read - 163 + 219 @@ -399,9 +399,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#disable + <Module::GC>#enable - 161 + 227 @@ -412,9 +412,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#enable + <Module::GC>#disable - 171 + 217 @@ -429,27 +429,27 @@

Thread 260, Fiber: 240

    - 0.01 - 0.01 0.00 0.00 - 1/10 - Object#assign_sessions_to_users + 0.00 + 0.00 + 1/4 + Object#initialize_users - 76 + 121     - 0.01 0.00 0.00 0.00 - 1/10 - Object#initialize_users + 0.00 + 1/4 + Object#assign_sessions_to_users - 66 + 131 @@ -459,33 +459,33 @@

Thread 260, Fiber: 240

0.01 0.00 0.03 - 1/10 + 1/4 Object#split_users_and_sessions - 54 + 109     - 0.18 - 0.04 + 0.05 + 0.01 0.00 - 0.14 - 7/10 + 0.04 + 1/4 Object#collect_stats_from_users 43 - 90.48% - 21.98% - 0.23 - 0.06 + 82.70% + 23.50% + 0.11 + 0.03 0.00 - 0.17 - 10 + 0.08 + 4 Array#each @@ -504,14 +504,14 @@

Thread 260, Fiber: 240

    - 0.11 - 0.04 + 0.02 + 0.02 0.00 - 0.07 - 16896/16899 + 0.00 + 7680/7683 Array#map - 129 + 47 @@ -524,7 +524,7 @@

Thread 260, Fiber: 240

8464/8464 Object#parse_session - 57 + 112 @@ -537,33 +537,33 @@

Thread 260, Fiber: 240

10000/20001 String#split - 55 + 110     0.01 - 0.01 0.00 0.00 - 3072/3073 - Array#sort + 0.00 + 1536/1536 + Array#any? - 139 + 50     - 0.01 - 0.01 0.00 0.00 - 10752/10752 - Hash#merge + 0.00 + 0.00 + 3072/3073 + Array#sort - 124 + 50 @@ -574,9 +574,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#any? + Object#parse_user - 144 + 111 @@ -587,9 +587,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Class#new + Array#all? - 68 + 50 @@ -600,9 +600,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Object#parse_user + Class#new - 56 + 123 @@ -612,10 +612,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#all? + 1536/1537 + Array#join - 149 + 50 @@ -625,10 +625,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1537 - Array#join + 1536/1536 + Hash#merge - 139 + 50 @@ -639,9 +639,9 @@

Thread 260, Fiber: 240

0.00 0.00 3072/3072 - String#+ + Integer#to_s - 129 + 50 @@ -652,9 +652,9 @@

Thread 260, Fiber: 240

0.00 0.00 3072/3072 - Integer#to_s + String#+ - 129 + 50 @@ -667,7 +667,7 @@

Thread 260, Fiber: 240

1536/1536 Array#reverse - 154 + 50 @@ -678,9 +678,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#max + Array#sum - 134 + 50 @@ -691,9 +691,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#sum + Array#max - 129 + 50 @@ -706,7 +706,7 @@

Thread 260, Fiber: 240

1536/1539 Array#count - 124 + 50 @@ -721,23 +721,23 @@

Thread 260, Fiber: 240

    - 0.19 + 0.07 0.00 0.00 - 0.19 + 0.07 1/1 Object#work - 167 + 223 - 76.26% + 54.39% 0.02% - 0.19 + 0.07 0.00 0.00 - 0.19 + 0.07 1 @@ -747,7 +747,7 @@

Thread 260, Fiber: 240

- 81 + 136 @@ -757,14 +757,14 @@

Thread 260, Fiber: 240

    - 0.18 + 0.05 0.00 0.00 - 0.18 - 7/7 + 0.05 + 1/1 Object#collect_stats_from_users - 123 + 177 @@ -774,10 +774,10 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 3/16899 + 3/7683 Array#map - 104 + 159 @@ -790,7 +790,7 @@

Thread 260, Fiber: 240

2/2 Array#uniq - 104 + 159 @@ -803,7 +803,7 @@

Thread 260, Fiber: 240

1/3073 Array#sort - 109 + 164 @@ -816,7 +816,7 @@

Thread 260, Fiber: 240

1/1537 Array#join - 109 + 164 @@ -829,7 +829,7 @@

Thread 260, Fiber: 240

2/2 Hash#values - 82 + 137 @@ -842,7 +842,7 @@

Thread 260, Fiber: 240

3/1539 Array#count - 101 + 156 @@ -857,24 +857,24 @@

Thread 260, Fiber: 240

    - 0.18 + 0.05 0.00 0.00 - 0.18 - 7/7 + 0.05 + 1/1 Object#build_report - 123 + 177 - 69.59% - 0.01% - 0.18 + 41.89% + 0.00% + 0.05 0.00 0.00 - 0.18 - 7 + 0.05 + 1 Object#collect_stats_from_users @@ -893,11 +893,11 @@

Thread 260, Fiber: 240

    - 0.18 - 0.04 + 0.05 + 0.01 0.00 - 0.14 - 7/10 + 0.04 + 1/4 Array#each 43 @@ -915,46 +915,33 @@

Thread 260, Fiber: 240

    - 0.01 - 0.01 + 0.04 0.00 0.00 - 3/16899 - Object#build_report - - 104 - - - -   -   - 0.11 0.04 - 0.00 - 0.07 - 16896/16899 - Array#each + 1/1 + Object#work - + 220 - 49.83% - 21.21% - 0.13 - 0.05 + 33.68% + 0.00% + 0.04 0.00 - 0.07 - 16899 + 0.00 + 0.04 + 1 - - Array#map + + Object#split_users_and_sessions - + 105 @@ -964,16 +951,25 @@

Thread 260, Fiber: 240

    - 0.06 - 0.03 + 0.04 + 0.01 0.00 0.03 - 8464/8464 - <Class::Date>#parse + 1/4 + Array#each - 154 + 109 + + + + + + + + +     @@ -981,71 +977,36 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 16928/23399 - String#upcase - - 112 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 8464/8464 - Date#iso8601 + 3/7683 + Object#build_report - 154 + 159     + 0.02 + 0.02 0.00 0.00 - 0.00 - 0.00 - 16928/16928 - String#to_i - - 129 - - - - - - - - - - - - -   -   - 0.06 - 0.03 - 0.00 - 0.03 - 8464/8464 - Array#map + 7680/7683 + Array#each - 23.24% - 10.80% - 0.06 + 26.63% + 21.56% 0.03 - 0.00 0.03 - 8464 + 0.00 + 0.01 + 7683 - - <Class::Date>#parse + + Array#map @@ -1061,42 +1022,38 @@

Thread 260, Fiber: 240

    - 0.01 - 0.01 0.00 0.00 - 16928/16928 - Regexp#match - - - - - -   -   - 0.01 - 0.01 0.00 0.00 - 8464/8464 - String#gsub! + 16928/23399 + String#upcase - + 167     - 0.01 - 0.01 + 0.00 + 0.00 0.00 0.00 8464/8464 - MatchData#begin + String#to_i - + 47 + + + + + + + + +     @@ -1104,10 +1061,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - String#[]= + 1536/20001 + Object#parse_user - + 22 @@ -1117,136 +1074,30 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - Integer#div + 1/20001 + Object#work - + 219     + 0.01 + 0.01 0.00 0.00 - 0.00 - 0.00 - 8464/8464 - MatchData#end + 8464/20001 + Object#parse_session - + 32 - - - - - - - - -     - 0.04 - 0.00 - 0.00 - 0.04 - 1/1 - Object#work - - 164 - - - - 15.85% - 0.00% - 0.04 - 0.00 - 0.00 - 0.04 - 1 - - - Object#split_users_and_sessions - - - - - - 50 - - - - - - - -   -   - 0.04 - 0.01 - 0.00 - 0.03 - 1/10 - Array#each - - 54 - - - - - - - - - - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/20001 - Object#parse_user - - 22 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/20001 - Object#work - - 163 - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 8464/20001 - Object#parse_session - - 32 - - - -   -   - 0.01 - 0.01 + 0.01 + 0.01 0.00 0.00 10000/20001 @@ -1256,8 +1107,8 @@

Thread 260, Fiber: 240

- 8.49% - 8.49% + 17.97% + 17.97% 0.02 0.02 0.00 @@ -1301,8 +1152,8 @@

Thread 260, Fiber: 240

- 6.60% - 3.39% + 14.39% + 7.33% 0.02 0.01 0.00 @@ -1343,225 +1194,6 @@

Thread 260, Fiber: 240

- - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 16928/16928 - <Class::Date>#parse - - - - - - 5.02% - 5.02% - 0.01 - 0.01 - 0.00 - 0.00 - 16928 - - - Regexp#match - - - - - - - - - - - - - - - - - - - - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/3073 - Object#build_report - - 109 - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 3072/3073 - Array#each - - - - - - 4.16% - 2.81% - 0.01 - 0.01 - 0.00 - 0.00 - 3073 - - - Array#sort - - - - - - - - - - - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 17169/17169 - Date#<=> - - - - - - - - - - - - - - -   -   - 0.01 - 0.00 - 0.00 - 0.01 - 1/1 - Object#work - - 165 - - - - 2.96% - 0.01% - 0.01 - 0.00 - 0.00 - 0.01 - 1 - - - Object#initialize_users - - - - - - 63 - - - - - - - -   -   - 0.01 - 0.00 - 0.00 - 0.00 - 1/10 - Array#each - - 66 - - - - - - - - - - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 8464/8464 - <Class::Date>#parse - - - - - - 2.84% - 2.84% - 0.01 - 0.01 - 0.00 - 0.00 - 8464 - - - String#gsub! - - - - - - - - - - - - - - - - - - - @@ -1593,8 +1225,8 @@

Thread 260, Fiber: 240

    - 0.01 - 0.01 + 0.00 + 0.00 0.00 0.00 16928/23399 @@ -1604,8 +1236,8 @@

Thread 260, Fiber: 240

- 2.84% - 2.84% + 5.19% + 5.19% 0.01 0.01 0.00 @@ -1639,154 +1271,6 @@

Thread 260, Fiber: 240

    0.01 - 0.01 - 0.00 - 0.00 - 10752/10752 - Array#each - - - - - - 2.50% - 2.50% - 0.01 - 0.01 - 0.00 - 0.00 - 10752 - - - Hash#merge - - - - - - - - - - - - - - - - - - - - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 8464/8464 - <Class::Date>#parse - - - - - - 2.35% - 2.35% - 0.01 - 0.01 - 0.00 - 0.00 - 8464 - - - MatchData#begin - - - - - - - - - - - - - - - - - - - - - - -   -   - 0.01 - 0.00 - 0.00 - 0.01 - 1/1 - Object#work - - 166 - - - - 2.11% - 0.00% - 0.01 - 0.00 - 0.00 - 0.01 - 1 - - - Object#assign_sessions_to_users - - - - - - 75 - - - - - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 1/10 - Array#each - - 76 - - - - - - - - - - - - -   -   - 0.00 0.00 0.00 0.00 @@ -1797,9 +1281,9 @@

Thread 260, Fiber: 240

- 1.91% - 1.43% - 0.00 + 4.66% + 3.52% + 0.01 0.00 0.00 0.00 @@ -1829,7 +1313,7 @@

Thread 260, Fiber: 240

4492/23399 String#upcase - 144 + 61 @@ -1848,44 +1332,12 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - Array#map + 1/3073 + Object#build_report - + 164 - - 1.76% - 1.76% - 0.00 - 0.00 - 0.00 - 0.00 - 8464 - - - Date#iso8601 - - - - - - - - - - - - - - - - - - - - -     @@ -1893,23 +1345,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 3072/3073 + Array#each - 169 + - 1.64% - 1.64% - 0.00 - 0.00 + 3.97% + 3.97% + 0.01 + 0.01 0.00 0.00 - 1 + 3073 - - JSON::Ext::Generator::GeneratorMethods::Hash#to_json + + Array#sort @@ -1922,19 +1374,6 @@

Thread 260, Fiber: 240

- -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/1 - JSON::Ext::Generator::State#initialize - - - - @@ -1951,35 +1390,48 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 16928/16928 - Array#map + 1/1 + Object#work - + 222 - 1.48% - 1.48% + 3.71% + 0.00% 0.00 0.00 0.00 0.00 - 16928 + 1 - - String#to_i + + Object#assign_sessions_to_users - + 130 + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/4 + Array#each + + 131 + + @@ -1996,35 +1448,48 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 17169/17169 - Array#sort + 1/1 + Object#work - + 221 - 1.34% - 1.34% + 3.44% + 0.00% 0.00 0.00 0.00 0.00 - 17169 + 1 - - Date#<=> + + Object#initialize_users - + 118 + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/4 + Array#each + + 121 + + @@ -2041,23 +1506,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 225 - 1.31% - 0.61% + 2.62% + 2.62% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Class#new + + JSON::Ext::Generator::GeneratorMethods::Hash#to_json @@ -2077,8 +1542,8 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#initialize + 1/1 + JSON::Ext::Generator::State#initialize @@ -2106,8 +1571,8 @@

Thread 260, Fiber: 240

- 1.16% - 0.60% + 2.49% + 1.35% 0.00 0.00 0.00 @@ -2157,23 +1622,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1536/1536 + Array#each - 1.01% - 1.01% + 2.26% + 1.75% 0.00 0.00 0.00 0.00 - 8464 + 1536 - - String#[]= + + Array#all? @@ -2186,6 +1651,19 @@

Thread 260, Fiber: 240

+ +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1979/23399 + String#upcase + + 63 + + @@ -2209,16 +1687,16 @@

Thread 260, Fiber: 240

- 0.93% - 0.71% + 1.80% + 0.80% 0.00 0.00 0.00 0.00 1536 - - Array#all? + + Class#new @@ -2238,10 +1716,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1979/23399 - String#upcase + 1536/1536 + User#initialize - 149 + @@ -2260,36 +1738,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1537 + 2/2 Object#build_report - 109 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1537 - Array#each - - + 159 - 0.78% - 0.78% + 1.75% + 1.75% 0.00 0.00 0.00 0.00 - 1537 + 2 - - Array#join + + Array#uniq @@ -2318,29 +1783,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Class#new + 8464/8464 + Array#map - 0.70% - 0.70% + 1.53% + 1.53% 0.00 0.00 0.00 0.00 - 1536 + 8464 - - User#initialize + + String#to_i - 12 + @@ -2363,23 +1828,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 + 1/1537 Object#build_report - 104 + 164 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1537 + Array#each + + - 0.66% - 0.66% + 1.49% + 1.49% 0.00 0.00 0.00 0.00 - 2 + 1537 - - Array#uniq + + Array#join @@ -2408,23 +1886,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1536/1536 + Array#each - 0.64% - 0.64% + 1.12% + 1.12% 0.00 0.00 0.00 0.00 - 8464 + 1536 - - Integer#div + + Hash#merge @@ -2453,29 +1931,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - <Class::Date>#parse + 1536/1536 + Class#new - 0.58% - 0.58% + 1.00% + 1.00% 0.00 0.00 0.00 0.00 - 8464 + 1536 - - MatchData#end + + User#initialize - + 12 @@ -2505,16 +1983,16 @@

Thread 260, Fiber: 240

- 0.35% - 0.35% + 0.74% + 0.74% 0.00 0.00 0.00 0.00 3072 - - String#+ + + Integer#to_s @@ -2550,16 +2028,16 @@

Thread 260, Fiber: 240

- 0.35% - 0.35% + 0.68% + 0.68% 0.00 0.00 0.00 0.00 3072 - - Integer#to_s + + String#+ @@ -2588,23 +2066,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 169 + - 0.27% - 0.27% + 0.47% + 0.47% 0.00 0.00 0.00 0.00 - 1 + 1536 - - <Class::IO>#write + + Array#reverse @@ -2640,16 +2118,16 @@

Thread 260, Fiber: 240

- 0.18% - 0.18% + 0.35% + 0.35% 0.00 0.00 0.00 0.00 1536 - - Array#reverse + + Array#sum @@ -2685,8 +2163,8 @@

Thread 260, Fiber: 240

- 0.17% - 0.17% + 0.34% + 0.34% 0.00 0.00 0.00 @@ -2723,23 +2201,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 225 - 0.16% - 0.16% + 0.29% + 0.29% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Array#sum + + <Class::IO>#write @@ -2768,23 +2246,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 3/1539 + Object#build_report + + 156 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1539 + Array#each - 163 + - 0.13% - 0.13% + 0.28% + 0.28% 0.00 0.00 0.00 0.00 - 1 + 1539 - - <Class::IO>#read + + Array#count @@ -2813,36 +2304,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 - Object#build_report - - 101 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1539 - Array#each + 1/1 + Object#work - + 219 - 0.12% - 0.12% + 0.25% + 0.25% 0.00 0.00 0.00 0.00 - 1539 + 1 - - Array#count + + <Class::IO>#read @@ -2874,7 +2352,7 @@

Thread 260, Fiber: 240

2/2 Object#build_report - 82 + 137 @@ -2919,7 +2397,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 161 + 227 @@ -2931,14 +2409,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#disable + + <Module::GC>#enable - 84 + 72 @@ -2962,9 +2440,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - Object#work + JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 171 + @@ -2976,14 +2454,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#enable + + JSON::Ext::Generator::State#initialize - 72 + @@ -3007,9 +2485,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - JSON::Ext::Generator::GeneratorMethods::Hash#to_json + Object#work - + 217 @@ -3021,14 +2499,14 @@

Thread 260, Fiber: 240

0.00 1 - - JSON::Ext::Generator::State#initialize + + <Module::GC>#disable - + 84 diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index b0dcf7b0..5a1fd24f 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,45 +1,45 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.167349 +Total: 0.125500 Sort by: self_time %self total self wait child calls name location - 30.86 0.146 0.052 0.000 0.095 10 Array#each - 24.53 0.049 0.041 0.000 0.008 13827 Array#map - 13.54 0.023 0.023 0.000 0.000 20001 String#split - 5.51 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 3.74 0.006 0.006 0.000 0.000 23399 String#upcase - 3.55 0.006 0.006 0.000 0.000 10752 Hash#merge - 2.72 0.005 0.005 0.000 0.000 3073 Array#sort - 2.57 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 2.26 0.005 0.004 0.000 0.001 1536 Array#any? - 2.08 0.003 0.003 0.000 0.000 16928 String#to_i - 1.25 0.003 0.002 0.000 0.001 1536 Array#all? - 0.99 0.002 0.002 0.000 0.000 1537 Array#join - 0.93 0.003 0.002 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 0.89 0.001 0.001 0.000 0.000 2 Array#uniq - 0.81 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 0.67 0.002 0.001 0.000 0.001 1536 Class#new - 0.59 0.001 0.001 0.000 0.000 1 #read - 0.49 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.49 0.001 0.001 0.000 0.000 1 #write - 0.48 0.001 0.001 0.000 0.000 3072 String#+ - 0.28 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.23 0.000 0.000 0.000 0.000 1536 Array#max - 0.21 0.000 0.000 0.000 0.000 1536 Array#sum - 0.17 0.000 0.000 0.000 0.000 1539 Array#count - 0.08 0.167 0.000 0.000 0.167 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:161 - 0.03 0.107 0.000 0.000 0.107 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:81 - 0.01 0.167 0.000 0.000 0.167 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.01 0.095 0.000 0.000 0.094 7 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 + 22.62 0.102 0.028 0.000 0.073 4 Array#each + 20.04 0.025 0.025 0.000 0.000 20001 String#split + 19.33 0.030 0.024 0.000 0.006 7683 Array#map + 7.82 0.019 0.010 0.000 0.010 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 4.97 0.006 0.006 0.000 0.000 23399 String#upcase + 3.64 0.005 0.005 0.000 0.000 3073 Array#sort + 3.24 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 3.13 0.005 0.004 0.000 0.001 1536 Array#any? + 2.05 0.003 0.003 0.000 0.000 1 #read + 1.54 0.002 0.002 0.000 0.001 1536 Array#all? + 1.49 0.002 0.002 0.000 0.000 8464 String#to_i + 1.36 0.002 0.002 0.000 0.000 1537 Array#join + 1.27 0.003 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 1.22 0.002 0.002 0.000 0.000 2 Array#uniq + 1.04 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 1.01 0.001 0.001 0.000 0.000 1536 Hash#merge + 0.86 0.002 0.001 0.000 0.001 1536 Class#new + 0.65 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.65 0.001 0.001 0.000 0.000 3072 String#+ + 0.64 0.001 0.001 0.000 0.000 1 #write + 0.36 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.32 0.000 0.000 0.000 0.000 1536 Array#max + 0.29 0.000 0.000 0.000 0.000 1536 Array#sum + 0.28 0.000 0.000 0.000 0.000 1539 Array#count + 0.11 0.125 0.000 0.000 0.125 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:216 + 0.02 0.061 0.000 0.000 0.061 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:136 + 0.02 0.125 0.000 0.000 0.125 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.02 0.046 0.000 0.000 0.046 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:105 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:63 - 0.00 0.042 0.000 0.000 0.042 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:75 + 0.01 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:118 0.00 0.000 0.000 0.000 0.000 1 #disable :84 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:130 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize + 0.00 0.048 0.000 0.000 0.048 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 * recursively called methods diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index 7187c0c0..2da41c2e 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -5,7 +5,7 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } let(:size) { 50_000 } - let(:ms) { 900 } + let(:ms) { 460 } before { ensure_test_data_exists(size) } diff --git a/task-1.rb b/task-1.rb index f5d239a9..ab065c2b 100644 --- a/task-1.rb +++ b/task-1.rb @@ -43,7 +43,62 @@ def collect_stats_from_users(report, users_objects, &block) users_objects.each do |user| user_key = "#{user.first_name}" + ' ' + "#{user.last_name}" report['usersStats'][user_key] ||= {} - report['usersStats'][user_key] = report['usersStats'][user_key].merge(block.call(user)) + + user_times = user.sessions.map {|s| s['time']}.map {|t| t.to_i} + user_browsers = user.sessions.map {|s| s['browser']} + + report['usersStats'][user_key] = report['usersStats'][user_key].merge( + { + # # Собираем количество сессий по пользователям + 'sessionsCount' => user.sessions.count, + # # Собираем количество времени по пользователям + 'totalTime' => user_times.sum.to_s + ' min.', + # # Выбираем самую длинную сессию пользователя + 'longestSession' => user_times.max.to_s + ' min.', + # # Браузеры пользователя через запятую + 'browsers' => user_browsers.map {|b| b.upcase}.sort.join(', '), + # # Хоть раз использовал IE? + 'usedIE' => user_browsers.any? { |b| b.upcase =~ /INTERNET EXPLORER/ }, + # # Всегда использовал только Chrome? + 'alwaysUsedChrome' => user_browsers.all? { |b| b.upcase =~ /CHROME/ }, + # # Даты сессий через запятую в обратном порядке в формате iso8601 + 'dates' => user.sessions.map{|s| s['date']}.sort.reverse + } + # # Собираем количество сессий по пользователям + # collect_stats_from_users(report, users_objects) do |user| + # { 'sessionsCount' => user.sessions.count } + # end + + # # Собираем количество времени по пользователям + # collect_stats_from_users(report, users_objects) do |user| + # { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } + # end + + # # Выбираем самую длинную сессию пользователя + # collect_stats_from_users(report, users_objects) do |user| + # { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } + # end + + # # Браузеры пользователя через запятую + # collect_stats_from_users(report, users_objects) do |user| + # { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } + # end + + # # Хоть раз использовал IE? + # collect_stats_from_users(report, users_objects) do |user| + # { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } + # end + + # # Всегда использовал только Chrome? + # collect_stats_from_users(report, users_objects) do |user| + # { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } + # end + + # # Даты сессий через запятую в обратном порядке в формате iso8601 + # collect_stats_from_users(report, users_objects) do |user| + # { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } + # end + ) end end @@ -119,41 +174,41 @@ def build_report(users_objects_by_id, sessions) users_objects = users_objects_by_id.values - # Собираем количество сессий по пользователям - collect_stats_from_users(report, users_objects) do |user| - { 'sessionsCount' => user.sessions.count } - end - - # Собираем количество времени по пользователям - collect_stats_from_users(report, users_objects) do |user| - { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } - end - - # Выбираем самую длинную сессию пользователя - collect_stats_from_users(report, users_objects) do |user| - { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } - end - - # Браузеры пользователя через запятую - collect_stats_from_users(report, users_objects) do |user| - { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } - end - - # Хоть раз использовал IE? - collect_stats_from_users(report, users_objects) do |user| - { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } - end - - # Всегда использовал только Chrome? - collect_stats_from_users(report, users_objects) do |user| - { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } - end - - # Даты сессий через запятую в обратном порядке в формате iso8601 - collect_stats_from_users(report, users_objects) do |user| - # { 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 } } - { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } - end + collect_stats_from_users(report, users_objects) + # # Собираем количество сессий по пользователям + # collect_stats_from_users(report, users_objects) do |user| + # { 'sessionsCount' => user.sessions.count } + # end + + # # Собираем количество времени по пользователям + # collect_stats_from_users(report, users_objects) do |user| + # { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } + # end + + # # Выбираем самую длинную сессию пользователя + # collect_stats_from_users(report, users_objects) do |user| + # { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } + # end + + # # Браузеры пользователя через запятую + # collect_stats_from_users(report, users_objects) do |user| + # { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } + # end + + # # Хоть раз использовал IE? + # collect_stats_from_users(report, users_objects) do |user| + # { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } + # end + + # # Всегда использовал только Chrome? + # collect_stats_from_users(report, users_objects) do |user| + # { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } + # end + + # # Даты сессий через запятую в обратном порядке в формате iso8601 + # collect_stats_from_users(report, users_objects) do |user| + # { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } + # end report end From 3249cbe2993463ec7d4e76cb702ecc0c92002477 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 21:34:50 +0300 Subject: [PATCH 18/25] Remove redundant comments --- task-1.rb | 68 ------------------------------------------------------- 1 file changed, 68 deletions(-) diff --git a/task-1.rb b/task-1.rb index ab065c2b..413c5961 100644 --- a/task-1.rb +++ b/task-1.rb @@ -64,40 +64,6 @@ def collect_stats_from_users(report, users_objects, &block) # # Даты сессий через запятую в обратном порядке в формате iso8601 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } - # # Собираем количество сессий по пользователям - # collect_stats_from_users(report, users_objects) do |user| - # { 'sessionsCount' => user.sessions.count } - # end - - # # Собираем количество времени по пользователям - # collect_stats_from_users(report, users_objects) do |user| - # { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } - # end - - # # Выбираем самую длинную сессию пользователя - # collect_stats_from_users(report, users_objects) do |user| - # { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } - # end - - # # Браузеры пользователя через запятую - # collect_stats_from_users(report, users_objects) do |user| - # { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } - # end - - # # Хоть раз использовал IE? - # collect_stats_from_users(report, users_objects) do |user| - # { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } - # end - - # # Всегда использовал только Chrome? - # collect_stats_from_users(report, users_objects) do |user| - # { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } - # end - - # # Даты сессий через запятую в обратном порядке в формате iso8601 - # collect_stats_from_users(report, users_objects) do |user| - # { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } - # end ) end end @@ -175,40 +141,6 @@ def build_report(users_objects_by_id, sessions) users_objects = users_objects_by_id.values collect_stats_from_users(report, users_objects) - # # Собираем количество сессий по пользователям - # collect_stats_from_users(report, users_objects) do |user| - # { 'sessionsCount' => user.sessions.count } - # end - - # # Собираем количество времени по пользователям - # collect_stats_from_users(report, users_objects) do |user| - # { 'totalTime' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.sum.to_s + ' min.' } - # end - - # # Выбираем самую длинную сессию пользователя - # collect_stats_from_users(report, users_objects) do |user| - # { 'longestSession' => user.sessions.map {|s| s['time']}.map {|t| t.to_i}.max.to_s + ' min.' } - # end - - # # Браузеры пользователя через запятую - # collect_stats_from_users(report, users_objects) do |user| - # { 'browsers' => user.sessions.map {|s| s['browser']}.map {|b| b.upcase}.sort.join(', ') } - # end - - # # Хоть раз использовал IE? - # collect_stats_from_users(report, users_objects) do |user| - # { 'usedIE' => user.sessions.map{|s| s['browser']}.any? { |b| b.upcase =~ /INTERNET EXPLORER/ } } - # end - - # # Всегда использовал только Chrome? - # collect_stats_from_users(report, users_objects) do |user| - # { 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } } - # end - - # # Даты сессий через запятую в обратном порядке в формате iso8601 - # collect_stats_from_users(report, users_objects) do |user| - # { 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } - # end report end From 1e5aac99bc269000890bd5fcef46e9fcc515f3ee Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Wed, 18 Oct 2023 22:11:01 +0300 Subject: [PATCH 19/25] Update split_users_and_sessions --- case-study.md | 25 + .../ruby_prof_reports/callgrind.out.86565 | 326 ++++++++++ profiling/ruby_prof_reports/callstack.html | 592 +++++++++--------- profiling/ruby_prof_reports/flat.txt | 67 +- task-1.rb | 5 +- 5 files changed, 683 insertions(+), 332 deletions(-) create mode 100644 profiling/ruby_prof_reports/callgrind.out.86565 diff --git a/case-study.md b/case-study.md index 2f6a4c85..6c44735b 100644 --- a/case-study.md +++ b/case-study.md @@ -182,6 +182,31 @@ callstack 82.70% 23.50% 0.11 0.03 0.00 0.08 4 Array#each 0.02 0.02 0.00 0.00 7680/7683 Array#map 47 +### Ваша находка №6 +- какой отчёт показал главную точку роста + +Flat: + %self total self wait child calls name location + 22.99 0.100 0.029 0.000 0.071 4 Array#each + 19.44 0.031 0.025 0.000 0.006 7683 Array#map + 18.74 0.024 0.024 0.000 0.000 20001 String#split + +Split в числе лидеров. + +- как вы решили её оптимизировать + +Разбирая сессии/пользователей - лучше пользоваться String#start_with?. Массив нам там не нужен. + +- как изменилась метрика + +460ms -> 320ms + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + + %self total self wait child calls name location + 24.79 0.095 0.029 0.000 0.066 4 Array#each + 20.47 0.030 0.024 0.000 0.006 7683 Array#map + 10.73 0.013 0.013 0.000 0.000 10001 String#split ### Ваша находка №X - какой отчёт показал главную точку роста diff --git a/profiling/ruby_prof_reports/callgrind.out.86565 b/profiling/ruby_prof_reports/callgrind.out.86565 new file mode 100644 index 00000000..230ca747 --- /dev/null +++ b/profiling/ruby_prof_reports/callgrind.out.86565 @@ -0,0 +1,326 @@ +events: wall_time + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +fn=GC::enable^ +72 6 + +fl= +fn=IO::write^ +0 444 + +fl= +fn=JSON/Ext/Generator/State::initialize +0 4 + +fl= +fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +0 3633 +cfl= +cfn=JSON/Ext/Generator/State::initialize +calls=1 0 +0 4 + +fl= +fn=Hash::merge +0 1298 + +fl= +fn=Array::reverse +0 517 + +fl= +fn=Array::all? +0 1914 +cfl= +cfn=String::upcase +calls=1979 63 +63 495 + +fl= +fn=Array::any? +0 3909 +cfl= +cfn=String::upcase +calls=4492 61 +61 1167 + +fl= +fn=Array::max +0 399 + +fl= +fn=String::+ +0 810 + +fl= +fn=Integer::to_s +0 882 + +fl= +fn=Array::sum +0 396 + +fl= +fn=String::to_i +0 1839 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::collect_stats_from_users +42 4 +cfl= +cfn=Array::each +calls=1 43 +43 46937 + +fl= +fn=Array::join +0 1676 + +fl= +fn=Array::sort +0 4477 + +fl= +fn=String::upcase +0 6040 + +fl= +fn=Array::uniq +0 1688 + +fl= +fn=Array::map +0 25027 +cfl= +cfn=String::upcase +calls=16928 133 +133 4378 +cfl= +cfn=String::to_i +calls=8464 47 +47 1839 + +fl= +fn=Array::count +0 371 + +fl= +fn=Hash::values +0 21 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::build_report +102 42 +cfl= +cfn=Hash::values +calls=2 103 +103 21 +cfl= +cfn=Array::count +calls=3 122 +122 6 +cfl= +cfn=Array::map +calls=3 125 +125 11560 +cfl= +cfn=Array::uniq +calls=2 125 +125 1688 +cfl= +cfn=Array::sort +calls=1 130 +130 1580 +cfl= +cfn=Array::join +calls=1 130 +130 41 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::collect_stats_from_users +calls=1 143 +143 46941 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::assign_sessions_to_users +96 9 +cfl= +cfn=Array::each +calls=1 97 +97 5581 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=User::initialize +12 1439 + +fl= +fn=Class::new +0 1244 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=User::initialize +calls=1536 0 +0 1439 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::initialize_users +84 7 +cfl= +cfn=Array::each +calls=1 87 +87 5049 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_session +31 9489 +cfl= +cfn=String::split +calls=8464 32 +32 8942 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::parse_user +21 1505 +cfl= +cfn=String::split +calls=1536 22 +22 1490 + +fl= +fn=Array::each +0 29829 +cfl= +cfn=String::split +calls=10000 76 +76 10685 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_user +calls=1536 77 +77 2995 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::parse_session +calls=8464 78 +78 18431 +cfl= +cfn=Class::new +calls=1536 89 +89 2683 +cfl= +cfn=Array::map +calls=7680 47 +47 19684 +cfl= +cfn=Array::count +calls=1536 50 +50 365 +cfl= +cfn=Array::sum +calls=1536 50 +50 396 +cfl= +cfn=Integer::to_s +calls=3072 50 +50 882 +cfl= +cfn=String::+ +calls=3072 50 +50 810 +cfl= +cfn=Array::max +calls=1536 50 +50 399 +cfl= +cfn=Array::sort +calls=3072 50 +50 2898 +cfl= +cfn=Array::join +calls=1536 50 +50 1635 +cfl= +cfn=Array::any? +calls=1536 50 +50 5076 +cfl= +cfn=Array::all? +calls=1536 50 +50 2409 +cfl= +cfn=Array::reverse +calls=1536 50 +50 517 +cfl= +cfn=Hash::merge +calls=1536 50 +50 1298 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::split_users_and_sessions +71 6 +cfl= +cfn=Array::each +calls=1 75 +75 43423 + +fl= +fn=String::split +0 23272 + +fl= +fn=IO::read^ +0 308 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +fn=GC::disable^ +84 4 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +fn=Object::work +148 157 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::disable^ +calls=1 149 +149 4 +cfl= +cfn=IO::read^ +calls=1 151 +151 308 +cfl= +cfn=String::split +calls=1 151 +151 2155 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::split_users_and_sessions +calls=1 152 +152 43429 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::initialize_users +calls=1 153 +153 5056 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::assign_sessions_to_users +calls=1 154 +154 5590 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::build_report +calls=1 155 +155 61878 +cfl= +cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json +calls=1 157 +157 3637 +cfl= +cfn=IO::write^ +calls=1 157 +157 444 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ +cfn=GC::enable^ +calls=1 159 +159 6 + +fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb +fn=[global]:: +10 19 +cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb +cfn=Object::work +calls=1 10 +10 122664 + diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html index f509281c..ae3f5db9 100644 --- a/profiling/ruby_prof_reports/callstack.html +++ b/profiling/ruby_prof_reports/callstack.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 9:32:54 PM (MSK)
+
Wednesday, October 18 at 10:04:54 PM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.12930498400055512 + 0.12461452800016559 @@ -209,10 +209,10 @@

Thread 260, Fiber: 240

100.00% 0.01% - 0.13 + 0.12 0.00 0.00 - 0.13 + 0.12 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.13 + 0.12 0.00 0.00 - 0.13 + 0.12 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.13 + 0.12 0.00 0.00 - 0.13 + 0.12 1/1 [global]# @@ -266,11 +266,11 @@

Thread 260, Fiber: 240

99.99% - 0.08% - 0.13 + 0.10% + 0.12 0.00 0.00 - 0.13 + 0.12 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 216 + 148 @@ -290,14 +290,14 @@

Thread 260, Fiber: 240

    - 0.07 + 0.06 0.00 0.00 - 0.07 + 0.06 1/1 Object#build_report - 223 + 155 @@ -310,20 +310,20 @@

Thread 260, Fiber: 240

1/1 Object#split_users_and_sessions - 220 + 152     + 0.01 0.00 0.00 - 0.00 - 0.00 + 0.01 1/1 Object#assign_sessions_to_users - 222 + 154 @@ -336,7 +336,7 @@

Thread 260, Fiber: 240

1/1 Object#initialize_users - 221 + 153 @@ -349,7 +349,7 @@

Thread 260, Fiber: 240

1/1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 225 + 157 @@ -359,10 +359,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/20001 - String#split + 1/1 + <Class::IO>#write - 219 + 157 @@ -372,10 +372,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - <Class::IO>#write + 1/20001 + String#split - 225 + 151 @@ -388,7 +388,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#read - 219 + 151 @@ -401,7 +401,7 @@

Thread 260, Fiber: 240

1/1 <Module::GC>#enable - 227 + 159 @@ -414,7 +414,7 @@

Thread 260, Fiber: 240

1/1 <Module::GC>#disable - 217 + 149 @@ -436,20 +436,20 @@

Thread 260, Fiber: 240

1/4 Object#initialize_users - 121 + 87     - 0.00 - 0.00 + 0.01 + 0.01 0.00 0.00 1/4 Object#assign_sessions_to_users - 131 + 97 @@ -462,7 +462,7 @@

Thread 260, Fiber: 240

1/4 Object#split_users_and_sessions - 109 + 75 @@ -479,12 +479,12 @@

Thread 260, Fiber: 240

- 82.70% - 23.50% - 0.11 + 81.44% + 25.79% + 0.10 0.03 0.00 - 0.08 + 0.07 4 @@ -524,7 +524,7 @@

Thread 260, Fiber: 240

8464/8464 Object#parse_session - 112 + 78 @@ -537,7 +537,7 @@

Thread 260, Fiber: 240

10000/20001 String#split - 110 + 76 @@ -560,10 +560,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3073 - Array#sort + 1536/1536 + Object#parse_user - 50 + 77 @@ -573,10 +573,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Object#parse_user + 3072/3073 + Array#sort - 111 + 50 @@ -602,7 +602,7 @@

Thread 260, Fiber: 240

1536/1536 Class#new - 123 + 89 @@ -678,7 +678,7 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#sum + Array#max 50 @@ -691,7 +691,7 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#max + Array#sum 50 @@ -721,23 +721,23 @@

Thread 260, Fiber: 240

    - 0.07 + 0.06 0.00 0.00 - 0.07 + 0.06 1/1 Object#work - 223 + 155 - 54.39% + 48.35% 0.02% - 0.07 + 0.06 0.00 0.00 - 0.07 + 0.06 1 @@ -747,7 +747,7 @@

Thread 260, Fiber: 240

- 136 + 102 @@ -764,7 +764,7 @@

Thread 260, Fiber: 240

1/1 Object#collect_stats_from_users - 177 + 143 @@ -777,7 +777,7 @@

Thread 260, Fiber: 240

3/7683 Array#map - 159 + 125 @@ -790,7 +790,7 @@

Thread 260, Fiber: 240

2/2 Array#uniq - 159 + 125 @@ -803,7 +803,7 @@

Thread 260, Fiber: 240

1/3073 Array#sort - 164 + 130 @@ -816,7 +816,7 @@

Thread 260, Fiber: 240

1/1537 Array#join - 164 + 130 @@ -829,7 +829,7 @@

Thread 260, Fiber: 240

2/2 Hash#values - 137 + 103 @@ -842,7 +842,7 @@

Thread 260, Fiber: 240

3/1539 Array#count - 156 + 122 @@ -864,11 +864,11 @@

Thread 260, Fiber: 240

1/1 Object#build_report - 177 + 143 - 41.89% + 37.52% 0.00% 0.05 0.00 @@ -922,12 +922,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 220 + 152 - 33.68% - 0.00% + 33.43% + 0.01% 0.04 0.00 0.00 @@ -941,7 +941,7 @@

Thread 260, Fiber: 240

- 105 + 71 @@ -958,7 +958,7 @@

Thread 260, Fiber: 240

1/4 Array#each - 109 + 75 @@ -980,7 +980,7 @@

Thread 260, Fiber: 240

3/7683 Object#build_report - 159 + 125 @@ -997,10 +997,10 @@

Thread 260, Fiber: 240

- 26.63% - 21.56% - 0.03 + 23.96% + 19.08% 0.03 + 0.02 0.00 0.01 7683 @@ -1029,7 +1029,7 @@

Thread 260, Fiber: 240

16928/23399 String#upcase - 167 + 133 @@ -1077,7 +1077,7 @@

Thread 260, Fiber: 240

1/20001 Object#work - 219 + 151 @@ -1107,8 +1107,8 @@

Thread 260, Fiber: 240

- 17.97% - 17.97% + 17.99% + 17.99% 0.02 0.02 0.00 @@ -1152,8 +1152,8 @@

Thread 260, Fiber: 240

- 14.39% - 7.33% + 14.02% + 7.24% 0.02 0.01 0.00 @@ -1194,6 +1194,64 @@

Thread 260, Fiber: 240

+ + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Object#work + + 154 + + + + 6.71% + 0.01% + 0.01 + 0.00 + 0.00 + 0.01 + 1 + + + Object#assign_sessions_to_users + + + + + + 96 + + + + + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 1/4 + Array#each + + 97 + + + + + + + + + @@ -1236,8 +1294,8 @@

Thread 260, Fiber: 240

- 5.19% - 5.19% + 4.75% + 4.75% 0.01 0.01 0.00 @@ -1281,8 +1339,8 @@

Thread 260, Fiber: 240

- 4.66% - 3.52% + 4.07% + 3.13% 0.01 0.00 0.00 @@ -1323,64 +1381,6 @@

Thread 260, Fiber: 240

- - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/3073 - Object#build_report - - 164 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 3072/3073 - Array#each - - - - - - 3.97% - 3.97% - 0.01 - 0.01 - 0.00 - 0.00 - 3073 - - - Array#sort - - - - - - - - - - - - - - - - - - - @@ -1393,26 +1393,26 @@

Thread 260, Fiber: 240

1/1 Object#work - 222 + 153 - 3.71% - 0.00% + 3.80% + 0.01% 0.00 0.00 0.00 0.00 1 - - Object#assign_sessions_to_users + + Object#initialize_users - 130 + 84 @@ -1429,7 +1429,7 @@

Thread 260, Fiber: 240

1/4 Array#each - 131 + 87 @@ -1448,48 +1448,48 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1/3073 + Object#build_report - 221 + 130 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 3072/3073 + Array#each + + - 3.44% - 0.00% + 3.56% + 3.56% 0.00 0.00 0.00 0.00 - 1 + 3073 - - Object#initialize_users + + Array#sort - 118 + - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/4 - Array#each - - 121 - - @@ -1509,12 +1509,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 225 + 157 - 2.62% - 2.62% + 3.09% + 3.08% 0.00 0.00 0.00 @@ -1571,8 +1571,8 @@

Thread 260, Fiber: 240

- 2.49% - 1.35% + 2.37% + 1.18% 0.00 0.00 0.00 @@ -1622,23 +1622,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 157 - 2.26% - 1.75% + 1.93% + 1.93% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Array#all? + + <Class::IO>#write @@ -1651,19 +1651,6 @@

Thread 260, Fiber: 240

- -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1979/23399 - String#upcase - - 63 - - @@ -1687,16 +1674,16 @@

Thread 260, Fiber: 240

- 1.80% - 0.80% + 1.90% + 1.50% 0.00 0.00 0.00 0.00 1536 - - Class#new + + Array#all? @@ -1716,10 +1703,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#initialize + 1979/23399 + String#upcase - + 63 @@ -1738,23 +1725,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 - Object#build_report + 1536/1536 + Array#each - 159 + - 1.75% - 1.75% + 1.90% + 0.84% 0.00 0.00 0.00 0.00 - 2 + 1536 - - Array#uniq + + Class#new @@ -1767,6 +1754,19 @@

Thread 260, Fiber: 240

+ +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1536 + User#initialize + + + + @@ -1790,8 +1790,8 @@

Thread 260, Fiber: 240

- 1.53% - 1.53% + 1.46% + 1.46% 0.00 0.00 0.00 @@ -1831,7 +1831,7 @@

Thread 260, Fiber: 240

1/1537 Object#build_report - 164 + 130 @@ -1848,8 +1848,8 @@

Thread 260, Fiber: 240

- 1.49% - 1.49% + 1.34% + 1.34% 0.00 0.00 0.00 @@ -1886,23 +1886,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 2/2 + Object#build_report - + 125 - 1.12% - 1.12% + 1.28% + 1.28% 0.00 0.00 0.00 0.00 - 1536 + 2 - - Hash#merge + + Array#uniq @@ -1938,8 +1938,8 @@

Thread 260, Fiber: 240

- 1.00% - 1.00% + 1.06% + 1.06% 0.00 0.00 0.00 @@ -1976,23 +1976,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3072 + 1536/1536 Array#each - 0.74% - 0.74% + 1.05% + 1.05% 0.00 0.00 0.00 0.00 - 3072 + 1536 - - Integer#to_s + + Hash#merge @@ -2021,23 +2021,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3072 - Array#each + 1/1 + Object#work - + 151 - 0.68% - 0.68% + 0.86% + 0.86% 0.00 0.00 0.00 0.00 - 3072 + 1 - - String#+ + + <Class::IO>#read @@ -2066,23 +2066,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 + 3072/3072 Array#each - 0.47% - 0.47% + 0.69% + 0.69% 0.00 0.00 0.00 0.00 - 1536 + 3072 - - Array#reverse + + Integer#to_s @@ -2111,23 +2111,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 + 3072/3072 Array#each - 0.35% - 0.35% + 0.68% + 0.68% 0.00 0.00 0.00 0.00 - 1536 + 3072 - - Array#sum + + String#+ @@ -2163,16 +2163,16 @@

Thread 260, Fiber: 240

- 0.34% - 0.34% + 0.38% + 0.38% 0.00 0.00 0.00 0.00 1536 - - Array#max + + Array#reverse @@ -2201,23 +2201,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 225 + - 0.29% - 0.29% + 0.34% + 0.34% 0.00 0.00 0.00 0.00 - 1 + 1536 - - <Class::IO>#write + + Array#max @@ -2246,36 +2246,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 - Object#build_report - - 156 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1539 + 1536/1536 Array#each - 0.28% - 0.28% + 0.31% + 0.31% 0.00 0.00 0.00 0.00 - 1539 + 1536 - - Array#count + + Array#sum @@ -2304,23 +2291,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 3/1539 + Object#build_report + + 122 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1539 + Array#each - 219 + - 0.25% - 0.25% + 0.27% + 0.27% 0.00 0.00 0.00 0.00 - 1 + 1539 - - <Class::IO>#read + + Array#count @@ -2352,7 +2352,7 @@

Thread 260, Fiber: 240

2/2 Object#build_report - 137 + 103 @@ -2397,7 +2397,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 227 + 159 @@ -2487,7 +2487,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 217 + 149 diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index 5a1fd24f..e8521616 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,45 +1,46 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.125500 +Total: 0.117758 Sort by: self_time %self total self wait child calls name location - 22.62 0.102 0.028 0.000 0.073 4 Array#each - 20.04 0.025 0.025 0.000 0.000 20001 String#split - 19.33 0.030 0.024 0.000 0.006 7683 Array#map - 7.82 0.019 0.010 0.000 0.010 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 4.97 0.006 0.006 0.000 0.000 23399 String#upcase - 3.64 0.005 0.005 0.000 0.000 3073 Array#sort - 3.24 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 3.13 0.005 0.004 0.000 0.001 1536 Array#any? - 2.05 0.003 0.003 0.000 0.000 1 #read - 1.54 0.002 0.002 0.000 0.001 1536 Array#all? - 1.49 0.002 0.002 0.000 0.000 8464 String#to_i - 1.36 0.002 0.002 0.000 0.000 1537 Array#join - 1.27 0.003 0.002 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 1.22 0.002 0.002 0.000 0.000 2 Array#uniq - 1.04 0.001 0.001 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 1.01 0.001 0.001 0.000 0.000 1536 Hash#merge - 0.86 0.002 0.001 0.000 0.001 1536 Class#new - 0.65 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.65 0.001 0.001 0.000 0.000 3072 String#+ - 0.64 0.001 0.001 0.000 0.000 1 #write - 0.36 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.32 0.000 0.000 0.000 0.000 1536 Array#max - 0.29 0.000 0.000 0.000 0.000 1536 Array#sum - 0.28 0.000 0.000 0.000 0.000 1539 Array#count - 0.11 0.125 0.000 0.000 0.125 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:216 - 0.02 0.061 0.000 0.000 0.061 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:136 - 0.02 0.125 0.000 0.000 0.125 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.02 0.046 0.000 0.000 0.046 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:105 + 24.79 0.095 0.029 0.000 0.066 4 Array#each + 20.47 0.030 0.024 0.000 0.006 7683 Array#map + 10.73 0.013 0.013 0.000 0.000 10001 String#split + 7.71 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 5.32 0.006 0.006 0.000 0.000 23399 String#upcase + 4.00 0.005 0.005 0.000 0.000 3073 Array#sort + 3.68 0.004 0.004 0.000 0.000 20000 String#start_with? + 3.38 0.005 0.004 0.000 0.001 1536 Array#any? + 3.29 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.11 0.002 0.002 0.000 0.000 1 #read + 1.63 0.003 0.002 0.000 0.001 1536 Array#all? + 1.58 0.002 0.002 0.000 0.000 8464 String#to_i + 1.50 0.002 0.002 0.000 0.000 1537 Array#join + 1.27 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 + 1.27 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 1.16 0.001 0.001 0.000 0.000 2 Array#uniq + 1.15 0.001 0.001 0.000 0.000 1536 Hash#merge + 1.11 0.003 0.001 0.000 0.002 1536 Class#new + 0.79 0.001 0.001 0.000 0.000 3072 String#+ + 0.73 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.65 0.001 0.001 0.000 0.000 1 #write + 0.50 0.001 0.001 0.000 0.000 1536 Array#reverse + 0.35 0.000 0.000 0.000 0.000 1536 Array#max + 0.33 0.000 0.000 0.000 0.000 1536 Array#sum + 0.29 0.000 0.000 0.000 0.000 1539 Array#count + 0.11 0.118 0.000 0.000 0.118 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:147 + 0.02 0.062 0.000 0.000 0.062 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:101 + 0.02 0.036 0.000 0.000 0.036 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:71 + 0.01 0.118 0.000 0.000 0.118 1 [global]# profiling/ruby_prof_flat.rb:8 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.005 0.000 0.000 0.005 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:118 - 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 0.01 0.005 0.000 0.000 0.005 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:95 + 0.01 0.006 0.000 0.000 0.006 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:83 0.00 0.000 0.000 0.000 0.000 1 #enable :72 - 0.00 0.004 0.000 0.000 0.004 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:130 + 0.00 0.000 0.000 0.000 0.000 1 #disable :84 + 0.00 0.049 0.000 0.000 0.049 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize - 0.00 0.048 0.000 0.000 0.048 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 * recursively called methods diff --git a/task-1.rb b/task-1.rb index 413c5961..e7f5a503 100644 --- a/task-1.rb +++ b/task-1.rb @@ -73,9 +73,8 @@ def split_users_and_sessions(file_lines) sessions = [] file_lines.each do |line| - cols = line.split(',') - users << parse_user(line) if cols[0] == 'user' - sessions << parse_session(line) if cols[0] == 'session' + users << parse_user(line) if line.start_with?('user') + sessions << parse_session(line) if line.start_with?('session') end [users, sessions] From d59585d27aa171342e4343d3fc54b9c4713689b3 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 09:41:11 +0300 Subject: [PATCH 20/25] Update complexity --- case-study.md | 31 + profiling/ruby_prof_reports/callstack.html | 1484 +++++++++++++------- profiling/ruby_prof_reports/flat.txt | 77 +- spec/work/performance/complexity_spec.rb | 16 +- spec/work/performance/speed_spec.rb | 4 +- task-1.rb | 113 +- 6 files changed, 1124 insertions(+), 601 deletions(-) diff --git a/case-study.md b/case-study.md index 6c44735b..969af7d1 100644 --- a/case-study.md +++ b/case-study.md @@ -208,6 +208,37 @@ Split в числе лидеров. 20.47 0.030 0.024 0.000 0.006 7683 Array#map 10.73 0.013 0.013 0.000 0.000 10001 String#split +### Ваша находка №7 +- какой отчёт показал главную точку роста + +flat + %self total self wait child calls name location + 24.83 0.110 0.033 0.000 0.076 4 Array#each + + `each` выполняется 4 раза в программе, хотя мы должны это кол-во минимизировть. Кажется, и вся "сложность" алгоритма отсюда. + +- как вы решили её оптимизировать + +Надо бы пробегать по строкам файла один раз - и сразу собирать нужные для отчета данные там. + +- как изменилась метрика + +Весь `each`/`map` остается значительным, и метрика практически не изменилась. Но (ура!) сложность сменилась с квадратичной на линейную! + +Проверяем целевой тест - `data_large` за 34 секунды! мы близки. + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +Отчет изменился не значительно. + + %self total self wait child calls name location + 20.56 0.122 0.030 0.000 0.092 1540 *Array#each + 20.03 0.042 0.029 0.000 0.013 12290 *Array#map + 9.30 0.013 0.013 0.000 0.000 10001 String#split + 7.67 0.023 0.011 0.000 0.012 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:54 + +Коммитим изменение и пересматриваем входные данные метрики. + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html index ae3f5db9..37392835 100644 --- a/profiling/ruby_prof_reports/callstack.html +++ b/profiling/ruby_prof_reports/callstack.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Wednesday, October 18 at 10:04:54 PM (MSK)
+
Thursday, October 19 at 9:12:28 AM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.12461452800016559 + 0.13126262900186703 @@ -208,11 +208,11 @@

Thread 260, Fiber: 240

100.00% - 0.01% - 0.12 + 0.02% + 0.13 0.00 0.00 - 0.12 + 0.13 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.12 + 0.13 0.00 0.00 - 0.12 + 0.13 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.12 + 0.13 0.00 0.00 - 0.12 + 0.13 1/1 [global]# @@ -265,12 +265,12 @@

Thread 260, Fiber: 240

- 99.99% - 0.10% - 0.12 + 99.98% + 0.11% + 0.13 0.00 0.00 - 0.12 + 0.13 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 148 + 150 @@ -290,10 +290,10 @@

Thread 260, Fiber: 240

    - 0.06 + 0.07 0.00 0.00 - 0.06 + 0.07 1/1 Object#build_report @@ -303,42 +303,16 @@

Thread 260, Fiber: 240

    - 0.04 - 0.00 - 0.00 - 0.04 - 1/1 - Object#split_users_and_sessions - - 152 - - - -   -   - 0.01 + 0.05 0.00 0.00 - 0.01 + 0.05 1/1 - Object#assign_sessions_to_users + Object#parse_lines 154 - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1/1 - Object#initialize_users - - 153 - -     @@ -360,9 +334,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Class::IO>#write + <Class::IO>#read - 157 + 153 @@ -372,10 +346,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/20001 + 1/10001 String#split - 151 + 153 @@ -386,9 +360,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Class::IO>#read + <Class::IO>#write - 151 + 157 @@ -414,7 +388,7 @@

Thread 260, Fiber: 240

1/1 <Module::GC>#disable - 149 + 151 @@ -433,23 +407,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/4 - Object#initialize_users + 1536/1540 + Enumerable#max_by - 87 +     0.01 + 0.00 + 0.00 + 0.00 + 1/1540 + Enumerable#group_by + + + + + +   +   0.01 0.00 0.00 - 1/4 - Object#assign_sessions_to_users + 0.01 + 1/1540 + Enumerable#each_with_object - 97 + @@ -459,36 +446,36 @@

Thread 260, Fiber: 240

0.01 0.00 0.03 - 1/4 - Object#split_users_and_sessions + 1/1540 + Object#parse_lines - 75 + 104     - 0.05 + 0.06 0.01 0.00 - 0.04 - 1/4 + 0.05 + 1/1540 Object#collect_stats_from_users - 43 + 66 - 81.44% - 25.79% - 0.10 + 83.41% + 22.19% + 0.11 0.03 0.00 - 0.07 - 4 + 0.08 + 1540 - Array#each + *Array#each @@ -501,19 +488,6 @@

Thread 260, Fiber: 240

- -   -   - 0.02 - 0.02 - 0.00 - 0.00 - 7680/7683 - Array#map - - 47 - -     @@ -524,20 +498,20 @@

Thread 260, Fiber: 240

8464/8464 Object#parse_session - 78 + 105     0.01 - 0.01 0.00 0.00 - 10000/20001 - String#split + 0.01 + 1536/1536 + User#used_internet_explorer? - 76 + 73 @@ -546,50 +520,50 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.00 + 0.01 1536/1536 - Array#any? + User#always_used_chrome? - 50 + 73     + 0.01 0.00 0.00 - 0.00 - 0.00 - 1536/1536 - Object#parse_user + 0.01 + 1536/6144 + User#browsers - 77 + 73     + 0.01 + 0.01 0.00 0.00 - 0.00 - 0.00 - 3072/3073 - Array#sort + 8464/8464 + User#add_session - 50 + 108     - 0.00 + 0.01 0.00 0.00 0.00 1536/1536 - Array#all? + User#longest_session - 50 + 73 @@ -600,9 +574,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Class#new + Object#parse_user - 89 + 99 @@ -612,10 +586,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1537 - Array#join + 1536/1536 + Class#new - 50 + 100 @@ -625,10 +599,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Hash#merge + 3072/9217 + Array#sort - 50 + 73 @@ -638,10 +612,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3072 - Integer#to_s + 1536/7682 + Array#map - 50 + 73 @@ -651,10 +625,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3072 - String#+ + 10000/10000 + String#start_with? - 50 + 96 @@ -664,10 +638,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#reverse + 1536/1537 + Array#join - 50 + 73 @@ -678,9 +652,9 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#max + Hash#merge - 50 + 73 @@ -690,10 +664,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#sum + 3072/3072 + Integer#to_s - 50 + 73 @@ -703,10 +677,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1539 - Array#count + 1536/1536 + Array#reverse - 50 + 73 @@ -721,10 +695,10 @@

Thread 260, Fiber: 240

    - 0.06 + 0.07 0.00 0.00 - 0.06 + 0.07 1/1 Object#work @@ -732,12 +706,12 @@

Thread 260, Fiber: 240

- 48.35% + 51.19% 0.02% - 0.06 + 0.07 0.00 0.00 - 0.06 + 0.07 1 @@ -747,7 +721,7 @@

Thread 260, Fiber: 240

- 102 + 114 @@ -757,27 +731,40 @@

Thread 260, Fiber: 240

    - 0.05 + 0.06 0.00 0.00 - 0.05 + 0.06 1/1 Object#collect_stats_from_users - 143 + 145     0.01 - 0.01 0.00 0.00 - 3/7683 + 0.01 + 2/7682 Array#map - 125 + 135 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + Array#flatten + + 135 @@ -790,7 +777,7 @@

Thread 260, Fiber: 240

2/2 Array#uniq - 125 + 135 @@ -800,10 +787,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/3073 + 1/9217 Array#sort - 130 + 140 @@ -816,7 +803,7 @@

Thread 260, Fiber: 240

1/1537 Array#join - 130 + 140 @@ -826,10 +813,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 - Hash#values + 1/1 + Array#sum - 103 + 138 @@ -839,10 +826,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 + 2/2 Array#count - 122 + 132 @@ -857,23 +844,23 @@

Thread 260, Fiber: 240

    - 0.05 + 0.06 0.00 0.00 - 0.05 + 0.06 1/1 Object#build_report - 143 + 145 - 37.52% + 42.27% 0.00% - 0.05 + 0.06 0.00 0.00 - 0.05 + 0.06 1 @@ -883,7 +870,7 @@

Thread 260, Fiber: 240

- 42 + 65 @@ -893,14 +880,14 @@

Thread 260, Fiber: 240

    - 0.05 + 0.06 0.01 0.00 - 0.04 - 1/4 + 0.05 + 1/1540 Array#each - 43 + 66 @@ -915,33 +902,33 @@

Thread 260, Fiber: 240

    - 0.04 + 0.05 0.00 0.00 - 0.04 + 0.05 1/1 Object#work - 152 + 154 - 33.43% + 41.18% 0.01% - 0.04 + 0.05 0.00 0.00 - 0.04 + 0.05 1 - - Object#split_users_and_sessions + + Object#parse_lines - 71 + 94 @@ -955,81 +942,36 @@

Thread 260, Fiber: 240

0.01 0.00 0.03 - 1/4 + 1/1540 Array#each - 75 + 104 - - - - - - - - -     0.01 - 0.01 - 0.00 - 0.00 - 3/7683 - Object#build_report - - 125 - - - -   -   - 0.02 - 0.02 0.00 0.00 - 7680/7683 - Array#each + 0.01 + 1/1 + Enumerable#each_with_object - + 98 - - 23.96% - 19.08% - 0.03 - 0.02 - 0.00 - 0.01 - 7683 - - - Array#map - - - - - - - - - - - -     + 0.01 0.00 0.00 - 0.00 - 0.00 - 16928/23399 - String#upcase + 0.01 + 1/1 + Enumerable#group_by - 133 + 96 @@ -1039,10 +981,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - String#to_i + 2/2 + Hash#values - 47 + 96 @@ -1057,117 +999,453 @@

Thread 260, Fiber: 240

    + 0.01 0.00 0.00 - 0.00 - 0.00 - 1536/20001 - Object#parse_user + 0.01 + 1536/6144 + User#always_used_chrome? - 22 + 34     + 0.01 0.00 0.00 - 0.00 - 0.00 - 1/20001 - Object#work + 0.01 + 1536/6144 + User#used_internet_explorer? - 151 + 30     0.01 - 0.01 0.00 0.00 - 8464/20001 - Object#parse_session + 0.01 + 1536/6144 + Array#each - 32 +     0.01 - 0.01 0.00 0.00 - 10000/20001 - Array#each + 0.01 + 1536/6144 + Array#map - 17.99% - 17.99% - 0.02 - 0.02 + 25.17% + 2.99% + 0.03 0.00 0.00 - 20001 + 0.03 + 6144 - - String#split + + User#browsers - + 25 - - - - - - - - -     0.02 + 0.02 + 0.00 + 0.01 + 6144/7682 + Array#map + + 26 + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 6144/9217 + Array#sort + + 26 + + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/7682 + Array#each + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 2/7682 + Object#build_report + + 135 + + + +   +   + 0.02 + 0.02 + 0.00 + 0.01 + 6144/7682 + User#browsers + + 26 + + + + 22.50% + 14.38% + 0.03 + 0.02 + 0.00 + 0.01 + 7682 + + + *Array#map + + + + + + + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1536/6144 + User#browsers + + + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 33856/33856 + String#upcase + + 26 + + + + + + + + + + + + +   +   + 0.02 + 0.01 + 0.00 + 0.01 + 8464/8464 + Array#each + + + + + + 17.22% + 8.20% + 0.02 + 0.01 + 0.00 + 0.01 + 8464 + + + Object#parse_session + + + + + + 54 + + + + + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 8464/10001 + String#split + + 55 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 8464/8464 + String#to_i + + 57 + + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/10001 + Object#parse_user + + 45 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/10001 + Object#work + + 153 + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 8464/10001 + Object#parse_session + + 55 + + + + 10.53% + 10.53% + 0.01 + 0.01 + 0.00 + 0.00 + 10001 + + + String#split + + + + + + + + + + + + + + + + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1536/1536 + Array#each + + + + + + 9.54% + 0.78% + 0.01 + 0.00 + 0.00 + 0.01 + 1536 + + + User#used_internet_explorer? + + + + + + 29 + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1536/6144 + User#browsers + + 30 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1536 + Array#any? + + 30 + + + + + + + + + + + + +   +   0.01 0.00 + 0.00 0.01 - 8464/8464 + 1536/1536 Array#each - 14.02% - 7.24% - 0.02 + 8.54% + 0.75% 0.01 0.00 + 0.00 0.01 - 8464 + 1536 - - Object#parse_session + + User#always_used_chrome? - 31 + 33 @@ -1178,13 +1456,26 @@

Thread 260, Fiber: 240

    0.01 + 0.00 + 0.00 0.01 + 1536/6144 + User#browsers + + 34 + + + +   +   0.00 0.00 - 8464/20001 - String#split + 0.00 + 0.00 + 1536/1536 + Array#all? - 32 + 34 @@ -1204,13 +1495,13 @@

Thread 260, Fiber: 240

0.00 0.01 1/1 - Object#work + Object#parse_lines - 154 + 98 - 6.71% + 7.42% 0.01% 0.01 0.00 @@ -1218,14 +1509,14 @@

Thread 260, Fiber: 240

0.01 1 - - Object#assign_sessions_to_users + + Enumerable#each_with_object - 96 + @@ -1236,15 +1527,60 @@

Thread 260, Fiber: 240

    0.01 - 0.01 0.00 0.00 - 1/4 + 0.01 + 1/1540 Array#each - 97 + + + + + + + + + + + + + +   +   + 0.01 + 0.01 + 0.00 + 0.00 + 33856/33856 + Array#map + + + + 6.22% + 6.22% + 0.01 + 0.01 + 0.00 + 0.00 + 33856 + + + String#upcase + + + + + + + + + + + + @@ -1261,10 +1597,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1979/23399 - Array#all? + 1/9217 + Object#build_report - + 140 @@ -1274,8 +1610,8 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 4492/23399 - Array#any? + 3072/9217 + Array#each @@ -1283,33 +1619,136 @@

Thread 260, Fiber: 240

    + 0.01 + 0.01 + 0.00 + 0.00 + 6144/9217 + User#browsers + + 26 + + + + 6.06% + 6.06% + 0.01 + 0.01 + 0.00 + 0.00 + 9217 + + + Array#sort + + + + + + + + + + + + + + + + + + + + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Object#parse_lines + + 96 + + + + 4.62% + 0.01% + 0.01 + 0.00 + 0.00 + 0.01 + 1 + + + Enumerable#group_by + + + + + + + + + + + + + +   +   + 0.01 0.00 0.00 0.00 + 1/1540 + Array#each + + + + + + + + + + + + + + +   +   + 0.01 + 0.01 + 0.00 0.00 - 16928/23399 - Array#map + 8464/8464 + Array#each - 4.75% - 4.75% + 4.48% + 4.48% 0.01 0.01 0.00 0.00 - 23399 + 8464 - - String#upcase + + User#add_session - + 37 @@ -1339,22 +1778,22 @@

Thread 260, Fiber: 240

- 4.07% - 3.13% + 4.10% + 0.62% 0.01 0.00 0.00 0.00 1536 - - Array#any? + + User#longest_session - + 21 @@ -1368,10 +1807,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 4492/23399 - String#upcase + 1536/1536 + Enumerable#max_by - 61 + 22 @@ -1390,29 +1829,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + User#longest_session - 153 + 22 - 3.80% - 0.01% + 3.48% + 0.69% 0.00 0.00 0.00 0.00 - 1 + 1536 - - Object#initialize_users + + Enumerable#max_by - 84 + @@ -1426,10 +1865,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/4 + 1536/1540 Array#each - 87 + @@ -1448,12 +1887,57 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/3073 - Object#build_report + 1/1 + Object#work + + 157 + + + + 2.95% + 2.95% + 0.00 + 0.00 + 0.00 + 0.00 + 1 + + + JSON::Ext::Generator::GeneratorMethods::Hash#to_json + + + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + JSON::Ext::Generator::State#initialize - 130 + + + + + + + + + +     @@ -1461,23 +1945,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3073 - Array#each + 1536/1536 + User#used_internet_explorer? - + 30 - 3.56% - 3.56% + 2.91% + 1.94% 0.00 0.00 0.00 0.00 - 3073 + 1536 - - Array#sort + + Array#any? @@ -1490,6 +1974,19 @@

Thread 260, Fiber: 240

+ +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 5839/9407 + String#include? + + 30 + + @@ -1506,29 +2003,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 157 + - 3.09% - 3.08% + 2.79% + 1.41% 0.00 0.00 0.00 0.00 - 1 + 1536 - - JSON::Ext::Generator::GeneratorMethods::Hash#to_json + + Object#parse_user - + 44 @@ -1542,10 +2039,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - JSON::Ext::Generator::State#initialize + 1536/10001 + String#split - + 45 @@ -1571,22 +2068,22 @@

Thread 260, Fiber: 240

- 2.37% - 1.18% + 2.42% + 1.02% 0.00 0.00 0.00 0.00 1536 - - Object#parse_user + + Class#new - 21 + @@ -1600,10 +2097,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/20001 - String#split + 1536/1536 + User#initialize - 22 + @@ -1625,20 +2122,20 @@

Thread 260, Fiber: 240

1/1 Object#work - 157 + 153 - 1.93% - 1.93% + 2.12% + 2.12% 0.00 0.00 0.00 0.00 1 - - <Class::IO>#write + + <Class::IO>#read @@ -1668,14 +2165,14 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Array#each + User#always_used_chrome? - + 34 - 1.90% - 1.50% + 1.96% + 1.34% 0.00 0.00 0.00 @@ -1703,10 +2200,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1979/23399 - String#upcase + 3568/9407 + String#include? - 63 + 34 @@ -1725,23 +2222,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 3568/9407 + Array#all? + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 5839/9407 + Array#any? - 1.90% - 0.84% + 1.59% + 1.59% 0.00 0.00 0.00 0.00 - 1536 + 9407 - - Class#new + + String#include? @@ -1754,19 +2264,6 @@

Thread 260, Fiber: 240

- -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1536 - User#initialize - - - - @@ -1784,14 +2281,14 @@

Thread 260, Fiber: 240

0.00 0.00 8464/8464 - Array#map + Object#parse_session - + 57 - 1.46% - 1.46% + 1.58% + 1.58% 0.00 0.00 0.00 @@ -1828,36 +2325,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1537 - Object#build_report - - 130 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1537 + 10000/10000 Array#each - 1.34% - 1.34% + 1.52% + 1.52% 0.00 0.00 0.00 0.00 - 1537 + 10000 - - Array#join + + String#start_with? @@ -1886,29 +2370,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 - Object#build_report + 1536/1536 + Class#new - 125 + - 1.28% - 1.28% + 1.41% + 1.41% 0.00 0.00 0.00 0.00 - 2 + 1536 - - Array#uniq + + User#initialize - + 11 @@ -1931,29 +2415,42 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Class#new + 1/1537 + Object#build_report + + 140 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1537 + Array#each - 1.06% - 1.06% + 1.31% + 1.31% 0.00 0.00 0.00 0.00 - 1536 + 1537 - - User#initialize + + Array#join - 12 + @@ -1983,8 +2480,8 @@

Thread 260, Fiber: 240

- 1.05% - 1.05% + 0.92% + 0.92% 0.00 0.00 0.00 @@ -2024,20 +2521,20 @@

Thread 260, Fiber: 240

1/1 Object#work - 151 + 157 - 0.86% - 0.86% + 0.72% + 0.72% 0.00 0.00 0.00 0.00 1 - - <Class::IO>#read + + <Class::IO>#write @@ -2066,23 +2563,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/3072 - Array#each + 1/1 + Object#build_report - + 135 - 0.69% - 0.69% + 0.60% + 0.60% 0.00 0.00 0.00 0.00 - 3072 + 1 - - Integer#to_s + + Array#flatten @@ -2118,16 +2615,16 @@

Thread 260, Fiber: 240

- 0.68% - 0.68% + 0.60% + 0.60% 0.00 0.00 0.00 0.00 3072 - - String#+ + + Integer#to_s @@ -2156,23 +2653,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 2/2 + Object#build_report - + 135 - 0.38% - 0.38% + 0.56% + 0.56% 0.00 0.00 0.00 0.00 - 1536 + 2 - - Array#reverse + + Array#uniq @@ -2216,8 +2713,8 @@

Thread 260, Fiber: 240

0.00 1536 - - Array#max + + Array#reverse @@ -2246,29 +2743,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 159 - 0.31% - 0.31% + 0.01% + 0.01% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Array#sum + + <Module::GC>#enable - + 72 @@ -2291,36 +2788,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3/1539 - Object#build_report - - 122 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1539 - Array#each + 2/2 + Object#parse_lines - + 96 - 0.27% - 0.27% + 0.01% + 0.01% 0.00 0.00 0.00 0.00 - 1539 + 2 - - Array#count + + Hash#values @@ -2349,23 +2833,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 + 1/1 Object#build_report - 103 + 138 - 0.01% - 0.01% + 0.00% + 0.00% 0.00 0.00 0.00 0.00 - 2 + 1 - - Hash#values + + Array#sum @@ -2397,7 +2881,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 159 + 151 @@ -2409,14 +2893,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#enable + + <Module::GC>#disable - 72 + 84 @@ -2439,10 +2923,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2/2 + Object#build_report - + 132 @@ -2452,10 +2936,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1 + 2 - - JSON::Ext::Generator::State#initialize + + Array#count @@ -2485,9 +2969,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - Object#work + JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 149 + @@ -2499,14 +2983,14 @@

Thread 260, Fiber: 240

0.00 1 - - <Module::GC>#disable + + JSON::Ext::Generator::State#initialize - 84 + diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index e8521616..c96f0e71 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,45 +1,52 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.117758 +Total: 0.143747 Sort by: self_time %self total self wait child calls name location - 24.79 0.095 0.029 0.000 0.066 4 Array#each - 20.47 0.030 0.024 0.000 0.006 7683 Array#map - 10.73 0.013 0.013 0.000 0.000 10001 String#split - 7.71 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 5.32 0.006 0.006 0.000 0.000 23399 String#upcase - 4.00 0.005 0.005 0.000 0.000 3073 Array#sort - 3.68 0.004 0.004 0.000 0.000 20000 String#start_with? - 3.38 0.005 0.004 0.000 0.001 1536 Array#any? - 3.29 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 2.11 0.002 0.002 0.000 0.000 1 #read - 1.63 0.003 0.002 0.000 0.001 1536 Array#all? - 1.58 0.002 0.002 0.000 0.000 8464 String#to_i - 1.50 0.002 0.002 0.000 0.000 1537 Array#join - 1.27 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:12 - 1.27 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 1.16 0.001 0.001 0.000 0.000 2 Array#uniq - 1.15 0.001 0.001 0.000 0.000 1536 Hash#merge - 1.11 0.003 0.001 0.000 0.002 1536 Class#new - 0.79 0.001 0.001 0.000 0.000 3072 String#+ - 0.73 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.65 0.001 0.001 0.000 0.000 1 #write - 0.50 0.001 0.001 0.000 0.000 1536 Array#reverse - 0.35 0.000 0.000 0.000 0.000 1536 Array#max - 0.33 0.000 0.000 0.000 0.000 1536 Array#sum - 0.29 0.000 0.000 0.000 0.000 1539 Array#count - 0.11 0.118 0.000 0.000 0.118 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:147 - 0.02 0.062 0.000 0.000 0.062 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:101 - 0.02 0.036 0.000 0.000 0.036 1 Object#split_users_and_sessions /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:71 - 0.01 0.118 0.000 0.000 0.118 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.005 0.000 0.000 0.005 1 Object#assign_sessions_to_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:95 - 0.01 0.006 0.000 0.000 0.006 1 Object#initialize_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:83 - 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 20.56 0.122 0.030 0.000 0.092 1540 *Array#each + 20.03 0.042 0.029 0.000 0.013 12290 *Array#map + 9.30 0.013 0.013 0.000 0.000 10001 String#split + 7.67 0.023 0.011 0.000 0.012 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:54 + 5.80 0.008 0.008 0.000 0.000 33856 String#upcase + 5.60 0.008 0.008 0.000 0.000 9217 Array#sort + 4.06 0.006 0.006 0.000 0.000 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:37 + 2.85 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.79 0.034 0.004 0.000 0.030 6144 User#browsers /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:25 + 1.88 0.003 0.003 0.000 0.000 1 #read + 1.79 0.004 0.003 0.000 0.001 1536 Array#any? + 1.59 0.002 0.002 0.000 0.000 8464 Integer#to_i :130 + 1.58 0.002 0.002 0.000 0.000 9407 String#include? + 1.42 0.002 0.002 0.000 0.000 8464 String#to_i + 1.37 0.002 0.002 0.000 0.000 10000 String#start_with? + 1.25 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 1.21 0.002 0.002 0.000 0.000 1537 Array#join + 1.19 0.003 0.002 0.000 0.001 1536 Array#all? + 1.01 0.003 0.001 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:44 + 0.84 0.001 0.001 0.000 0.000 1536 Hash#merge + 0.82 0.003 0.001 0.000 0.002 1536 Class#new + 0.77 0.013 0.001 0.000 0.012 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:29 + 0.73 0.012 0.001 0.000 0.011 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:33 + 0.62 0.003 0.001 0.000 0.002 1536 Enumerable#max_by + 0.60 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.59 0.001 0.001 0.000 0.000 1 Array#flatten + 0.55 0.004 0.001 0.000 0.003 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 + 0.54 0.001 0.001 0.000 0.000 1 #write + 0.52 0.001 0.001 0.000 0.000 2 Array#uniq + 0.32 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.08 0.144 0.000 0.000 0.144 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:154 + 0.02 0.081 0.000 0.000 0.081 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:114 + 0.01 0.000 0.000 0.000 0.000 3 Hash#values + 0.01 0.144 0.000 0.000 0.144 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.01 0.053 0.000 0.000 0.053 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:94 + 0.01 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.006 0.000 0.000 0.006 1 Enumerable#group_by 0.00 0.000 0.000 0.000 0.000 1 #disable :84 - 0.00 0.049 0.000 0.000 0.049 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:42 + 0.00 0.000 0.000 0.000 0.000 1 Array#sum + 0.00 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object + 0.00 0.069 0.000 0.000 0.069 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:65 + 0.00 0.000 0.000 0.000 0.000 2 Array#count 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize * recursively called methods diff --git a/spec/work/performance/complexity_spec.rb b/spec/work/performance/complexity_spec.rb index e2bf7390..d4ab33ce 100644 --- a/spec/work/performance/complexity_spec.rb +++ b/spec/work/performance/complexity_spec.rb @@ -1,24 +1,24 @@ RSpec.describe 'Work' do describe 'performance' do let(:from) { 8 } - let(:to) { 10_000 } + let(:to) { 100_000 } let(:benchmark_range) { bench_range(from, to) } let(:file_path) { full_path("spec/fixtures/data#{size}.txt") } - xdescribe 'complexity' do + describe 'complexity' do before { benchmark_range.each { |i| ensure_test_data_exists(i) } } - # it 'is linear' do - # expect { |n, _i| work(fixture(n)) }.to perform_linear.in_range(from, to) - # end + it 'is linear' do + expect { |n, _i| work(fixture(n)) }.to perform_linear.in_range(from, to) + end # it 'is logarithmic' do # expect { |n, _i| work(fixture(n)) }.to perform_logarithmic.in_range(from, to) # end - it 'is not power' do - expect { |n, _i| work(fixture(n)) }.not_to perform_power.in_range(from, to) - end + # it 'is not power' do + # expect { |n, _i| work(fixture(n)) }.not_to perform_power.in_range(from, to) + # end end end end diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index 2da41c2e..c2ee4903 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -4,8 +4,8 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } - let(:size) { 50_000 } - let(:ms) { 460 } + let(:size) { 250_000 } + let(:ms) { 2000 } before { ensure_test_data_exists(size) } diff --git a/task-1.rb b/task-1.rb index e7f5a503..515e5aa6 100644 --- a/task-1.rb +++ b/task-1.rb @@ -6,8 +6,7 @@ require 'minitest/autorun' class User - attr_reader :id, :first_name, :last_name, :age - attr_accessor :sessions + attr_reader :id, :first_name, :last_name, :age, :sessions, :sessions_count, :total_time def initialize(id:, first_name:, last_name:, age:, sessions: []) @id = id @@ -15,6 +14,30 @@ def initialize(id:, first_name:, last_name:, age:, sessions: []) @last_name = last_name @age = age @sessions = sessions + @sessions_count = 0 + @total_time = 0 + end + + def longest_session + @sessions.max_by { |s| s['time'] } + end + + def browsers + @sessions.map { |s| s['browser'].upcase }.sort + end + + def used_internet_explorer? + browsers.any? { |b| b.include?('INTERNET EXPLORER') } + end + + def always_used_chrome? + browsers.all? { |b| b.include?('CHROME') } + end + + def add_session(session) + @sessions << session + @sessions_count += 1 + @total_time += session['time'] end end @@ -34,33 +57,33 @@ def parse_session(session) 'user_id' => fields[1], 'session_id' => fields[2], 'browser' => fields[3], - 'time' => fields[4], + 'time' => fields[4].to_i, 'date' => fields[5], } end -def collect_stats_from_users(report, users_objects, &block) - users_objects.each do |user| +def collect_stats_from_users(report, users) + users.each do |user| user_key = "#{user.first_name}" + ' ' + "#{user.last_name}" report['usersStats'][user_key] ||= {} - user_times = user.sessions.map {|s| s['time']}.map {|t| t.to_i} - user_browsers = user.sessions.map {|s| s['browser']} + # user_times = user.sessions.map {|s| s['time']}.map {|t| t.to_i} + # user_browsers = user.sessions.map {|s| s['browser']} report['usersStats'][user_key] = report['usersStats'][user_key].merge( { # # Собираем количество сессий по пользователям - 'sessionsCount' => user.sessions.count, + 'sessionsCount' => user.sessions_count, # # Собираем количество времени по пользователям - 'totalTime' => user_times.sum.to_s + ' min.', + 'totalTime' => "#{user.total_time} min.", # # Выбираем самую длинную сессию пользователя - 'longestSession' => user_times.max.to_s + ' min.', + 'longestSession' => "#{user.longest_session['time']} min.", # # Браузеры пользователя через запятую - 'browsers' => user_browsers.map {|b| b.upcase}.sort.join(', '), + 'browsers' => user.browsers.sort.join(', '), # # Хоть раз использовал IE? - 'usedIE' => user_browsers.any? { |b| b.upcase =~ /INTERNET EXPLORER/ }, + 'usedIE' => user.used_internet_explorer?, # # Всегда использовал только Chrome? - 'alwaysUsedChrome' => user_browsers.all? { |b| b.upcase =~ /CHROME/ }, + 'alwaysUsedChrome' => user.always_used_chrome?, # # Даты сессий через запятую в обратном порядке в формате iso8601 'dates' => user.sessions.map{|s| s['date']}.sort.reverse } @@ -68,39 +91,27 @@ def collect_stats_from_users(report, users_objects, &block) end end -def split_users_and_sessions(file_lines) - users = [] - sessions = [] +def parse_lines(file_lines) + # lines = file_lines.sort_by { |l| l} + users, sessions = file_lines.group_by { |l| l.start_with?('user') }.values - file_lines.each do |line| - users << parse_user(line) if line.start_with?('user') - sessions << parse_session(line) if line.start_with?('session') + users_objects_by_id = users.each_with_object({}) do |u, acc| + user_attributes = parse_user(u) + user_object = User.new(**user_attributes) + acc[user_object.id] = user_object end - [users, sessions] -end - -def initialize_users(users) - users_objects_by_id = {} - - users.each do |user| - attributes = user - user_object = User.new(**attributes) - users_objects_by_id[user_object.id] = user_object + sessions.each do |s| + session = parse_session(s) + session_user_id = session['user_id'] + session_user = users_objects_by_id[session_user_id] + session_user.add_session(session) end - users_objects_by_id + users_objects_by_id.values end -def assign_sessions_to_users(users_objects_by_id, sessions) - sessions.each do |session| - users_objects_by_id[session['user_id']].sessions << session - end -end - -def build_report(users_objects_by_id, sessions) - users = users_objects_by_id.values - +def build_report(users) # Отчёт в json # - Сколько всего юзеров + # - Сколько всего уникальных браузеров + @@ -121,25 +132,17 @@ def build_report(users_objects_by_id, sessions) report[:totalUsers] = users.count # Подсчёт количества уникальных браузеров - uniqueBrowsers = sessions.map { |s| s['browser'] }.uniq - report['uniqueBrowsersCount'] = uniqueBrowsers.count + unique_browsers = users.map(&:browsers).flatten.uniq + report['uniqueBrowsersCount'] = unique_browsers.count - report['totalSessions'] = sessions.count + report['totalSessions'] = users.map(&:sessions_count).sum - report['allBrowsers'] = - sessions - .map { |s| s['browser'] } - .map { |b| b.upcase } - .sort - .uniq - .join(',') + report['allBrowsers'] = unique_browsers.uniq.sort.join(',') # Статистика по пользователям report['usersStats'] = {} - users_objects = users_objects_by_id.values - - collect_stats_from_users(report, users_objects) + collect_stats_from_users(report, users) report end @@ -148,10 +151,8 @@ def work(file_path = 'data.txt', **options) GC.disable if options[:disable_gc] file_lines = File.read(file_path).split("\n") - users, sessions = split_users_and_sessions(file_lines) - users_objects_by_id = initialize_users(users) - assign_sessions_to_users(users_objects_by_id, sessions) - report = build_report(users_objects_by_id, sessions) + users = parse_lines(file_lines) + report = build_report(users) File.write('result.json', "#{report.to_json}\n") ensure From 62a63c56bf6b42023112664c4e122fda2650a31f Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 10:33:02 +0300 Subject: [PATCH 21/25] Update alwaysUsedChrome --- case-study.md | 56 + profiling/ruby_prof_reports/callstack.html | 1244 +++++++++----------- profiling/ruby_prof_reports/flat.txt | 77 +- spec/work/performance/budget_spec.rb | 2 +- spec/work/performance/speed_spec.rb | 2 +- task-1.rb | 18 +- 6 files changed, 674 insertions(+), 725 deletions(-) diff --git a/case-study.md b/case-study.md index 969af7d1..5c6dc4a8 100644 --- a/case-study.md +++ b/case-study.md @@ -239,6 +239,62 @@ flat Коммитим изменение и пересматриваем входные данные метрики. + +### Ваша находка №8 +- какой отчёт показал главную точку роста + + Кажется, нам больше не нужны кардинальные изменения для достижения бюджетной метрики. + Судя по отчету flat, мы продолжаем тратить много времени в each / map. + + %self total self wait child calls name location + 21.48 0.112 0.030 0.000 0.083 1540 *Array#each + 15.17 0.032 0.021 0.000 0.011 7682 *Array#map + 9.94 0.014 0.014 0.000 0.000 10001 String#split + 7.74 0.023 0.011 0.000 0.012 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:54 + 6.45 0.009 0.009 0.000 0.000 33856 String#upcase + 5.94 0.008 0.008 0.000 0.000 9217 Array#sort + 4.30 0.006 0.006 0.000 0.000 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:37 + 2.97 0.036 0.004 0.000 0.032 6144 User#browsers /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:25 + 2.79 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.57 0.004 0.004 0.000 0.000 1 #write + 2.08 0.003 0.003 0.000 0.000 1 #read + 1.89 0.004 0.003 0.000 0.001 1536 Array#any? + 1.67 0.002 0.002 0.000 0.000 9407 String#include? + 1.57 0.002 0.002 0.000 0.000 8464 String#to_i + 1.47 0.002 0.002 0.000 0.000 10000 String#start_with? + 1.35 0.002 0.002 0.000 0.000 1537 Array#join + 1.34 0.003 0.002 0.000 0.001 1536 Array#all? + + +- как вы решили её оптимизировать + +Во-первых, `upcase` по браузеру мы можем выполнять сразу при добавлении сессии пользователю (и дальше не дублировать это при построении отчета). +Во-вторых, (кажется, мы мало что можем сделать с определением `alwaysUsedChrome` - т.к. все равно придется проверить все сессии пользователя), но что касается `usedIE` - мы можем делать это при добавлении сессии, и сохранять это в переменной пользователя, чтобы дальше обращаться при построении отчета к ней. + +- как изменилась метрика + +Улучшилась: +2sec -> 1.67sec +Но в бюджет пока не пролезаем. + +- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + +Веса перераспределилилсь. + + %self total self wait child calls name location + 28.05 0.091 0.029 0.000 0.062 1540 *Array#each + 12.65 0.013 0.013 0.000 0.000 10001 String#split + 12.29 0.026 0.013 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:60 + 11.35 0.014 0.012 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:40 + 3.29 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 3.02 0.003 0.003 0.000 0.000 3073 Array#sort + 2.91 0.003 0.003 0.000 0.000 1538 Array#map + 2.58 0.003 0.003 0.000 0.000 10443 String#include? + 2.28 0.002 0.002 0.000 0.000 8464 String#upcase + 2.10 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 2.08 0.002 0.002 0.000 0.000 8464 String#to_i + 1.95 0.002 0.002 0.000 0.000 10000 String#start_with? + ### Ваша находка №X - какой отчёт показал главную точку роста - как вы решили её оптимизировать diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html index 37392835..09091c2e 100644 --- a/profiling/ruby_prof_reports/callstack.html +++ b/profiling/ruby_prof_reports/callstack.html @@ -162,7 +162,7 @@
Profile Report

Wall_time

-
Thursday, October 19 at 9:12:28 AM (MSK)
+
Thursday, October 19 at 10:21:42 AM (MSK)
@@ -178,7 +178,7 @@

Wall_time

260 240 - 0.13126262900186703 + 0.11642924600164406 @@ -208,11 +208,11 @@

Thread 260, Fiber: 240

100.00% - 0.02% - 0.13 + 0.01% + 0.12 0.00 0.00 - 0.13 + 0.12 1 @@ -232,10 +232,10 @@

Thread 260, Fiber: 240

    - 0.13 + 0.12 0.00 0.00 - 0.13 + 0.12 1/1 Object#work @@ -254,10 +254,10 @@

Thread 260, Fiber: 240

    - 0.13 + 0.12 0.00 0.00 - 0.13 + 0.12 1/1 [global]# @@ -265,12 +265,12 @@

Thread 260, Fiber: 240

- 99.98% - 0.11% - 0.13 + 99.99% + 0.08% + 0.12 0.00 0.00 - 0.13 + 0.12 1 @@ -280,7 +280,7 @@

Thread 260, Fiber: 240

- 150 + 153 @@ -290,27 +290,27 @@

Thread 260, Fiber: 240

    - 0.07 + 0.06 0.00 0.00 - 0.07 + 0.06 1/1 - Object#build_report + Object#parse_lines - 155 + 157     - 0.05 + 0.04 0.00 0.00 - 0.05 + 0.04 1/1 - Object#parse_lines + Object#build_report - 154 + 158 @@ -323,7 +323,7 @@

Thread 260, Fiber: 240

1/1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 157 + 160 @@ -336,7 +336,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#read - 153 + 156 @@ -349,7 +349,7 @@

Thread 260, Fiber: 240

1/10001 String#split - 153 + 156 @@ -362,7 +362,7 @@

Thread 260, Fiber: 240

1/1 <Class::IO>#write - 157 + 160 @@ -373,9 +373,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#enable + <Module::GC>#disable - 159 + 154 @@ -386,9 +386,9 @@

Thread 260, Fiber: 240

0.00 0.00 1/1 - <Module::GC>#disable + <Module::GC>#enable - 151 + 162 @@ -447,31 +447,31 @@

Thread 260, Fiber: 240

0.00 0.03 1/1540 - Object#parse_lines + Object#collect_stats_from_users - 104 + 69     - 0.06 + 0.05 0.01 0.00 - 0.05 + 0.04 1/1540 - Object#collect_stats_from_users + Object#parse_lines - 66 + 107 - 83.41% - 22.19% - 0.11 + 85.04% + 25.99% + 0.10 0.03 0.00 - 0.08 + 0.07 1540 @@ -491,27 +491,27 @@

Thread 260, Fiber: 240

    - 0.02 + 0.03 0.01 0.00 0.01 8464/8464 Object#parse_session - 105 + 108     0.01 + 0.01 0.00 0.00 - 0.01 - 1536/1536 - User#used_internet_explorer? + 8464/8464 + User#add_session - 73 + 111 @@ -520,11 +520,11 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 + 0.00 1536/1536 User#always_used_chrome? - 73 + 76 @@ -533,37 +533,24 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 - 1536/6144 - User#browsers - - 73 - - - -   -   - 0.01 - 0.01 - 0.00 0.00 - 8464/8464 - User#add_session + 1536/1536 + User#longest_session - 108 + 76     - 0.01 0.00 0.00 0.00 - 1536/1536 - User#longest_session + 0.00 + 3072/3073 + Array#sort - 73 + 76 @@ -573,10 +560,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Object#parse_user + 1536/4608 + User#browsers - 99 + 76 @@ -589,7 +576,7 @@

Thread 260, Fiber: 240

1536/1536 Class#new - 100 + 103 @@ -599,10 +586,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/9217 - Array#sort + 1536/1536 + Object#parse_user - 73 + 102 @@ -612,10 +599,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/7682 + 1536/6146 Array#map - 73 + 76 @@ -628,7 +615,7 @@

Thread 260, Fiber: 240

10000/10000 String#start_with? - 96 + 99 @@ -641,7 +628,7 @@

Thread 260, Fiber: 240

1536/1537 Array#join - 73 + 76 @@ -654,7 +641,7 @@

Thread 260, Fiber: 240

1536/1536 Hash#merge - 73 + 76 @@ -667,7 +654,7 @@

Thread 260, Fiber: 240

3072/3072 Integer#to_s - 73 + 76 @@ -680,7 +667,117 @@

Thread 260, Fiber: 240

1536/1536 Array#reverse - 73 + 76 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1536/1536 + User#used_internet_explorer? + + 76 + + + + + + + + + + + + +   +   + 0.06 + 0.00 + 0.00 + 0.06 + 1/1 + Object#work + + 157 + + + + 54.31% + 0.01% + 0.06 + 0.00 + 0.00 + 0.06 + 1 + + + Object#parse_lines + + + + + + 97 + + + + + + + +   +   + 0.05 + 0.01 + 0.00 + 0.04 + 1/1540 + Array#each + + 107 + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Enumerable#each_with_object + + 101 + + + +   +   + 0.01 + 0.00 + 0.00 + 0.01 + 1/1 + Enumerable#group_by + + 99 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 2/2 + Hash#values + + 99 @@ -695,23 +792,23 @@

Thread 260, Fiber: 240

    - 0.07 + 0.04 0.00 0.00 - 0.07 + 0.04 1/1 Object#work - 155 + 158 - 51.19% + 36.96% 0.02% - 0.07 + 0.04 0.00 0.00 - 0.07 + 0.04 1 @@ -721,7 +818,7 @@

Thread 260, Fiber: 240

- 114 + 117 @@ -731,14 +828,14 @@

Thread 260, Fiber: 240

    - 0.06 + 0.04 0.00 0.00 - 0.06 + 0.04 1/1 Object#collect_stats_from_users - 145 + 148 @@ -747,11 +844,11 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 - 2/7682 + 0.00 + 2/6146 Array#map - 135 + 138 @@ -764,7 +861,7 @@

Thread 260, Fiber: 240

1/1 Array#flatten - 135 + 138 @@ -777,7 +874,7 @@

Thread 260, Fiber: 240

2/2 Array#uniq - 135 + 138 @@ -787,10 +884,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/9217 + 1/3073 Array#sort - 140 + 143 @@ -803,7 +900,7 @@

Thread 260, Fiber: 240

1/1537 Array#join - 140 + 143 @@ -816,7 +913,7 @@

Thread 260, Fiber: 240

1/1 Array#sum - 138 + 141 @@ -829,7 +926,7 @@

Thread 260, Fiber: 240

2/2 Array#count - 132 + 135 @@ -844,23 +941,23 @@

Thread 260, Fiber: 240

    - 0.06 + 0.04 0.00 0.00 - 0.06 + 0.04 1/1 Object#build_report - 145 + 148 - 42.27% + 30.78% 0.00% - 0.06 + 0.04 0.00 0.00 - 0.06 + 0.04 1 @@ -870,7 +967,7 @@

Thread 260, Fiber: 240

- 65 + 68 @@ -880,14 +977,14 @@

Thread 260, Fiber: 240

    - 0.06 + 0.04 0.01 0.00 - 0.05 + 0.03 1/1540 Array#each - 66 + 69 @@ -902,33 +999,33 @@

Thread 260, Fiber: 240

    - 0.05 - 0.00 + 0.03 + 0.01 0.00 - 0.05 - 1/1 - Object#work + 0.01 + 8464/8464 + Array#each - 154 + - 41.18% - 0.01% - 0.05 - 0.00 + 23.39% + 10.75% + 0.03 + 0.01 0.00 - 0.05 - 1 + 0.01 + 8464 - - Object#parse_lines + + Object#parse_session - 94 + 57 @@ -938,40 +1035,27 @@

Thread 260, Fiber: 240

    - 0.04 0.01 - 0.00 - 0.03 - 1/1540 - Array#each - - 104 - - - -   -   0.01 0.00 0.00 - 0.01 - 1/1 - Enumerable#each_with_object + 8464/10001 + String#split - 98 + 58     - 0.01 0.00 0.00 - 0.01 - 1/1 - Enumerable#group_by + 0.00 + 0.00 + 8464/8464 + String#upcase - 96 + 60 @@ -981,10 +1065,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 2/2 - Hash#values + 8464/8464 + String#to_i - 96 + 60 @@ -999,104 +1083,65 @@

Thread 260, Fiber: 240

    - 0.01 0.00 0.00 - 0.01 - 1536/6144 - User#always_used_chrome? - - 34 - - - -   -   - 0.01 0.00 0.00 - 0.01 - 1536/6144 - User#used_internet_explorer? + 1536/10001 + Object#parse_user - 30 + 48     - 0.01 0.00 0.00 - 0.01 - 1536/6144 - Array#each + 0.00 + 0.00 + 1/10001 + Object#work - + 156     0.01 + 0.01 0.00 0.00 - 0.01 - 1536/6144 - Array#map + 8464/10001 + Object#parse_session - + 58 - 25.17% - 2.99% - 0.03 + 11.92% + 11.92% + 0.01 + 0.01 0.00 0.00 - 0.03 - 6144 + 10001 - - User#browsers + + String#split - 25 + - -   -   - 0.02 - 0.02 - 0.00 - 0.01 - 6144/7682 - Array#map - - 26 - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 6144/9217 - Array#sort - - 26 - - @@ -1113,7 +1158,7 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/7682 + 1536/6146 Array#each @@ -1125,34 +1170,34 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 - 2/7682 + 0.00 + 2/6146 Object#build_report - 135 + 138     - 0.02 - 0.02 - 0.00 0.01 - 6144/7682 + 0.01 + 0.00 + 0.00 + 4608/6146 User#browsers - 26 + 28 - 22.50% - 14.38% - 0.03 - 0.02 - 0.00 + 11.16% + 10.41% + 0.01 0.01 - 7682 + 0.00 + 0.00 + 6146 *Array#map @@ -1171,27 +1216,14 @@

Thread 260, Fiber: 240

    - 0.01 0.00 0.00 - 0.01 - 1536/6144 - User#browsers - - - - - -   -   - 0.01 - 0.01 0.00 0.00 - 33856/33856 - String#upcase + 1536/4608 + User#browsers - 26 + @@ -1206,10 +1238,10 @@

Thread 260, Fiber: 240

    - 0.02 0.01 - 0.00 0.01 + 0.00 + 0.00 8464/8464 Array#each @@ -1217,22 +1249,22 @@

Thread 260, Fiber: 240

- 17.22% - 8.20% - 0.02 + 9.75% + 7.81% 0.01 - 0.00 0.01 + 0.00 + 0.00 8464 - - Object#parse_session + + User#add_session - 54 + 39 @@ -1242,27 +1274,14 @@

Thread 260, Fiber: 240

    - 0.01 - 0.01 0.00 0.00 - 8464/10001 - String#split - - 55 - - - -   -   0.00 0.00 - 0.00 - 0.00 - 8464/8464 - String#to_i + 8464/10443 + String#include? - 57 + 43 @@ -1281,10 +1300,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/10001 - Object#parse_user + 1536/4608 + User#always_used_chrome? - 45 + 36 @@ -1294,87 +1313,42 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/10001 - Object#work + 1536/4608 + Array#each - 153 +     - 0.01 - 0.01 0.00 0.00 - 8464/10001 - Object#parse_session - - 55 - - - - 10.53% - 10.53% - 0.01 - 0.01 - 0.00 - 0.00 - 10001 - - - String#split - - - - - - - - - - - - - - - - - - - - - - -   -   - 0.01 0.00 0.00 - 0.01 - 1536/1536 - Array#each + 1536/4608 + Array#map - 9.54% - 0.78% + 9.50% + 1.99% 0.01 0.00 0.00 0.01 - 1536 + 4608 - - User#used_internet_explorer? + + User#browsers - 29 + 26 @@ -1385,26 +1359,13 @@

Thread 260, Fiber: 240

    0.01 - 0.00 - 0.00 0.01 - 1536/6144 - User#browsers - - 30 - - - -   -   - 0.00 - 0.00 0.00 0.00 - 1536/1536 - Array#any? + 4608/6146 + Array#map - 30 + 28 @@ -1423,29 +1384,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.01 - 1536/1536 - Array#each + 1/1 + Object#parse_lines - + 101 - 8.54% - 0.75% + 7.24% + 0.00% 0.01 0.00 0.00 0.01 - 1536 + 1 - - User#always_used_chrome? + + Enumerable#each_with_object - 33 + @@ -1459,23 +1420,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.01 - 1536/6144 - User#browsers - - 34 - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1536 - Array#all? + 1/1540 + Array#each - 34 + @@ -1497,11 +1445,11 @@

Thread 260, Fiber: 240

1/1 Object#parse_lines - 98 + 99 - 7.42% + 5.21% 0.01% 0.01 0.00 @@ -1509,8 +1457,8 @@

Thread 260, Fiber: 240

0.01 1 - - Enumerable#each_with_object + + Enumerable#group_by @@ -1529,7 +1477,7 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 + 0.00 1/1540 Array#each @@ -1549,47 +1497,38 @@

Thread 260, Fiber: 240

    0.01 - 0.01 0.00 0.00 - 33856/33856 - Array#map + 0.00 + 1536/1536 + Array#each - 6.22% - 6.22% - 0.01 + 5.17% + 0.89% 0.01 0.00 0.00 - 33856 + 0.00 + 1536 - - String#upcase + + User#always_used_chrome? - + 35 - - - - - - - - -     @@ -1597,10 +1536,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/9217 - Object#build_report + 1536/4608 + User#browsers - 140 + 36 @@ -1610,48 +1549,12 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3072/9217 - Array#each - - - - - -   -   - 0.01 - 0.01 - 0.00 - 0.00 - 6144/9217 - User#browsers + 1536/1536 + Array#all? - 26 + 36 - - 6.06% - 6.06% - 0.01 - 0.01 - 0.00 - 0.00 - 9217 - - - Array#sort - - - - - - - - - - - - @@ -1667,30 +1570,30 @@

Thread 260, Fiber: 240

0.01 0.00 0.00 - 0.01 - 1/1 - Object#parse_lines + 0.00 + 1536/1536 + Array#each - 96 + - 4.62% - 0.01% + 4.75% + 0.73% 0.01 0.00 0.00 - 0.01 - 1 + 0.00 + 1536 - - Enumerable#group_by + + User#longest_session - + 22 @@ -1700,61 +1603,16 @@

Thread 260, Fiber: 240

    - 0.01 - 0.00 0.00 0.00 - 1/1540 - Array#each - - - - - - - - - - - - - - -   -   - 0.01 - 0.01 0.00 0.00 - 8464/8464 - Array#each + 1536/1536 + Enumerable#max_by - + 23 - - 4.48% - 4.48% - 0.01 - 0.01 - 0.00 - 0.00 - 8464 - - - User#add_session - - - - - - 37 - - - - - - @@ -1767,33 +1625,33 @@

Thread 260, Fiber: 240

    - 0.01 + 0.00 0.00 0.00 0.00 1536/1536 - Array#each + User#longest_session - + 23 - 4.10% - 0.62% - 0.01 + 4.02% + 0.77% + 0.00 0.00 0.00 0.00 1536 - - User#longest_session + + Enumerable#max_by - 21 + @@ -1807,10 +1665,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Enumerable#max_by + 1536/1540 + Array#each - 22 + @@ -1829,23 +1687,36 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#longest_session + 1/3073 + Object#build_report + + 143 + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 3072/3073 + Array#each - 22 + - 3.48% - 0.69% + 2.99% + 2.99% 0.00 0.00 0.00 0.00 - 1536 + 3073 - - Enumerable#max_by + + Array#sort @@ -1858,19 +1729,6 @@

Thread 260, Fiber: 240

- -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 1536/1540 - Array#each - - - - @@ -1890,12 +1748,12 @@

Thread 260, Fiber: 240

1/1 Object#work - 157 + 160 - 2.95% - 2.95% + 2.90% + 2.89% 0.00 0.00 0.00 @@ -1946,22 +1804,22 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - User#used_internet_explorer? + Array#each - 30 + - 2.91% - 1.94% + 2.66% + 1.04% 0.00 0.00 0.00 0.00 1536 - - Array#any? + + Class#new @@ -1981,10 +1839,10 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 5839/9407 - String#include? + 1536/1536 + User#initialize - 30 + @@ -2010,8 +1868,8 @@

Thread 260, Fiber: 240

- 2.79% - 1.41% + 2.56% + 1.29% 0.00 0.00 0.00 @@ -2025,7 +1883,7 @@

Thread 260, Fiber: 240

- 44 + 47 @@ -2042,7 +1900,7 @@

Thread 260, Fiber: 240

1536/10001 String#split - 45 + 48 @@ -2061,23 +1919,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 156 - 2.42% - 1.02% + 2.52% + 2.52% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Class#new + + <Class::IO>#read @@ -2090,6 +1948,15 @@

Thread 260, Fiber: 240

+ + + + + + + + +     @@ -2097,21 +1964,12 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#initialize + 1979/10443 + Array#all? - + - - - - - - - - -     @@ -2119,23 +1977,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 8464/10443 + User#add_session - 153 + 43 - 2.12% - 2.12% + 2.46% + 2.46% 0.00 0.00 0.00 0.00 - 1 + 10443 - - <Class::IO>#read + + String#include? @@ -2164,23 +2022,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - User#always_used_chrome? + 8464/8464 + Object#parse_session - 34 + 60 - 1.96% - 1.34% + 2.09% + 2.09% 0.00 0.00 0.00 0.00 - 1536 + 8464 - - Array#all? + + String#upcase @@ -2193,19 +2051,6 @@

Thread 260, Fiber: 240

- -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 3568/9407 - String#include? - - 34 - - @@ -2222,36 +2067,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 3568/9407 - Array#all? - - - - - -   -   - 0.00 - 0.00 - 0.00 - 0.00 - 5839/9407 - Array#any? + 8464/8464 + Object#parse_session - + 60 - 1.59% - 1.59% + 1.83% + 1.83% 0.00 0.00 0.00 0.00 - 9407 + 8464 - - String#include? + + String#to_i @@ -2280,23 +2112,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 8464/8464 - Object#parse_session + 10000/10000 + Array#each - 57 + - 1.58% - 1.58% + 1.69% + 1.69% 0.00 0.00 0.00 0.00 - 8464 + 10000 - - String#to_i + + String#start_with? @@ -2325,29 +2157,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 10000/10000 - Array#each + 1536/1536 + Class#new - 1.52% - 1.52% + 1.61% + 1.61% 0.00 0.00 0.00 0.00 - 10000 + 1536 - - String#start_with? + + User#initialize - + 11 @@ -2371,34 +2203,47 @@

Thread 260, Fiber: 240

0.00 0.00 1536/1536 - Class#new + User#always_used_chrome? - + 36 - 1.41% - 1.41% + 1.51% + 0.99% 0.00 0.00 0.00 0.00 1536 - - User#initialize + + Array#all? - 11 + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1979/10443 + String#include? + + 36 + + @@ -2418,7 +2263,7 @@

Thread 260, Fiber: 240

1/1537 Object#build_report - 140 + 143 @@ -2435,8 +2280,8 @@

Thread 260, Fiber: 240

- 1.31% - 1.31% + 1.44% + 1.44% 0.00 0.00 0.00 @@ -2473,23 +2318,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1536/1536 - Array#each + 1/1 + Object#work - + 160 - 0.92% - 0.92% + 1.29% + 1.29% 0.00 0.00 0.00 0.00 - 1536 + 1 - - Hash#merge + + <Class::IO>#write @@ -2518,23 +2363,23 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 157 + - 0.72% - 0.72% + 1.10% + 1.10% 0.00 0.00 0.00 0.00 - 1 + 1536 - - <Class::IO>#write + + Hash#merge @@ -2566,12 +2411,12 @@

Thread 260, Fiber: 240

1/1 Object#build_report - 135 + 138 - 0.60% - 0.60% + 0.79% + 0.79% 0.00 0.00 0.00 @@ -2615,8 +2460,8 @@

Thread 260, Fiber: 240

- 0.60% - 0.60% + 0.78% + 0.78% 0.00 0.00 0.00 @@ -2656,12 +2501,12 @@

Thread 260, Fiber: 240

2/2 Object#build_report - 135 + 138 - 0.56% - 0.56% + 0.78% + 0.78% 0.00 0.00 0.00 @@ -2705,8 +2550,8 @@

Thread 260, Fiber: 240

- 0.34% - 0.34% + 0.52% + 0.52% 0.00 0.00 0.00 @@ -2743,29 +2588,29 @@

Thread 260, Fiber: 240

0.00 0.00 0.00 - 1/1 - Object#work + 1536/1536 + Array#each - 159 + - 0.01% - 0.01% + 0.47% + 0.47% 0.00 0.00 0.00 0.00 - 1 + 1536 - - <Module::GC>#enable + + User#used_internet_explorer? - 72 + 31 @@ -2791,7 +2636,7 @@

Thread 260, Fiber: 240

2/2 Object#parse_lines - 96 + 99 @@ -2836,12 +2681,12 @@

Thread 260, Fiber: 240

1/1 Object#build_report - 138 + 141 - 0.00% - 0.00% + 0.01% + 0.01% 0.00 0.00 0.00 @@ -2881,7 +2726,7 @@

Thread 260, Fiber: 240

1/1 Object#work - 151 + 154 @@ -2905,6 +2750,51 @@

Thread 260, Fiber: 240

+ + + + + + + + + + + + +   +   + 0.00 + 0.00 + 0.00 + 0.00 + 1/1 + Object#work + + 162 + + + + 0.00% + 0.00% + 0.00 + 0.00 + 0.00 + 0.00 + 1 + + + <Module::GC>#enable + + + + + + 72 + + + + @@ -2926,7 +2816,7 @@

Thread 260, Fiber: 240

2/2 Object#build_report - 132 + 135 diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index c96f0e71..0080c834 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,51 +1,48 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.143747 +Total: 0.101798 Sort by: self_time %self total self wait child calls name location - 20.56 0.122 0.030 0.000 0.092 1540 *Array#each - 20.03 0.042 0.029 0.000 0.013 12290 *Array#map - 9.30 0.013 0.013 0.000 0.000 10001 String#split - 7.67 0.023 0.011 0.000 0.012 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:54 - 5.80 0.008 0.008 0.000 0.000 33856 String#upcase - 5.60 0.008 0.008 0.000 0.000 9217 Array#sort - 4.06 0.006 0.006 0.000 0.000 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:37 - 2.85 0.004 0.004 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 2.79 0.034 0.004 0.000 0.030 6144 User#browsers /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:25 - 1.88 0.003 0.003 0.000 0.000 1 #read - 1.79 0.004 0.003 0.000 0.001 1536 Array#any? - 1.59 0.002 0.002 0.000 0.000 8464 Integer#to_i :130 - 1.58 0.002 0.002 0.000 0.000 9407 String#include? - 1.42 0.002 0.002 0.000 0.000 8464 String#to_i - 1.37 0.002 0.002 0.000 0.000 10000 String#start_with? - 1.25 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 - 1.21 0.002 0.002 0.000 0.000 1537 Array#join - 1.19 0.003 0.002 0.000 0.001 1536 Array#all? - 1.01 0.003 0.001 0.000 0.002 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:44 - 0.84 0.001 0.001 0.000 0.000 1536 Hash#merge - 0.82 0.003 0.001 0.000 0.002 1536 Class#new - 0.77 0.013 0.001 0.000 0.012 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:29 - 0.73 0.012 0.001 0.000 0.011 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:33 - 0.62 0.003 0.001 0.000 0.002 1536 Enumerable#max_by - 0.60 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.59 0.001 0.001 0.000 0.000 1 Array#flatten - 0.55 0.004 0.001 0.000 0.003 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:21 - 0.54 0.001 0.001 0.000 0.000 1 #write - 0.52 0.001 0.001 0.000 0.000 2 Array#uniq - 0.32 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.08 0.144 0.000 0.000 0.144 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:154 - 0.02 0.081 0.000 0.000 0.081 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:114 - 0.01 0.000 0.000 0.000 0.000 3 Hash#values - 0.01 0.144 0.000 0.000 0.144 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.01 0.053 0.000 0.000 0.053 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:94 - 0.01 0.000 0.000 0.000 0.000 1 #enable :72 - 0.00 0.006 0.000 0.000 0.006 1 Enumerable#group_by + 28.05 0.091 0.029 0.000 0.062 1540 *Array#each + 12.65 0.013 0.013 0.000 0.000 10001 String#split + 12.29 0.026 0.013 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:60 + 11.35 0.014 0.012 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:40 + 3.29 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 3.02 0.003 0.003 0.000 0.000 3073 Array#sort + 2.91 0.003 0.003 0.000 0.000 1538 Array#map + 2.58 0.003 0.003 0.000 0.000 10443 String#include? + 2.28 0.002 0.002 0.000 0.000 8464 String#upcase + 2.10 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 2.08 0.002 0.002 0.000 0.000 8464 String#to_i + 1.95 0.002 0.002 0.000 0.000 10000 String#start_with? + 1.62 0.002 0.002 0.000 0.000 1 Array#flatten + 1.47 0.001 0.001 0.000 0.000 1537 Array#join + 1.42 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 + 1.40 0.001 0.001 0.000 0.000 1 #write + 1.23 0.001 0.001 0.000 0.000 1536 Hash#merge + 1.15 0.002 0.001 0.000 0.001 1536 Array#all? + 1.09 0.003 0.001 0.000 0.002 1536 Class#new + 0.90 0.001 0.001 0.000 0.000 1 #read + 0.87 0.001 0.001 0.000 0.000 2 Array#uniq + 0.84 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.82 0.005 0.001 0.000 0.004 1536 Enumerable#max_by + 0.78 0.005 0.001 0.000 0.005 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:23 + 0.72 0.002 0.001 0.000 0.002 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:36 + 0.50 0.001 0.001 0.000 0.000 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:32 + 0.46 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.08 0.102 0.000 0.000 0.102 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:156 + 0.02 0.029 0.000 0.000 0.029 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:120 + 0.02 0.102 0.000 0.000 0.102 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.01 0.065 0.000 0.000 0.065 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:100 + 0.01 0.000 0.000 0.000 0.000 2 Hash#values + 0.01 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object 0.00 0.000 0.000 0.000 0.000 1 #disable :84 0.00 0.000 0.000 0.000 0.000 1 Array#sum - 0.00 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object - 0.00 0.069 0.000 0.000 0.069 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:65 + 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.006 0.000 0.000 0.006 1 Enumerable#group_by + 0.00 0.026 0.000 0.000 0.026 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:71 0.00 0.000 0.000 0.000 0.000 2 Array#count 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize diff --git a/spec/work/performance/budget_spec.rb b/spec/work/performance/budget_spec.rb index 80ca3586..7abf3dde 100644 --- a/spec/work/performance/budget_spec.rb +++ b/spec/work/performance/budget_spec.rb @@ -9,7 +9,7 @@ before { ensure_test_data_exists(size) } - xdescribe 'budget' do + describe 'budget' do let(:file_path) { 'data_large.txt' } it 'is fast as hell' do diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index c2ee4903..23a0e3e7 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -5,7 +5,7 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } let(:size) { 250_000 } - let(:ms) { 2000 } + let(:ms) { 1670 } before { ensure_test_data_exists(size) } diff --git a/task-1.rb b/task-1.rb index 515e5aa6..de5d61f9 100644 --- a/task-1.rb +++ b/task-1.rb @@ -6,7 +6,7 @@ require 'minitest/autorun' class User - attr_reader :id, :first_name, :last_name, :age, :sessions, :sessions_count, :total_time + attr_reader :id, :first_name, :last_name, :age, :sessions, :sessions_count, :total_time, :browsers def initialize(id:, first_name:, last_name:, age:, sessions: []) @id = id @@ -16,18 +16,21 @@ def initialize(id:, first_name:, last_name:, age:, sessions: []) @sessions = sessions @sessions_count = 0 @total_time = 0 + @used_internet_explorer = false + @browsers = [] end def longest_session @sessions.max_by { |s| s['time'] } end - def browsers - @sessions.map { |s| s['browser'].upcase }.sort - end + # def browsers + # # @sessions.map { |s| s['browser'] }.sort + # @sessions.map { |s| s['browser'] } + # end def used_internet_explorer? - browsers.any? { |b| b.include?('INTERNET EXPLORER') } + @used_internet_explorer end def always_used_chrome? @@ -38,6 +41,9 @@ def add_session(session) @sessions << session @sessions_count += 1 @total_time += session['time'] + browser = session['browser'] + @browsers << browser + @used_internet_explorer = true if browser.include?('INTERNET EXPLORER') end end @@ -56,7 +62,7 @@ def parse_session(session) parsed_result = { 'user_id' => fields[1], 'session_id' => fields[2], - 'browser' => fields[3], + 'browser' => fields[3].upcase, 'time' => fields[4].to_i, 'date' => fields[5], } From 9090372a1f7e376b6f1d3b6540bda43d92d7b72e Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 12:04:50 +0300 Subject: [PATCH 22/25] Remove redundant comments --- task-1.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/task-1.rb b/task-1.rb index de5d61f9..d00f1ca9 100644 --- a/task-1.rb +++ b/task-1.rb @@ -24,11 +24,6 @@ def longest_session @sessions.max_by { |s| s['time'] } end - # def browsers - # # @sessions.map { |s| s['browser'] }.sort - # @sessions.map { |s| s['browser'] } - # end - def used_internet_explorer? @used_internet_explorer end @@ -73,9 +68,6 @@ def collect_stats_from_users(report, users) user_key = "#{user.first_name}" + ' ' + "#{user.last_name}" report['usersStats'][user_key] ||= {} - # user_times = user.sessions.map {|s| s['time']}.map {|t| t.to_i} - # user_browsers = user.sessions.map {|s| s['browser']} - report['usersStats'][user_key] = report['usersStats'][user_key].merge( { # # Собираем количество сессий по пользователям @@ -98,7 +90,6 @@ def collect_stats_from_users(report, users) end def parse_lines(file_lines) - # lines = file_lines.sort_by { |l| l} users, sessions = file_lines.group_by { |l| l.start_with?('user') }.values users_objects_by_id = users.each_with_object({}) do |u, acc| From 327e5085a595cba887d27e1f82308c9443cf88a5 Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 12:36:50 +0300 Subject: [PATCH 23/25] Finish case --- case-study.md | 79 +++++++++++++++++++++------- profiling/ruby_prof_reports/flat.txt | 67 ++++++++++++----------- spec/work/correctness_spec.rb | 1 + spec/work/performance/speed_spec.rb | 4 +- task-1.rb | 32 +++++------ 5 files changed, 111 insertions(+), 72 deletions(-) diff --git a/case-study.md b/case-study.md index 5c6dc4a8..b631ab7e 100644 --- a/case-study.md +++ b/case-study.md @@ -17,18 +17,6 @@ ## Гарантия корректности работы оптимизированной программы Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. -```ruby - describe 'ms' do - it 'is equals or better that current implementation' do - expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times - end - - it 'is trying to be better ' do - expect { work(file_path) }.to perform_under(ms/2).ms.warmup(warmup_seconds).times.sample(10).times - end - end -``` - ## Feedback-Loop Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за несколько секунд. @@ -38,9 +26,20 @@ - смотрю на новое время, если оно меня устраивает, коммичу изменение и обновляю значение защитной метрики. ## Вникаем в детали системы, чтобы найти главные точки роста -Для того, чтобы найти "точки роста" для оптимизации я воспользовался *инструментами, которыми вы воспользовались* - -Вот какие проблемы удалось найти и решить +Для того, чтобы найти "точки роста" для оптимизации я воспользовался отчетами ruby-prof (в т.ч. `flat`, `graph`, `callgrind`, `callstack`). + +Вот какие проблемы удалось найти и решить: +- обработка каждой строки файла происходит только один раз; +- для отнесения сессия к тому или иному пользователю, прежде мы выбирали запись из массива, теперь вместо этого используется хэш с ключом `user_id`; +- мы стали хранить атрибуты пользователя не в виде хэша, а в отдельных переменных; +- мы заменили методы работа с массивами на более эффективные (`+= []` на `<<`) +- использовали стандартный метод `Array#uniq` для определения перечня уникальных браузеров; +- мы изавились от дорогостоящей `Date.parse`, в которой не было необходимости; +- для построения отчета мы обходим каждого пользователя только один раз; +- определение вида записи теперь происходит с помощью `String#start_with?`, мы не делаем лишний `String#split`; +- мы выполняем преобразование данных, например, `upcase` или `to_i` в момент парсинга записей, а не каждый раз при обращении к ним; +- мы по возможности сохраняем нужные для отчета данные на раннем этапе (например `usedIE`), таким образом минимизируя работу на этапе построения отчета; +- мы отказались от не нужного использования `Hash#merge` для построения отчета. ### Ваша находка №1 - какой отчёт показал главную точку роста @@ -297,15 +296,59 @@ flat ### Ваша находка №X - какой отчёт показал главную точку роста + +Главную находить все сложнее. Я не вижу, что можно улучшить в верхних строках + +flat: + %self total self wait child calls name location + 1.18 0.001 0.001 0.000 0.000 1536 Hash#merge + - как вы решили её оптимизировать + +Нам не нужен merge. + - как изменилась метрика + +1.67sec -> 1.56sec + - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? + %self total self wait child calls name location + 29.62 0.090 0.030 0.000 0.060 1540 *Array#each + 12.88 0.013 0.013 0.000 0.000 10001 String#split + 12.08 0.026 0.012 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:55 + 11.31 0.014 0.011 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:35 + 3.17 0.003 0.003 0.000 0.000 3073 Array#sort + 2.96 0.003 0.003 0.000 0.000 1 #write + 2.74 0.003 0.003 0.000 0.000 1538 Array#map + 2.69 0.003 0.003 0.000 0.000 10443 String#include? + 2.59 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json + 2.28 0.002 0.002 0.000 0.000 8464 String#upcase + 2.08 0.002 0.002 0.000 0.000 8464 String#to_i + 2.08 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 2.00 0.002 0.002 0.000 0.000 10000 String#start_with? + 1.49 0.002 0.002 0.000 0.000 1537 Array#join + 1.34 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:45 + 1.26 0.001 0.001 0.000 0.000 1 Array#flatten + 1.08 0.002 0.001 0.000 0.000 1536 Array#all? + 1.06 0.003 0.001 0.000 0.002 1536 Class#new + ## Результаты В результате проделанной оптимизации наконец удалось обработать файл с данными. -Удалось улучшить метрику системы с *того, что у вас было в начале, до того, что получилось в конце* и уложиться в заданный бюджет. -*Какими ещё результами можете поделиться* +Удалось улучшить метрику системы с 2_800ms / 10к записей до 46ms / 10к записей и уложиться в заданный бюджет. ## Защита от регрессии производительности -Для защиты от потери достигнутого прогресса при дальнейших изменениях программы *о performance-тестах, которые вы написали* +Для защиты от потери достигнутого прогресса при дальнейших изменениях программы я использовал тест: + +```ruby + describe 'ms' do + it 'is equals or better that current implementation' do + expect { work(file_path) }.to perform_under(ms).ms.warmup(warmup_seconds).times.sample(10).times + end + + it 'is trying to be better ' do + expect { work(file_path) }.to perform_under(ms/2).ms.warmup(warmup_seconds).times.sample(10).times + end + end +``` diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt index 0080c834..3cd83958 100644 --- a/profiling/ruby_prof_reports/flat.txt +++ b/profiling/ruby_prof_reports/flat.txt @@ -1,48 +1,47 @@ Measure Mode: wall_time Thread ID: 260 Fiber ID: 240 -Total: 0.101798 +Total: 0.100531 Sort by: self_time %self total self wait child calls name location - 28.05 0.091 0.029 0.000 0.062 1540 *Array#each - 12.65 0.013 0.013 0.000 0.000 10001 String#split - 12.29 0.026 0.013 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:60 - 11.35 0.014 0.012 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:40 - 3.29 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 3.02 0.003 0.003 0.000 0.000 3073 Array#sort - 2.91 0.003 0.003 0.000 0.000 1538 Array#map - 2.58 0.003 0.003 0.000 0.000 10443 String#include? + 29.62 0.090 0.030 0.000 0.060 1540 *Array#each + 12.88 0.013 0.013 0.000 0.000 10001 String#split + 12.08 0.026 0.012 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:55 + 11.31 0.014 0.011 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:35 + 3.17 0.003 0.003 0.000 0.000 3073 Array#sort + 2.96 0.003 0.003 0.000 0.000 1 #write + 2.74 0.003 0.003 0.000 0.000 1538 Array#map + 2.69 0.003 0.003 0.000 0.000 10443 String#include? + 2.59 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json 2.28 0.002 0.002 0.000 0.000 8464 String#upcase - 2.10 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 2.08 0.002 0.002 0.000 0.000 8464 String#to_i - 1.95 0.002 0.002 0.000 0.000 10000 String#start_with? - 1.62 0.002 0.002 0.000 0.000 1 Array#flatten - 1.47 0.001 0.001 0.000 0.000 1537 Array#join - 1.42 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:50 - 1.40 0.001 0.001 0.000 0.000 1 #write - 1.23 0.001 0.001 0.000 0.000 1536 Hash#merge - 1.15 0.002 0.001 0.000 0.001 1536 Array#all? - 1.09 0.003 0.001 0.000 0.002 1536 Class#new - 0.90 0.001 0.001 0.000 0.000 1 #read - 0.87 0.001 0.001 0.000 0.000 2 Array#uniq - 0.84 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.82 0.005 0.001 0.000 0.004 1536 Enumerable#max_by - 0.78 0.005 0.001 0.000 0.005 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:23 - 0.72 0.002 0.001 0.000 0.002 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:36 - 0.50 0.001 0.001 0.000 0.000 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:32 - 0.46 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.08 0.102 0.000 0.000 0.102 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:156 - 0.02 0.029 0.000 0.000 0.029 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:120 - 0.02 0.102 0.000 0.000 0.102 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.01 0.065 0.000 0.000 0.065 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:100 + 2.08 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 + 2.00 0.002 0.002 0.000 0.000 10000 String#start_with? + 1.49 0.002 0.002 0.000 0.000 1537 Array#join + 1.34 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:45 + 1.26 0.001 0.001 0.000 0.000 1 Array#flatten + 1.08 0.002 0.001 0.000 0.000 1536 Array#all? + 1.06 0.003 0.001 0.000 0.002 1536 Class#new + 0.83 0.001 0.001 0.000 0.000 2 Array#uniq + 0.83 0.004 0.001 0.000 0.003 1536 Enumerable#max_by + 0.77 0.001 0.001 0.000 0.000 3072 Integer#to_s + 0.76 0.005 0.001 0.000 0.004 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:23 + 0.70 0.002 0.001 0.000 0.002 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 + 0.49 0.000 0.000 0.000 0.000 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:27 + 0.43 0.000 0.000 0.000 0.000 1536 Array#reverse + 0.30 0.000 0.000 0.000 0.000 1 #read + 0.08 0.101 0.000 0.000 0.100 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:143 + 0.02 0.029 0.000 0.000 0.029 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:107 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object - 0.00 0.000 0.000 0.000 0.000 1 #disable :84 - 0.00 0.000 0.000 0.000 0.000 1 Array#sum + 0.01 0.101 0.000 0.000 0.101 1 [global]# profiling/ruby_prof_flat.rb:8 + 0.01 0.064 0.000 0.000 0.064 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:88 + 0.01 0.026 0.000 0.000 0.026 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:66 + 0.01 0.000 0.000 0.000 0.000 1 Array#sum 0.00 0.000 0.000 0.000 0.000 1 #enable :72 + 0.00 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object + 0.00 0.000 0.000 0.000 0.000 1 #disable :84 0.00 0.006 0.000 0.000 0.006 1 Enumerable#group_by - 0.00 0.026 0.000 0.000 0.026 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:71 0.00 0.000 0.000 0.000 0.000 2 Array#count 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize diff --git a/spec/work/correctness_spec.rb b/spec/work/correctness_spec.rb index d9bb4b3b..a5d5f8f5 100644 --- a/spec/work/correctness_spec.rb +++ b/spec/work/correctness_spec.rb @@ -34,6 +34,7 @@ it 'generates correct result json' do subject + # binding.irb expect(File.read('result.json')).to eq(expected_result) end end diff --git a/spec/work/performance/speed_spec.rb b/spec/work/performance/speed_spec.rb index 23a0e3e7..ed92aeb4 100644 --- a/spec/work/performance/speed_spec.rb +++ b/spec/work/performance/speed_spec.rb @@ -4,8 +4,8 @@ let(:file_path) { fixture(size) } let(:warmup_seconds) { 1 } - let(:size) { 250_000 } - let(:ms) { 1670 } + let(:size) { 10_000 } + let(:ms) { 1 } before { ensure_test_data_exists(size) } diff --git a/task-1.rb b/task-1.rb index d00f1ca9..f6e5c7ae 100644 --- a/task-1.rb +++ b/task-1.rb @@ -68,24 +68,20 @@ def collect_stats_from_users(report, users) user_key = "#{user.first_name}" + ' ' + "#{user.last_name}" report['usersStats'][user_key] ||= {} - report['usersStats'][user_key] = report['usersStats'][user_key].merge( - { - # # Собираем количество сессий по пользователям - 'sessionsCount' => user.sessions_count, - # # Собираем количество времени по пользователям - 'totalTime' => "#{user.total_time} min.", - # # Выбираем самую длинную сессию пользователя - 'longestSession' => "#{user.longest_session['time']} min.", - # # Браузеры пользователя через запятую - 'browsers' => user.browsers.sort.join(', '), - # # Хоть раз использовал IE? - 'usedIE' => user.used_internet_explorer?, - # # Всегда использовал только Chrome? - 'alwaysUsedChrome' => user.always_used_chrome?, - # # Даты сессий через запятую в обратном порядке в формате iso8601 - 'dates' => user.sessions.map{|s| s['date']}.sort.reverse - } - ) + # # Собираем количество сессий по пользователям + report['usersStats'][user_key]['sessionsCount'] = user.sessions_count + # # Собираем количество времени по пользователям + report['usersStats'][user_key]['totalTime'] = "#{user.total_time} min." + # # Браузеры пользователя через запятую + report['usersStats'][user_key]['longestSession'] = "#{user.longest_session['time']} min." + # # Хоть раз использовал IE? + report['usersStats'][user_key]['browsers'] = user.browsers.sort.join(', ') + # # Выбираем самую длинную сессию пользователя + report['usersStats'][user_key]['usedIE'] = user.used_internet_explorer? + # # Всегда использовал только Chrome? + report['usersStats'][user_key]['alwaysUsedChrome'] = user.always_used_chrome? + # # Даты сессий через запятую в обратном порядке в формате iso8601 + report['usersStats'][user_key]['dates'] = user.sessions.map{|s| s['date']}.sort.reverse end end From ea21ae0b28a2639ffe1019e77b4ffdb53028ec0e Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 12:42:13 +0300 Subject: [PATCH 24/25] Remove reports and update case --- case-study-template.md | 56 - case-study.md | 65 +- .../ruby_prof_reports/callgrind.out.59703 | 402 --- .../ruby_prof_reports/callgrind.out.67404 | 398 --- .../ruby_prof_reports/callgrind.out.86565 | 326 -- profiling/ruby_prof_reports/callstack.html | 2933 ---------------- profiling/ruby_prof_reports/flat.txt | 65 - profiling/ruby_prof_reports/graph.html | 3107 ----------------- 8 files changed, 37 insertions(+), 7315 deletions(-) delete mode 100644 case-study-template.md delete mode 100644 profiling/ruby_prof_reports/callgrind.out.59703 delete mode 100644 profiling/ruby_prof_reports/callgrind.out.67404 delete mode 100644 profiling/ruby_prof_reports/callgrind.out.86565 delete mode 100644 profiling/ruby_prof_reports/callstack.html delete mode 100644 profiling/ruby_prof_reports/flat.txt delete mode 100644 profiling/ruby_prof_reports/graph.html diff --git a/case-study-template.md b/case-study-template.md deleted file mode 100644 index d41034d9..00000000 --- a/case-study-template.md +++ /dev/null @@ -1,56 +0,0 @@ -# Case-study оптимизации - -## Актуальная проблема -В нашем проекте возникла серьёзная проблема. - -Необходимо было обработать файл с данными, чуть больше ста мегабайт. - -У нас уже была программа на `ruby`, которая умела делать нужную обработку. - -Она успешно работала на файлах размером пару мегабайт, но для большого файла она работала слишком долго, и не было понятно, закончит ли она вообще работу за какое-то разумное время. - -Я решил исправить эту проблему, оптимизировав эту программу. - -## Формирование метрики -Для того, чтобы понимать, дают ли мои изменения положительный эффект на быстродействие программы я придумал использовать такую метрику: *тут ваша метрика* - -## Гарантия корректности работы оптимизированной программы -Программа поставлялась с тестом. Выполнение этого теста в фидбек-лупе позволяет не допустить изменения логики программы при оптимизации. - -## Feedback-Loop -Для того, чтобы иметь возможность быстро проверять гипотезы я выстроил эффективный `feedback-loop`, который позволил мне получать обратную связь по эффективности сделанных изменений за *время, которое у вас получилось* - -Вот как я построил `feedback_loop`: *как вы построили feedback_loop* - -## Вникаем в детали системы, чтобы найти главные точки роста -Для того, чтобы найти "точки роста" для оптимизации я воспользовался *инструментами, которыми вы воспользовались* - -Вот какие проблемы удалось найти и решить - -### Ваша находка №1 -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - -### Ваша находка №2 -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - -### Ваша находка №X -- какой отчёт показал главную точку роста -- как вы решили её оптимизировать -- как изменилась метрика -- как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - -## Результаты -В результате проделанной оптимизации наконец удалось обработать файл с данными. -Удалось улучшить метрику системы с *того, что у вас было в начале, до того, что получилось в конце* и уложиться в заданный бюджет. - -*Какими ещё результами можете поделиться* - -## Защита от регрессии производительности -Для защиты от потери достигнутого прогресса при дальнейших изменениях программы *о performance-тестах, которые вы написали* - diff --git a/case-study.md b/case-study.md index b631ab7e..f4e55238 100644 --- a/case-study.md +++ b/case-study.md @@ -43,12 +43,12 @@ ### Ваша находка №1 - какой отчёт показал главную точку роста - +``` %self total self wait child calls name location 87.54 4.276 4.276 0.000 0.000 1536 Array#select 5.07 4.864 0.248 0.000 4.617 10 Array#each 3.27 0.161 0.160 0.000 0.001 10000 Array#all? - +``` Array#select - единственный в программе - как вы решили её оптимизировать @@ -63,10 +63,12 @@ Array#select - единственный в программе - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? +``` %self total self wait child calls name location 39.74 0.567 0.233 0.000 0.334 11 Array#each 27.07 0.159 0.159 0.000 0.001 10000 Array#all? 8.15 0.123 0.048 0.000 0.075 16898 Array#map +``` Да, перестала @@ -76,13 +78,14 @@ Array#select - единственный в программе Смотрим flat + graph. Array#each остается одним из лидеров. Прежде чем приступать к оптимизации, попробуем выделить фрагменты программы в отдельные методы, чтобы было удобнее профилировать. После выделения методов, в graph видно, что значительный вес приходится на split_users_and_sessions: +``` 0.01 0.00 0.00 0.00 1/11 Object#initialize_users 66 0.01 0.01 0.00 0.00 1/11 Object#assign_sessions_to_users 76 0.16 0.01 0.00 0.16 1/11 Object#build_report 105 0.18 0.04 0.00 0.14 7/11 Object#collect_stats_from_users 43 0.22 0.19 0.00 0.03 1/11 Object#split_users_and_sessions 54 96.96% 40.00% 0.57 0.24 0.00 0.34 11 Array#each - +``` - как вы решили её оптимизировать Изменили способ пополнения массивов с `+= []` на `<<`. @@ -94,14 +97,16 @@ Array#select - единственный в программе - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? перестала: +``` 94.94% 14.52% 0.39 0.06 0.00 0.33 11 Array#each - +``` +``` %self total self wait child calls name location 39.45 0.161 0.161 0.000 0.001 10000 Array#all? 14.00 0.386 0.057 0.000 0.329 11 Array#each 11.56 0.118 0.047 0.000 0.071 16898 Array#map 6.80 0.059 0.028 0.000 0.031 8464 #parse - +``` ### Ваша находка №3 - какой отчёт показал главную точку роста @@ -118,12 +123,12 @@ flat - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? перестала: - +``` %self total self wait child calls name location 21.41 0.234 0.055 0.000 0.179 10 Array#each 19.68 0.127 0.050 0.000 0.076 16899 Array#map 11.45 0.063 0.029 0.000 0.034 8464 #parse - +``` ### Увеличиваем объем тестового файла (и соответственно метрику) size: 10k -> 50k @@ -133,11 +138,12 @@ ms: 180ms -> 900ms - какой отчёт показал главную точку роста flat + callstack +``` %self total self wait child calls name location 21.54 0.218 0.051 0.000 0.167 10 Array#each 19.27 0.116 0.046 0.000 0.071 16899 Array#map 11.12 0.058 0.026 0.000 0.031 8464 #parse - +``` - как вы решили её оптимизировать При формировании 'dates' использование `Date.parse` (дорогого) с последующим переводом в `iso8601` кажется избыточным убрали (имеющийся тест проходит). @@ -149,22 +155,22 @@ flat + callstack - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? перестала. - +``` %self total self wait child calls name location 30.86 0.146 0.052 0.000 0.095 10 Array#each 24.53 0.049 0.041 0.000 0.008 13827 Array#map 13.54 0.023 0.023 0.000 0.000 20001 String#split 5.51 0.018 0.009 0.000 0.009 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - +``` ### Ваша находка №5 - какой отчёт показал главную точку роста callstack - +``` 0.10 0.03 0.00 0.06 7/10 Object#collect_stats_from_users 43 84.71% 29.32% 0.15 0.05 0.00 0.10 10 Array#each 0.04 0.03 0.00 0.01 13824/13827 Array#map 129 - +``` - как вы решили её оптимизировать `collect_stats_from_users` повторно пробегается по каждому из пользователей для формирования отдельных метрик. Попробуем сменить подход - пробегать пользователей один раз, но собирать сразу все метрики по нему. @@ -176,20 +182,21 @@ callstack 620ms -> 460ms - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - +``` 0.05 0.01 0.00 0.04 1/4 Object#collect_stats_from_users 43 82.70% 23.50% 0.11 0.03 0.00 0.08 4 Array#each 0.02 0.02 0.00 0.00 7680/7683 Array#map 47 - +``` ### Ваша находка №6 - какой отчёт показал главную точку роста Flat: +``` %self total self wait child calls name location 22.99 0.100 0.029 0.000 0.071 4 Array#each 19.44 0.031 0.025 0.000 0.006 7683 Array#map 18.74 0.024 0.024 0.000 0.000 20001 String#split - +``` Split в числе лидеров. - как вы решили её оптимизировать @@ -201,19 +208,20 @@ Split в числе лидеров. 460ms -> 320ms - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - +``` %self total self wait child calls name location 24.79 0.095 0.029 0.000 0.066 4 Array#each 20.47 0.030 0.024 0.000 0.006 7683 Array#map 10.73 0.013 0.013 0.000 0.000 10001 String#split - +``` ### Ваша находка №7 - какой отчёт показал главную точку роста flat +``` %self total self wait child calls name location 24.83 0.110 0.033 0.000 0.076 4 Array#each - +``` `each` выполняется 4 раза в программе, хотя мы должны это кол-во минимизировть. Кажется, и вся "сложность" алгоритма отсюда. - как вы решили её оптимизировать @@ -229,13 +237,13 @@ flat - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? Отчет изменился не значительно. - +``` %self total self wait child calls name location 20.56 0.122 0.030 0.000 0.092 1540 *Array#each 20.03 0.042 0.029 0.000 0.013 12290 *Array#map 9.30 0.013 0.013 0.000 0.000 10001 String#split 7.67 0.023 0.011 0.000 0.012 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:54 - +``` Коммитим изменение и пересматриваем входные данные метрики. @@ -244,7 +252,7 @@ flat Кажется, нам больше не нужны кардинальные изменения для достижения бюджетной метрики. Судя по отчету flat, мы продолжаем тратить много времени в each / map. - +``` %self total self wait child calls name location 21.48 0.112 0.030 0.000 0.083 1540 *Array#each 15.17 0.032 0.021 0.000 0.011 7682 *Array#map @@ -263,7 +271,7 @@ flat 1.47 0.002 0.002 0.000 0.000 10000 String#start_with? 1.35 0.002 0.002 0.000 0.000 1537 Array#join 1.34 0.003 0.002 0.000 0.001 1536 Array#all? - +``` - как вы решили её оптимизировать @@ -279,7 +287,7 @@ flat - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? Веса перераспределилилсь. - +``` %self total self wait child calls name location 28.05 0.091 0.029 0.000 0.062 1540 *Array#each 12.65 0.013 0.013 0.000 0.000 10001 String#split @@ -293,16 +301,17 @@ flat 2.10 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 2.08 0.002 0.002 0.000 0.000 8464 String#to_i 1.95 0.002 0.002 0.000 0.000 10000 String#start_with? - -### Ваша находка №X +``` +### Ваша находка №9 - какой отчёт показал главную точку роста Главную находить все сложнее. Я не вижу, что можно улучшить в верхних строках flat: +``` %self total self wait child calls name location 1.18 0.001 0.001 0.000 0.000 1536 Hash#merge - +``` - как вы решили её оптимизировать Нам не нужен merge. @@ -312,7 +321,7 @@ flat: 1.67sec -> 1.56sec - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? - +``` %self total self wait child calls name location 29.62 0.090 0.030 0.000 0.060 1540 *Array#each 12.88 0.013 0.013 0.000 0.000 10001 String#split @@ -332,7 +341,7 @@ flat: 1.26 0.001 0.001 0.000 0.000 1 Array#flatten 1.08 0.002 0.001 0.000 0.000 1536 Array#all? 1.06 0.003 0.001 0.000 0.002 1536 Class#new - +``` ## Результаты В результате проделанной оптимизации наконец удалось обработать файл с данными. diff --git a/profiling/ruby_prof_reports/callgrind.out.59703 b/profiling/ruby_prof_reports/callgrind.out.59703 deleted file mode 100644 index d09654fe..00000000 --- a/profiling/ruby_prof_reports/callgrind.out.59703 +++ /dev/null @@ -1,402 +0,0 @@ -events: wall_time - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::enable^ -72 5 - -fl= -fn=IO::write^ -0 574 - -fl= -fn=JSON/Ext/Generator/State::initialize -0 1 - -fl= -fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -0 3645 -cfl= -cfn=JSON/Ext/Generator/State::initialize -calls=1 0 -0 1 - -fl= -fn=Date::iso8601 -0 4549 - -fl= -fn=Array::reverse -0 488 - -fl= -fn=Date::<=> -0 3371 - -fl= -fn=Integer::div -0 1716 - -fl= -fn=String::[]= -0 2640 - -fl= -fn=MatchData::end -0 1454 - -fl= -fn=MatchData::begin -0 6146 - -fl= -fn=Regexp::match -0 13076 - -fl= -fn=String::gsub! -0 7083 - -fl= -fn=Date::parse^ -0 27793 -cfl= -cfn=String::gsub! -calls=8464 0 -0 7083 -cfl= -cfn=Regexp::match -calls=16928 0 -0 13076 -cfl= -cfn=MatchData::begin -calls=8464 0 -0 6146 -cfl= -cfn=MatchData::end -calls=8464 0 -0 1454 -cfl= -cfn=String::[]= -calls=8464 0 -0 2640 -cfl= -cfn=Integer::div -calls=8464 0 -0 1716 - -fl= -fn=Array::any? -0 3744 -cfl= -cfn=String::upcase -calls=4492 149 -149 1275 - -fl= -fn=Array::max -0 385 - -fl= -fn=String::+ -0 893 - -fl= -fn=Integer::to_s -0 843 - -fl= -fn=Array::sum -0 338 - -fl= -fn=String::to_i -0 3505 - -fl= -fn=Hash::merge -0 5716 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::collect_stats_from_users -42 12 -cfl= -cfn=Array::each -calls=7 43 -43 170641 - -fl= -fn=Array::join -0 1612 - -fl= -fn=Array::uniq -0 643 - -fl= -fn=Array::sort -0 7044 -cfl= -cfn=Date::<=> -calls=17169 0 -0 3371 - -fl= -fn=String::upcase -0 6560 - -fl= -fn=Array::map -0 46801 -cfl= -cfn=String::upcase -calls=16928 117 -117 4732 -cfl= -cfn=String::to_i -calls=16928 134 -134 3505 -cfl= -cfn=Date::parse^ -calls=8464 159 -159 59908 -cfl= -cfn=Date::iso8601 -calls=8464 159 -159 4549 - -fl= -fn=Array::all? -0 162413 -cfl= -cfn=String::upcase -calls=1979 154 -154 554 - -fl= -fn=Array::count -0 296 - -fl= -fn=Hash::values -0 16 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::build_report -81 44 -cfl= -cfn=Hash::values -calls=2 82 -82 16 -cfl= -cfn=Array::count -calls=3 101 -101 3 -cfl= -cfn=Array::each -calls=1 105 -105 166652 -cfl= -cfn=Array::map -calls=2 114 -114 9288 -cfl= -cfn=Array::sort -calls=1 114 -114 1528 -cfl= -cfn=Array::uniq -calls=1 114 -114 643 -cfl= -cfn=Array::join -calls=1 114 -114 21 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::collect_stats_from_users -calls=7 128 -128 170653 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::assign_sessions_to_users -75 4 -cfl= -cfn=Array::each -calls=1 76 -76 4570 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=User::initialize -12 1319 - -fl= -fn=Class::new -0 1071 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=User::initialize -calls=1536 0 -0 1319 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::initialize_users -63 8 -cfl= -cfn=Array::each -calls=1 66 -66 4673 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_session -31 9378 -cfl= -cfn=String::split -calls=8464 32 -32 9230 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_user -21 1600 -cfl= -cfn=String::split -calls=1536 22 -22 1485 - -fl= -fn=Array::each -0 57948 -cfl= -cfn=String::split -calls=10000 55 -55 11029 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_user -calls=1536 56 -56 3085 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_session -calls=8464 57 -57 18608 -cfl= -cfn=Class::new -calls=1536 68 -68 2390 -cfl= -cfn=Array::all? -calls=10000 107 -107 162967 -cfl= -cfn=Array::count -calls=1536 129 -129 293 -cfl= -cfn=Hash::merge -calls=10752 129 -129 5716 -cfl= -cfn=Array::map -calls=16896 134 -134 110206 -cfl= -cfn=Array::sum -calls=1536 134 -134 338 -cfl= -cfn=Integer::to_s -calls=3072 134 -134 843 -cfl= -cfn=String::+ -calls=3072 134 -134 893 -cfl= -cfn=Array::max -calls=1536 139 -139 385 -cfl= -cfn=Array::sort -calls=3072 144 -144 8887 -cfl= -cfn=Array::join -calls=1536 144 -144 1592 -cfl= -cfn=Array::any? -calls=1536 149 -149 5019 -cfl= -cfn=Array::reverse -calls=1536 159 -159 488 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::split_users_and_sessions -50 7 -cfl= -cfn=Array::each -calls=1 54 -54 44152 - -fl= -fn=String::split -0 23742 - -fl= -fn=IO::read^ -0 387 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::disable^ -84 4 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::work -165 117 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::disable^ -calls=1 166 -166 4 -cfl= -cfn=IO::read^ -calls=1 168 -168 387 -cfl= -cfn=String::split -calls=1 168 -168 1998 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::split_users_and_sessions -calls=1 169 -169 44159 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::initialize_users -calls=1 170 -170 4681 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::assign_sessions_to_users -calls=1 171 -171 4574 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::build_report -calls=1 172 -172 348848 -cfl= -cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -calls=1 174 -174 3646 -cfl= -cfn=IO::write^ -calls=1 174 -174 574 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::enable^ -calls=1 176 -176 5 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb -fn=[global]:: -10 14 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::work -calls=1 10 -10 408992 - diff --git a/profiling/ruby_prof_reports/callgrind.out.67404 b/profiling/ruby_prof_reports/callgrind.out.67404 deleted file mode 100644 index e551d148..00000000 --- a/profiling/ruby_prof_reports/callgrind.out.67404 +++ /dev/null @@ -1,398 +0,0 @@ -events: wall_time - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::enable^ -72 5 - -fl= -fn=IO::write^ -0 423 - -fl= -fn=JSON/Ext/Generator/State::initialize -0 1 - -fl= -fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -0 3508 -cfl= -cfn=JSON/Ext/Generator/State::initialize -calls=1 0 -0 1 - -fl= -fn=Date::iso8601 -0 4917 - -fl= -fn=Array::reverse -0 508 - -fl= -fn=Date::<=> -0 3741 - -fl= -fn=Integer::div -0 1749 - -fl= -fn=String::[]= -0 2796 - -fl= -fn=MatchData::end -0 1525 - -fl= -fn=MatchData::begin -0 5801 - -fl= -fn=Regexp::match -0 13492 - -fl= -fn=String::gsub! -0 7235 - -fl= -fn=Date::parse^ -0 28786 -cfl= -cfn=String::gsub! -calls=8464 0 -0 7235 -cfl= -cfn=Regexp::match -calls=16928 0 -0 13492 -cfl= -cfn=MatchData::begin -calls=8464 0 -0 5801 -cfl= -cfn=MatchData::end -calls=8464 0 -0 1525 -cfl= -cfn=String::[]= -calls=8464 0 -0 2796 -cfl= -cfn=Integer::div -calls=8464 0 -0 1749 - -fl= -fn=Array::all? -0 1949 -cfl= -cfn=String::upcase -calls=1979 149 -149 585 - -fl= -fn=Array::any? -0 3803 -cfl= -cfn=String::upcase -calls=4492 144 -144 1256 - -fl= -fn=Array::max -0 348 - -fl= -fn=String::+ -0 813 - -fl= -fn=Integer::to_s -0 771 - -fl= -fn=Array::sum -0 353 - -fl= -fn=String::to_i -0 3590 - -fl= -fn=Hash::merge -0 5585 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::collect_stats_from_users -42 16 -cfl= -cfn=Array::each -calls=7 43 -43 172314 - -fl= -fn=Array::join -0 1574 - -fl= -fn=Array::sort -0 7141 -cfl= -cfn=Date::<=> -calls=17169 0 -0 3741 - -fl= -fn=String::upcase -0 6203 - -fl= -fn=Array::uniq -0 2454 - -fl= -fn=Array::map -0 50682 -cfl= -cfn=String::upcase -calls=16928 112 -112 4362 -cfl= -cfn=String::to_i -calls=16928 129 -129 3590 -cfl= -cfn=Date::parse^ -calls=8464 154 -154 61384 -cfl= -cfn=Date::iso8601 -calls=8464 154 -154 4917 - -fl= -fn=Array::count -0 309 - -fl= -fn=Hash::values -0 25 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::build_report -81 58 -cfl= -cfn=Hash::values -calls=2 82 -82 25 -cfl= -cfn=Array::count -calls=3 101 -101 4 -cfl= -cfn=Array::map -calls=3 104 -104 12636 -cfl= -cfn=Array::uniq -calls=2 104 -104 2454 -cfl= -cfn=Array::sort -calls=1 109 -109 1556 -cfl= -cfn=Array::join -calls=1 109 -109 21 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::collect_stats_from_users -calls=7 123 -123 172330 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::assign_sessions_to_users -75 5 -cfl= -cfn=Array::each -calls=1 76 -76 5631 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=User::initialize -12 1374 - -fl= -fn=Class::new -0 1116 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=User::initialize -calls=1536 0 -0 1374 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::initialize_users -63 7 -cfl= -cfn=Array::each -calls=1 66 -66 4817 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_session -31 8962 -cfl= -cfn=String::split -calls=8464 32 -32 8743 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_user -21 1432 -cfl= -cfn=String::split -calls=1536 22 -22 1377 - -fl= -fn=Array::each -0 51568 -cfl= -cfn=String::split -calls=10000 55 -55 9977 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_user -calls=1536 56 -56 2809 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_session -calls=8464 57 -57 17705 -cfl= -cfn=Class::new -calls=1536 68 -68 2489 -cfl= -cfn=Array::count -calls=1536 124 -124 305 -cfl= -cfn=Hash::merge -calls=10752 124 -124 5585 -cfl= -cfn=Array::map -calls=16896 129 -129 112298 -cfl= -cfn=Array::sum -calls=1536 129 -129 353 -cfl= -cfn=Integer::to_s -calls=3072 129 -129 771 -cfl= -cfn=String::+ -calls=3072 129 -129 813 -cfl= -cfn=Array::max -calls=1536 134 -134 348 -cfl= -cfn=Array::sort -calls=3072 139 -139 9326 -cfl= -cfn=Array::join -calls=1536 139 -139 1553 -cfl= -cfn=Array::any? -calls=1536 144 -144 5059 -cfl= -cfn=Array::all? -calls=1536 149 -149 2535 -cfl= -cfn=Array::reverse -calls=1536 154 -154 508 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::split_users_and_sessions -50 5 -cfl= -cfn=Array::each -calls=1 54 -54 41239 - -fl= -fn=String::split -0 22041 - -fl= -fn=IO::read^ -0 312 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::disable^ -84 3 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::work -160 122 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::disable^ -calls=1 161 -161 3 -cfl= -cfn=IO::read^ -calls=1 163 -163 312 -cfl= -cfn=String::split -calls=1 163 -163 1945 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::split_users_and_sessions -calls=1 164 -164 41244 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::initialize_users -calls=1 165 -165 4824 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::assign_sessions_to_users -calls=1 166 -166 5636 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::build_report -calls=1 167 -167 189083 -cfl= -cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -calls=1 169 -169 3510 -cfl= -cfn=IO::write^ -calls=1 169 -169 423 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::enable^ -calls=1 171 -171 5 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb -fn=[global]:: -10 24 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::work -calls=1 10 -10 247106 - diff --git a/profiling/ruby_prof_reports/callgrind.out.86565 b/profiling/ruby_prof_reports/callgrind.out.86565 deleted file mode 100644 index 230ca747..00000000 --- a/profiling/ruby_prof_reports/callgrind.out.86565 +++ /dev/null @@ -1,326 +0,0 @@ -events: wall_time - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::enable^ -72 6 - -fl= -fn=IO::write^ -0 444 - -fl= -fn=JSON/Ext/Generator/State::initialize -0 4 - -fl= -fn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -0 3633 -cfl= -cfn=JSON/Ext/Generator/State::initialize -calls=1 0 -0 4 - -fl= -fn=Hash::merge -0 1298 - -fl= -fn=Array::reverse -0 517 - -fl= -fn=Array::all? -0 1914 -cfl= -cfn=String::upcase -calls=1979 63 -63 495 - -fl= -fn=Array::any? -0 3909 -cfl= -cfn=String::upcase -calls=4492 61 -61 1167 - -fl= -fn=Array::max -0 399 - -fl= -fn=String::+ -0 810 - -fl= -fn=Integer::to_s -0 882 - -fl= -fn=Array::sum -0 396 - -fl= -fn=String::to_i -0 1839 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::collect_stats_from_users -42 4 -cfl= -cfn=Array::each -calls=1 43 -43 46937 - -fl= -fn=Array::join -0 1676 - -fl= -fn=Array::sort -0 4477 - -fl= -fn=String::upcase -0 6040 - -fl= -fn=Array::uniq -0 1688 - -fl= -fn=Array::map -0 25027 -cfl= -cfn=String::upcase -calls=16928 133 -133 4378 -cfl= -cfn=String::to_i -calls=8464 47 -47 1839 - -fl= -fn=Array::count -0 371 - -fl= -fn=Hash::values -0 21 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::build_report -102 42 -cfl= -cfn=Hash::values -calls=2 103 -103 21 -cfl= -cfn=Array::count -calls=3 122 -122 6 -cfl= -cfn=Array::map -calls=3 125 -125 11560 -cfl= -cfn=Array::uniq -calls=2 125 -125 1688 -cfl= -cfn=Array::sort -calls=1 130 -130 1580 -cfl= -cfn=Array::join -calls=1 130 -130 41 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::collect_stats_from_users -calls=1 143 -143 46941 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::assign_sessions_to_users -96 9 -cfl= -cfn=Array::each -calls=1 97 -97 5581 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=User::initialize -12 1439 - -fl= -fn=Class::new -0 1244 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=User::initialize -calls=1536 0 -0 1439 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::initialize_users -84 7 -cfl= -cfn=Array::each -calls=1 87 -87 5049 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_session -31 9489 -cfl= -cfn=String::split -calls=8464 32 -32 8942 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::parse_user -21 1505 -cfl= -cfn=String::split -calls=1536 22 -22 1490 - -fl= -fn=Array::each -0 29829 -cfl= -cfn=String::split -calls=10000 76 -76 10685 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_user -calls=1536 77 -77 2995 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::parse_session -calls=8464 78 -78 18431 -cfl= -cfn=Class::new -calls=1536 89 -89 2683 -cfl= -cfn=Array::map -calls=7680 47 -47 19684 -cfl= -cfn=Array::count -calls=1536 50 -50 365 -cfl= -cfn=Array::sum -calls=1536 50 -50 396 -cfl= -cfn=Integer::to_s -calls=3072 50 -50 882 -cfl= -cfn=String::+ -calls=3072 50 -50 810 -cfl= -cfn=Array::max -calls=1536 50 -50 399 -cfl= -cfn=Array::sort -calls=3072 50 -50 2898 -cfl= -cfn=Array::join -calls=1536 50 -50 1635 -cfl= -cfn=Array::any? -calls=1536 50 -50 5076 -cfl= -cfn=Array::all? -calls=1536 50 -50 2409 -cfl= -cfn=Array::reverse -calls=1536 50 -50 517 -cfl= -cfn=Hash::merge -calls=1536 50 -50 1298 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::split_users_and_sessions -71 6 -cfl= -cfn=Array::each -calls=1 75 -75 43423 - -fl= -fn=String::split -0 23272 - -fl= -fn=IO::read^ -0 308 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -fn=GC::disable^ -84 4 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -fn=Object::work -148 157 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::disable^ -calls=1 149 -149 4 -cfl= -cfn=IO::read^ -calls=1 151 -151 308 -cfl= -cfn=String::split -calls=1 151 -151 2155 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::split_users_and_sessions -calls=1 152 -152 43429 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::initialize_users -calls=1 153 -153 5056 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::assign_sessions_to_users -calls=1 154 -154 5590 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::build_report -calls=1 155 -155 61878 -cfl= -cfn=JSON/Ext/Generator/GeneratorMethods/Hash::to_json -calls=1 157 -157 3637 -cfl= -cfn=IO::write^ -calls=1 157 -157 444 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/ -cfn=GC::enable^ -calls=1 159 -159 6 - -fl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/profiling/ruby_prof_callgrind.rb -fn=[global]:: -10 19 -cfl=/Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb -cfn=Object::work -calls=1 10 -10 122664 - diff --git a/profiling/ruby_prof_reports/callstack.html b/profiling/ruby_prof_reports/callstack.html deleted file mode 100644 index 09091c2e..00000000 --- a/profiling/ruby_prof_reports/callstack.html +++ /dev/null @@ -1,2933 +0,0 @@ - - - - - - -
-
-
-
Profile Report
-

Wall_time

-
-
-
Thursday, October 19 at 10:21:42 AM (MSK)
- -
-
-
-
- - - - - - - - - - - - - -
Thread IDFiber IDTotal
2602400.11642924600164406
- - - -

Thread 260, Fiber: 240

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%Total%SelfTotalSelfWaitChildCallsNameLine
100.00%0.01%0.120.000.000.121 - - [global]# - - 8
  0.120.000.000.121/1Object#work8 -
  0.120.000.000.121/1[global]#8
99.99%0.08%0.120.000.000.121 - - Object#work - - 153
  0.060.000.000.061/1Object#parse_lines157 -
  0.040.000.000.041/1Object#build_report158 -
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json160 -
  0.000.000.000.001/1<Class::IO>#read156 -
  0.000.000.000.001/10001String#split156 -
  0.000.000.000.001/1<Class::IO>#write160 -
  0.000.000.000.001/1<Module::GC>#disable154 -
  0.000.000.000.001/1<Module::GC>#enable162 -
  0.000.000.000.001536/1540Enumerable#max_by
  0.010.000.000.001/1540Enumerable#group_by
  0.010.000.000.011/1540Enumerable#each_with_object
  0.040.010.000.031/1540Object#collect_stats_from_users69
  0.050.010.000.041/1540Object#parse_lines107
85.04%25.99%0.100.030.000.071540 - - *Array#each - -
  0.030.010.000.018464/8464Object#parse_session108 -
  0.010.010.000.008464/8464User#add_session111 -
  0.010.000.000.001536/1536User#always_used_chrome?76 -
  0.010.000.000.001536/1536User#longest_session76 -
  0.000.000.000.003072/3073Array#sort76 -
  0.000.000.000.001536/4608User#browsers76 -
  0.000.000.000.001536/1536Class#new103 -
  0.000.000.000.001536/1536Object#parse_user102 -
  0.000.000.000.001536/6146Array#map76 -
  0.000.000.000.0010000/10000String#start_with?99 -
  0.000.000.000.001536/1537Array#join76 -
  0.000.000.000.001536/1536Hash#merge76 -
  0.000.000.000.003072/3072Integer#to_s76 -
  0.000.000.000.001536/1536Array#reverse76 -
  0.000.000.000.001536/1536User#used_internet_explorer?76 -
  0.060.000.000.061/1Object#work157
54.31%0.01%0.060.000.000.061 - - Object#parse_lines - - 97
  0.050.010.000.041/1540Array#each107 -
  0.010.000.000.011/1Enumerable#each_with_object101 -
  0.010.000.000.011/1Enumerable#group_by99 -
  0.000.000.000.002/2Hash#values99 -
  0.040.000.000.041/1Object#work158
36.96%0.02%0.040.000.000.041 - - Object#build_report - - 117
  0.040.000.000.041/1Object#collect_stats_from_users148 -
  0.010.000.000.002/6146Array#map138 -
  0.000.000.000.001/1Array#flatten138 -
  0.000.000.000.002/2Array#uniq138 -
  0.000.000.000.001/3073Array#sort143 -
  0.000.000.000.001/1537Array#join143 -
  0.000.000.000.001/1Array#sum141 -
  0.000.000.000.002/2Array#count135 -
  0.040.000.000.041/1Object#build_report148
30.78%0.00%0.040.000.000.041 - - Object#collect_stats_from_users - - 68
  0.040.010.000.031/1540Array#each69 -
  0.030.010.000.018464/8464Array#each
23.39%10.75%0.030.010.000.018464 - - Object#parse_session - - 57
  0.010.010.000.008464/10001String#split58 -
  0.000.000.000.008464/8464String#upcase60 -
  0.000.000.000.008464/8464String#to_i60 -
  0.000.000.000.001536/10001Object#parse_user48
  0.000.000.000.001/10001Object#work156
  0.010.010.000.008464/10001Object#parse_session58
11.92%11.92%0.010.010.000.0010001 - - String#split - -
  0.000.000.000.001536/6146Array#each
  0.010.000.000.002/6146Object#build_report138
  0.010.010.000.004608/6146User#browsers28
11.16%10.41%0.010.010.000.006146 - - *Array#map - -
  0.000.000.000.001536/4608User#browsers -
  0.010.010.000.008464/8464Array#each
9.75%7.81%0.010.010.000.008464 - - User#add_session - - 39
  0.000.000.000.008464/10443String#include?43 -
  0.000.000.000.001536/4608User#always_used_chrome?36
  0.000.000.000.001536/4608Array#each
  0.000.000.000.001536/4608Array#map
9.50%1.99%0.010.000.000.014608 - - User#browsers - - 26
  0.010.010.000.004608/6146Array#map28 -
  0.010.000.000.011/1Object#parse_lines101
7.24%0.00%0.010.000.000.011 - - Enumerable#each_with_object - -
  0.010.000.000.011/1540Array#each -
  0.010.000.000.011/1Object#parse_lines99
5.21%0.01%0.010.000.000.011 - - Enumerable#group_by - -
  0.010.000.000.001/1540Array#each -
  0.010.000.000.001536/1536Array#each
5.17%0.89%0.010.000.000.001536 - - User#always_used_chrome? - - 35
  0.000.000.000.001536/4608User#browsers36 -
  0.000.000.000.001536/1536Array#all?36 -
  0.010.000.000.001536/1536Array#each
4.75%0.73%0.010.000.000.001536 - - User#longest_session - - 22
  0.000.000.000.001536/1536Enumerable#max_by23 -
  0.000.000.000.001536/1536User#longest_session23
4.02%0.77%0.000.000.000.001536 - - Enumerable#max_by - -
  0.000.000.000.001536/1540Array#each -
  0.000.000.000.001/3073Object#build_report143
  0.000.000.000.003072/3073Array#each
2.99%2.99%0.000.000.000.003073 - - Array#sort - -
  0.000.000.000.001/1Object#work160
2.90%2.89%0.000.000.000.001 - - JSON::Ext::Generator::GeneratorMethods::Hash#to_json - -
  0.000.000.000.001/1JSON::Ext::Generator::State#initialize -
  0.000.000.000.001536/1536Array#each
2.66%1.04%0.000.000.000.001536 - - Class#new - -
  0.000.000.000.001536/1536User#initialize -
  0.000.000.000.001536/1536Array#each
2.56%1.29%0.000.000.000.001536 - - Object#parse_user - - 47
  0.000.000.000.001536/10001String#split48 -
  0.000.000.000.001/1Object#work156
2.52%2.52%0.000.000.000.001 - - <Class::IO>#read - -
  0.000.000.000.001979/10443Array#all?
  0.000.000.000.008464/10443User#add_session43
2.46%2.46%0.000.000.000.0010443 - - String#include? - -
  0.000.000.000.008464/8464Object#parse_session60
2.09%2.09%0.000.000.000.008464 - - String#upcase - -
  0.000.000.000.008464/8464Object#parse_session60
1.83%1.83%0.000.000.000.008464 - - String#to_i - -
  0.000.000.000.0010000/10000Array#each
1.69%1.69%0.000.000.000.0010000 - - String#start_with? - -
  0.000.000.000.001536/1536Class#new
1.61%1.61%0.000.000.000.001536 - - User#initialize - - 11
  0.000.000.000.001536/1536User#always_used_chrome?36
1.51%0.99%0.000.000.000.001536 - - Array#all? - -
  0.000.000.000.001979/10443String#include?36 -
  0.000.000.000.001/1537Object#build_report143
  0.000.000.000.001536/1537Array#each
1.44%1.44%0.000.000.000.001537 - - Array#join - -
  0.000.000.000.001/1Object#work160
1.29%1.29%0.000.000.000.001 - - <Class::IO>#write - -
  0.000.000.000.001536/1536Array#each
1.10%1.10%0.000.000.000.001536 - - Hash#merge - -
  0.000.000.000.001/1Object#build_report138
0.79%0.79%0.000.000.000.001 - - Array#flatten - -
  0.000.000.000.003072/3072Array#each
0.78%0.78%0.000.000.000.003072 - - Integer#to_s - -
  0.000.000.000.002/2Object#build_report138
0.78%0.78%0.000.000.000.002 - - Array#uniq - -
  0.000.000.000.001536/1536Array#each
0.52%0.52%0.000.000.000.001536 - - Array#reverse - -
  0.000.000.000.001536/1536Array#each
0.47%0.47%0.000.000.000.001536 - - User#used_internet_explorer? - - 31
  0.000.000.000.002/2Object#parse_lines99
0.01%0.01%0.000.000.000.002 - - Hash#values - -
  0.000.000.000.001/1Object#build_report141
0.01%0.01%0.000.000.000.001 - - Array#sum - -
  0.000.000.000.001/1Object#work154
0.00%0.00%0.000.000.000.001 - - <Module::GC>#disable - - 84
  0.000.000.000.001/1Object#work162
0.00%0.00%0.000.000.000.001 - - <Module::GC>#enable - - 72
  0.000.000.000.002/2Object#build_report135
0.00%0.00%0.000.000.000.002 - - Array#count - -
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json
0.00%0.00%0.000.000.000.001 - - JSON::Ext::Generator::State#initialize - -
* indicates recursively called methods
- -
- - - - diff --git a/profiling/ruby_prof_reports/flat.txt b/profiling/ruby_prof_reports/flat.txt deleted file mode 100644 index 3cd83958..00000000 --- a/profiling/ruby_prof_reports/flat.txt +++ /dev/null @@ -1,65 +0,0 @@ -Measure Mode: wall_time -Thread ID: 260 -Fiber ID: 240 -Total: 0.100531 -Sort by: self_time - - %self total self wait child calls name location - 29.62 0.090 0.030 0.000 0.060 1540 *Array#each - 12.88 0.013 0.013 0.000 0.000 10001 String#split - 12.08 0.026 0.012 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:55 - 11.31 0.014 0.011 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:35 - 3.17 0.003 0.003 0.000 0.000 3073 Array#sort - 2.96 0.003 0.003 0.000 0.000 1 #write - 2.74 0.003 0.003 0.000 0.000 1538 Array#map - 2.69 0.003 0.003 0.000 0.000 10443 String#include? - 2.59 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 2.28 0.002 0.002 0.000 0.000 8464 String#upcase - 2.08 0.002 0.002 0.000 0.000 8464 String#to_i - 2.08 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 - 2.00 0.002 0.002 0.000 0.000 10000 String#start_with? - 1.49 0.002 0.002 0.000 0.000 1537 Array#join - 1.34 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:45 - 1.26 0.001 0.001 0.000 0.000 1 Array#flatten - 1.08 0.002 0.001 0.000 0.000 1536 Array#all? - 1.06 0.003 0.001 0.000 0.002 1536 Class#new - 0.83 0.001 0.001 0.000 0.000 2 Array#uniq - 0.83 0.004 0.001 0.000 0.003 1536 Enumerable#max_by - 0.77 0.001 0.001 0.000 0.000 3072 Integer#to_s - 0.76 0.005 0.001 0.000 0.004 1536 User#longest_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:23 - 0.70 0.002 0.001 0.000 0.002 1536 User#always_used_chrome? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:31 - 0.49 0.000 0.000 0.000 0.000 1536 User#used_internet_explorer? /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:27 - 0.43 0.000 0.000 0.000 0.000 1536 Array#reverse - 0.30 0.000 0.000 0.000 0.000 1 #read - 0.08 0.101 0.000 0.000 0.100 1 Object#work /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:143 - 0.02 0.029 0.000 0.000 0.029 1 Object#build_report /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:107 - 0.01 0.000 0.000 0.000 0.000 2 Hash#values - 0.01 0.101 0.000 0.000 0.101 1 [global]# profiling/ruby_prof_flat.rb:8 - 0.01 0.064 0.000 0.000 0.064 1 Object#parse_lines /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:88 - 0.01 0.026 0.000 0.000 0.026 1 Object#collect_stats_from_users /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:66 - 0.01 0.000 0.000 0.000 0.000 1 Array#sum - 0.00 0.000 0.000 0.000 0.000 1 #enable :72 - 0.00 0.008 0.000 0.000 0.008 1 Enumerable#each_with_object - 0.00 0.000 0.000 0.000 0.000 1 #disable :84 - 0.00 0.006 0.000 0.000 0.006 1 Enumerable#group_by - 0.00 0.000 0.000 0.000 0.000 2 Array#count - 0.00 0.000 0.000 0.000 0.000 1 JSON::Ext::Generator::State#initialize - -* recursively called methods - -Columns are: - - %self - The percentage of time spent in this method, derived from self_time/total_time. - total - The time spent in this method and its children. - self - The time spent in this method. - wait - The amount of time this method waited for other threads. - child - The time spent in this method's children. - calls - The number of times this method was called. - name - The name of the method. - location - The location of the method. - -The interpretation of method names is: - - * MyObject#test - An instance method "test" of the class "MyObject" - * #test - The <> characters indicate a method on a singleton class. - diff --git a/profiling/ruby_prof_reports/graph.html b/profiling/ruby_prof_reports/graph.html deleted file mode 100644 index 81c2c968..00000000 --- a/profiling/ruby_prof_reports/graph.html +++ /dev/null @@ -1,3107 +0,0 @@ - - - - - - -
-
-
-
Profile Report
-

Wall_time

-
-
-
Wednesday, October 18 at 9:37:59 AM (MSK)
- -
-
-
-
- - - - - - - - - - - - - -
Thread IDFiber IDTotal
2602400.4150142199941911
- - - -

Thread 260, Fiber: 240

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%Total%SelfTotalSelfWaitChildCallsNameLine
100.00%0.00%0.420.000.000.421 - - [global]# - - 9
  0.420.000.000.411/1Object#work9 -
  0.420.000.000.411/1[global]#9
100.00%0.03%0.420.000.000.411 - - Object#work - - 165
  0.350.000.000.351/1Object#build_report172 -
  0.040.000.000.041/1Object#split_users_and_sessions169 -
  0.010.000.000.011/1Object#assign_sessions_to_users171 -
  0.000.000.000.001/1Object#initialize_users170 -
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json174 -
  0.000.000.000.001/1<Class::IO>#write174 -
  0.000.000.000.001/20001String#split168 -
  0.000.000.000.001/1<Class::IO>#read168 -
  0.000.000.000.001/1<Module::GC>#enable176 -
  0.000.000.000.001/1<Module::GC>#disable166 -
  0.000.000.000.001/11Object#initialize_users66
  0.010.010.000.001/11Object#assign_sessions_to_users76
  0.040.010.000.031/11Object#split_users_and_sessions54
  0.160.010.000.161/11Object#build_report105
  0.180.040.000.147/11Object#collect_stats_from_users43
94.94%14.52%0.390.060.000.3311 - - Array#each - -
  0.160.160.000.0010000/10000Array#all?107 -
  0.110.040.000.0716896/16898Array#map134 -
  0.020.010.000.018464/8464Object#parse_session57 -
  0.010.010.000.0010000/20001String#split55 -
  0.010.010.000.003072/3073Array#sort144 -
  0.010.010.000.0010752/10752Hash#merge129 -
  0.000.000.000.001536/1536Array#any?149 -
  0.000.000.000.001536/1536Object#parse_user56 -
  0.000.000.000.001536/1536Class#new68 -
  0.000.000.000.001536/1537Array#join144 -
  0.000.000.000.003072/3072Integer#to_s134 -
  0.000.000.000.003072/3072String#+134 -
  0.000.000.000.001536/1536Array#reverse159 -
  0.000.000.000.001536/1536Array#max139 -
  0.000.000.000.001536/1536Array#sum134 -
  0.000.000.000.001536/1539Array#count129 -
  0.350.000.000.351/1Object#work172
84.77%0.01%0.350.000.000.351 - - Object#build_report - - 81
  0.180.000.000.187/7Object#collect_stats_from_users128 -
  0.160.010.000.161/11Array#each105 -
  0.010.010.000.002/16898Array#map114 -
  0.000.000.000.001/3073Array#sort114 -
  0.000.000.000.001/1Array#uniq114 -
  0.000.000.000.002/2Hash#values82 -
  0.000.000.000.001/1537Array#join114 -
  0.000.000.000.003/1539Array#count101 -
  0.180.000.000.187/7Object#build_report128
42.69%0.00%0.180.000.000.187 - - Object#collect_stats_from_users - - 42
  0.180.040.000.147/11Array#each43 -
  0.160.160.000.0010000/10000Array#each
38.48%38.35%0.160.160.000.0010000 - - Array#all? - -
  0.000.000.000.001979/23399String#upcase154 -
  0.010.010.000.002/16898Object#build_report114
  0.110.040.000.0716896/16898Array#each
29.69%11.68%0.120.050.000.0716898 - - Array#map - -
  0.060.030.000.038464/8464<Class::Date>#parse159 -
  0.000.000.000.008464/8464Date#iso8601159 -
  0.000.000.000.0016928/23399String#upcase117 -
  0.000.000.000.0016928/16928String#to_i134 -
  0.060.030.000.038464/8464Array#map
14.90%6.96%0.060.030.000.038464 - - <Class::Date>#parse - -
  0.010.010.000.0016928/16928Regexp#match -
  0.010.010.000.008464/8464String#gsub! -
  0.010.010.000.008464/8464MatchData#begin -
  0.000.000.000.008464/8464String#[]= -
  0.000.000.000.008464/8464Integer#div -
  0.000.000.000.008464/8464MatchData#end -
  0.040.000.000.041/1Object#work169
10.49%0.00%0.040.000.000.041 - - Object#split_users_and_sessions - - 50
  0.040.010.000.031/11Array#each54 -
  0.000.000.000.001536/20001Object#parse_user22
  0.000.000.000.001/20001Object#work168
  0.010.010.000.008464/20001Object#parse_session32
  0.010.010.000.0010000/20001Array#each
5.63%5.63%0.020.020.000.0020001 - - String#split - -
  0.020.010.000.018464/8464Array#each
4.48%2.29%0.020.010.000.018464 - - Object#parse_session - - 31
  0.010.010.000.008464/20001String#split32 -
  0.010.010.000.0016928/16928<Class::Date>#parse
3.22%3.22%0.010.010.000.0016928 - - Regexp#match - -
  0.000.000.000.001/3073Object#build_report114
  0.010.010.000.003072/3073Array#each
2.70%1.83%0.010.010.000.003073 - - Array#sort - -
  0.000.000.000.0017169/17169Date#<=> -
  0.010.010.000.008464/8464<Class::Date>#parse
1.78%1.78%0.010.010.000.008464 - - String#gsub! - -
  0.000.000.000.001979/23399Array#all?
  0.000.000.000.004492/23399Array#any?
  0.000.000.000.0016928/23399Array#map
1.53%1.53%0.010.010.000.0023399 - - String#upcase - -
  0.010.010.000.008464/8464<Class::Date>#parse
1.51%1.51%0.010.010.000.008464 - - MatchData#begin - -
  0.010.010.000.0010752/10752Array#each
1.41%1.41%0.010.010.000.0010752 - - Hash#merge - -
  0.010.000.000.011/1Object#work171
1.35%0.00%0.010.000.000.011 - - Object#assign_sessions_to_users - - 75
  0.010.010.000.001/11Array#each76 -
  0.000.000.000.001536/1536Array#each
1.16%0.87%0.000.000.000.001536 - - Array#any? - -
  0.000.000.000.004492/23399String#upcase149 -
  0.000.000.000.008464/8464Array#map
1.14%1.14%0.000.000.000.008464 - - Date#iso8601 - -
  0.000.000.000.001/1Object#work170
1.13%0.00%0.000.000.000.001 - - Object#initialize_users - - 63
  0.000.000.000.001/11Array#each66 -
  0.000.000.000.001/1Object#work174
0.89%0.89%0.000.000.000.001 - - JSON::Ext::Generator::GeneratorMethods::Hash#to_json - -
  0.000.000.000.001/1JSON::Ext::Generator::State#initialize -
  0.000.000.000.0017169/17169Array#sort
0.87%0.87%0.000.000.000.0017169 - - Date#<=> - -
  0.000.000.000.0016928/16928Array#map
0.86%0.86%0.000.000.000.0016928 - - String#to_i - -
  0.000.000.000.001/1Object#work174
0.75%0.75%0.000.000.000.001 - - <Class::IO>#write - -
  0.000.000.000.001536/1536Array#each
0.72%0.38%0.000.000.000.001536 - - Object#parse_user - - 21
  0.000.000.000.001536/20001String#split22 -
  0.000.000.000.008464/8464<Class::Date>#parse
0.64%0.64%0.000.000.000.008464 - - String#[]= - -
  0.000.000.000.001536/1536Array#each
0.57%0.26%0.000.000.000.001536 - - Class#new - -
  0.000.000.000.001536/1536User#initialize -
  0.000.000.000.008464/8464<Class::Date>#parse
0.42%0.42%0.000.000.000.008464 - - Integer#div - -
  0.000.000.000.001/1537Object#build_report114
  0.000.000.000.001536/1537Array#each
0.41%0.41%0.000.000.000.001537 - - Array#join - -
  0.000.000.000.008464/8464<Class::Date>#parse
0.36%0.36%0.000.000.000.008464 - - MatchData#end - -
  0.000.000.000.001536/1536Class#new
0.31%0.31%0.000.000.000.001536 - - User#initialize - - 12
  0.000.000.000.003072/3072Array#each
0.21%0.21%0.000.000.000.003072 - - Integer#to_s - -
  0.000.000.000.003072/3072Array#each
0.20%0.20%0.000.000.000.003072 - - String#+ - -
  0.000.000.000.001/1Object#build_report114
0.16%0.16%0.000.000.000.001 - - Array#uniq - -
  0.000.000.000.001536/1536Array#each
0.12%0.12%0.000.000.000.001536 - - Array#reverse - -
  0.000.000.000.001536/1536Array#each
0.10%0.10%0.000.000.000.001536 - - Array#max - -
  0.000.000.000.001536/1536Array#each
0.09%0.09%0.000.000.000.001536 - - Array#sum - -
  0.000.000.000.001/1Object#work168
0.09%0.09%0.000.000.000.001 - - <Class::IO>#read - -
  0.000.000.000.003/1539Object#build_report101
  0.000.000.000.001536/1539Array#each
0.08%0.08%0.000.000.000.001539 - - Array#count - -
  0.000.000.000.002/2Object#build_report82
0.01%0.01%0.000.000.000.002 - - Hash#values - -
  0.000.000.000.001/1Object#work176
0.00%0.00%0.000.000.000.001 - - <Module::GC>#enable - - 72
  0.000.000.000.001/1Object#work166
0.00%0.00%0.000.000.000.001 - - <Module::GC>#disable - - 84
  0.000.000.000.001/1JSON::Ext::Generator::GeneratorMethods::Hash#to_json
0.00%0.00%0.000.000.000.001 - - JSON::Ext::Generator::State#initialize - -
* indicates recursively called methods
- -
- - - - From 564935f88bf6688b53dc1b905a24ace31e53290b Mon Sep 17 00:00:00 2001 From: Udalov Igor Date: Thu, 19 Oct 2023 12:45:13 +0300 Subject: [PATCH 25/25] Update case --- case-study.md | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/case-study.md b/case-study.md index f4e55238..11c6eb4a 100644 --- a/case-study.md +++ b/case-study.md @@ -321,31 +321,13 @@ flat: 1.67sec -> 1.56sec - как изменился отчёт профилировщика - исправленная проблема перестала быть главной точкой роста? -``` - %self total self wait child calls name location - 29.62 0.090 0.030 0.000 0.060 1540 *Array#each - 12.88 0.013 0.013 0.000 0.000 10001 String#split - 12.08 0.026 0.012 0.000 0.014 8464 Object#parse_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:55 - 11.31 0.014 0.011 0.000 0.002 8464 User#add_session /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:35 - 3.17 0.003 0.003 0.000 0.000 3073 Array#sort - 2.96 0.003 0.003 0.000 0.000 1 #write - 2.74 0.003 0.003 0.000 0.000 1538 Array#map - 2.69 0.003 0.003 0.000 0.000 10443 String#include? - 2.59 0.003 0.003 0.000 0.000 1 JSON::Ext::Generator::GeneratorMethods::Hash#to_json - 2.28 0.002 0.002 0.000 0.000 8464 String#upcase - 2.08 0.002 0.002 0.000 0.000 8464 String#to_i - 2.08 0.002 0.002 0.000 0.000 1536 User#initialize /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:11 - 2.00 0.002 0.002 0.000 0.000 10000 String#start_with? - 1.49 0.002 0.002 0.000 0.000 1537 Array#join - 1.34 0.003 0.001 0.000 0.001 1536 Object#parse_user /Users/i.udalov/Projects/thinknetica/ror_optimization/task1_new/rails-optimization-task1/task-1.rb:45 - 1.26 0.001 0.001 0.000 0.000 1 Array#flatten - 1.08 0.002 0.001 0.000 0.000 1536 Array#all? - 1.06 0.003 0.001 0.000 0.002 1536 Class#new -``` + +`merge` ушел из отчета. Ура! теперь мы попадаем в бюджет. + ## Результаты В результате проделанной оптимизации наконец удалось обработать файл с данными. -Удалось улучшить метрику системы с 2_800ms / 10к записей до 46ms / 10к записей и уложиться в заданный бюджет. +Удалось улучшить метрику системы с `2_800ms / 10к` записей до `46ms / 10к` записей и уложиться в заданный бюджет. ## Защита от регрессии производительности Для защиты от потери достигнутого прогресса при дальнейших изменениях программы я использовал тест: