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

Memory optimization #111

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

Conversation

dischglv
Copy link

@dischglv dischglv commented Jun 9, 2024

No description provided.

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.

```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-методы, переписала парсинг даты:
Copy link
Collaborator

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Мб
Copy link
Collaborator

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-методы
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Лайк за использование этого API, удобнее и чище чем строку по символам собирать

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