Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization ruby program by memory #106

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

beglov
Copy link

@beglov beglov commented May 6, 2024

  • Построить и проанализировать отчёт гемом memory_profiler
  • Построить и проанализировать отчёт ruby-prof в режиме Flat;
  • Построить и проанализировать отчёт ruby-prof в режиме Graph;
  • Построить и проанализировать отчёт ruby-prof в режиме CallStack;
  • Построить и проанализировать отчёт ruby-prof в режиме CallTree c визуализацией в QCachegrind;
  • Построить и проанализировать текстовый отчёт stackprof;
  • Построить и проанализировать отчёт flamegraph с помощью stackprof и визуализировать его в speedscope.app;
  • Построить график потребления памяти в valgrind massif visualier и включить скриншот в описание вашего PR;
  • Написать тест, на то что программа укладывается в бюджет по памяти

Получилось в два раза быстрее чем при оптимизации по процессору в первом задании:

# ruby task-2.rb 
MEMORY USAGE: 23 MB
Work data_large finish in 14.17

valgrind massif запустить не удалось, отваливается с ошибкой:

==1== Massif, a heap profiler
==1== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==1== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==1== Command: ruby work.rb
==1== 
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x25
### unhandled dwarf2 abbrev form code 0x1b
==1== Valgrind: debuginfo reader: ensure_valid failed:
==1== Valgrind:   during call to ML_(img_get)
==1== Valgrind:   request for range [1780434111, +4) exceeds
==1== Valgrind:   valid image size of 46151540 for image:
==1== Valgrind:   "/usr/local/lib/libruby.so.3.2.2"
==1== 
==1== Valgrind: debuginfo reader: Possibly corrupted debuginfo file.
==1== Valgrind: I can't recover.  Giving up.  Sorry.
==1== 

Copy link
Collaborator

@spajic spajic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Круто, что получилось в два раза быстрее первого задания, да?

  • можно с константным потреблением памяти переварить любой объём входящих данных


### Находка №5 - Вызов split при чтении строк из файла
- все отчеты указывают на это
- не присваивать переменной результат вызова метода, а передать ему блок
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да split with block в этом кейсе крутое решение

@@ -69,78 +121,61 @@ def work
# - Хоть раз использовал IE? +
# - Всегда использовал только Хром? +
# - даты сессий в порядке убывания через запятую +
total_users = 0
total_sessions = 0
unique_browsers = Hash.new(0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set?

Удалось улучшить метрику системы с *того, что у вас было в начале, до того, что получилось в конце* и уложиться в заданный бюджет.

*Какими ещё результами можете поделиться*
Удалось улучшить метрику системы до 23 MB при обработке файла любого размера и уложиться в заданный бюджет.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что-то в кейс-стади не вижу шага про переписывание в потоковом виде, хотя это сделано

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants