-
Notifications
You must be signed in to change notification settings - Fork 140
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
Memory optimization #111
base: master
Are you sure you want to change the base?
Memory optimization #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
```ruby | ||
writer.push_value(sessions.map{|s| s['date']}.map {|d| Date.parse(d)}.sort.reverse.map { |d| d.iso8601 }) | ||
``` | ||
- Выделила `sessions.map{|s| s['date']}` в отдельную переменную, к которой применяла bang-методы, переписала парсинг даты: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bang-методы - лайк
парсинг даты тут не нужен вообще, это пасхалочка
### Array.map() | ||
- Отчеты `ruby-prof` в режимах `callgrind` и `graph` | ||
- Вызовы метода `map` внутри `write_stats_for` занимали много памяти. Вынесла общие вызовы для `sessions.map` в переменные, использовала bang-методы | ||
- Метрика снизилась до 20Мб |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
там по сути памяти мы почти не потребляем, 20мб это близко к пустой программе на ruby, которая ничего не делает. и главное что мы почти не потребляя памяти можем перелопатить почти любой объём входящих данных
|
||
### Array.map() | ||
- Отчеты `ruby-prof` в режимах `callgrind` и `graph` | ||
- Вызовы метода `map` внутри `write_stats_for` занимали много памяти. Вынесла общие вызовы для `sessions.map` в переменные, использовала bang-методы |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Занимали много памяти" лучше уточнить что имеется в виду. У нас же по сути константное и минимальное потребление RSS на всём протяжении работы программы. То что там есть лишние аллокации это конечно неплохо убрать, так будет ещё чуть побыстрее, тк не придётся тратить время на копирование объектов и потом GC на их удаление.
|
||
def write_stats_for(user, sessions, writer) | ||
user_key = "#{user.attributes['first_name']}" + ' ' + "#{user.attributes['last_name']}" | ||
writer.push_key(user_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лайк за использование этого API, удобнее и чище чем строку по символам собирать
No description provided.