Skip to content

Conversation

@shell362
Copy link

@shell362 shell362 commented Mar 9, 2019

No description provided.

shell362 added 4 commits March 4, 2019 22:13
Remove Array#select, refactoring session and user stats to make it work
rapidly faster.
Optimize Array#split
Symbolize strings
and so on.
Copy link
Owner

@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.

Аппрув + несколько комментов

Вот как я построил `feedback_loop`: *как вы построили feedback_loop*
Вот как я построил `feedback_loop`:

Я немного изменил код, чтобы считывать не весь большой файл целиком, а только первые его x линий:
Copy link
Owner

Choose a reason for hiding this comment

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

👍


Результаты профилирования показали, что самое узкое место на данный момент приходится на операцию Array#select.
Общее кол-во памяти, отведенной на эти операции, составило 414 Mb (из 470 всего). Когда количество вызовов этой функции всего 3,046 (по количеству users в первых 20_000 строк).
То есть, не самая частая операция отъедает почти 89% памяти.
Copy link
Owner

Choose a reason for hiding this comment

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

Скорее всего, это была не память, а время

Но повторные запуски метрики показали, что рефакторинг привел к большому росту расхода памяти на постройку хэша и последующую его конвертацию в json для записи на диск.
Но это уже друга история.

P.S. Кстати, нашел бажок. В тестах этого кейса нет. Если у пользователя вообще нет ни одной сессии, то он попадает в статистику как:
Copy link
Owner

Choose a reason for hiding this comment

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

👍

bench_work 0.000581 0.000303 0.000716 0.007148 0.068577 0.648381
```

Ускорение более чем в 487 раз!
Copy link
Owner

Choose a reason for hiding this comment

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

👍

Память расходуется в районе ~2 Gb. (Если я правильно понял эту цифру в отчете профилировщика — 2 042 553)

Код все еще не самый красивый, есть что поDRYить, как разбить на классы, и где пописать больше тестов. Но вроде как урок
был не про это, поэтому можно пока пропустить и оставить как есть.
Copy link
Owner

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