Open
Conversation
Remove Array#select, refactoring session and user stats to make it work rapidly faster.
Optimize Array#split Symbolize strings and so on.
spajic
approved these changes
Mar 9, 2019
| Вот как я построил `feedback_loop`: *как вы построили feedback_loop* | ||
| Вот как я построил `feedback_loop`: | ||
|
|
||
| Я немного изменил код, чтобы считывать не весь большой файл целиком, а только первые его x линий: |
|
|
||
| Результаты профилирования показали, что самое узкое место на данный момент приходится на операцию Array#select. | ||
| Общее кол-во памяти, отведенной на эти операции, составило 414 Mb (из 470 всего). Когда количество вызовов этой функции всего 3,046 (по количеству users в первых 20_000 строк). | ||
| То есть, не самая частая операция отъедает почти 89% памяти. |
Owner
There was a problem hiding this comment.
Скорее всего, это была не память, а время
| Но повторные запуски метрики показали, что рефакторинг привел к большому росту расхода памяти на постройку хэша и последующую его конвертацию в json для записи на диск. | ||
| Но это уже друга история. | ||
|
|
||
| P.S. Кстати, нашел бажок. В тестах этого кейса нет. Если у пользователя вообще нет ни одной сессии, то он попадает в статистику как: |
| bench_work 0.000581 0.000303 0.000716 0.007148 0.068577 0.648381 | ||
| ``` | ||
|
|
||
| Ускорение более чем в 487 раз! |
| Память расходуется в районе ~2 Gb. (Если я правильно понял эту цифру в отчете профилировщика — 2 042 553) | ||
|
|
||
| Код все еще не самый красивый, есть что поDRYить, как разбить на классы, и где пописать больше тестов. Но вроде как урок | ||
| был не про это, поэтому можно пока пропустить и оставить как есть. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.