Skip to content

Conversation

@lightalloy
Copy link

Из-за дурацкой ошибки закопалась в микрооптимизации и до истины дошла только в конце.
Но case study оставила, как есть.

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.

Nice work!


На этапе отладки потокового варианта использовала sample, к-й позволял оценить работоспособность в пределах пары секунд.

Далее подобрала sample, с к-м фидбек можно было получить за 5-20 секунд.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


Подумала, раз `File`, то не открывать/закрывать его для каждого юзера, а открыть на запись 1 раз.

Переписала - по памяти ничего не поменялось, но программа стала быстрее отрабатывать (27 => 21 секунд, если проверять на большом файле без профилирования)
Copy link
Collaborator

Choose a reason for hiding this comment

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

да-да, надо не забывать разделять профилирование и замеры


Далее снова посмотрела с помощью memory_profiler:

Увидела, что String ест много памяти, причём на месте `split(',')`
Copy link
Collaborator

Choose a reason for hiding this comment

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

тут лучше быть более точным, ест много памяти => аллоцируется много объектов типа String или что-то ещё (потому что так не совсем понятно что конкретно это значит)

```

Можно оптимизировать `User` => `OptimizedUser`
+ увидела, что не используются id и age, их убираем из объекта.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

```
### 8

Увидела много объектов `','`, завела константу `DELIMITER = ','` (omg, чем я занимаюсь)
Copy link
Collaborator

Choose a reason for hiding this comment

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

))

по идее с # frozen_string_literal: true можно оставлять просто строковые литералы

MEMORY USAGE: 334 MB
MEMORY USAGE: 334 MB
MEMORY USAGE: 334 MB
MEMORY USAGE: 334 MB
Copy link
Collaborator

Choose a reason for hiding this comment

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

в принципе видно было сразу по вот этим строкам, что сразу же идёт накопление памяти, а далее стоит на месте. (можно предположить что исходный файл читается в память целиком)


## Результаты
В результате проделанной оптимизации удалось обработать файл с данными.
Удалось улучшить метрику системы с использования 2444 MB и 30с до обработки целевого файла за 6-7 секунд и 29mb памяти, но не удалось уложиться в заданный бюджет.
Copy link
Collaborator

Choose a reason for hiding this comment

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

почему не удалось, всё отлично

Copy link
Author

Choose a reason for hiding this comment

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

Забыла отредактировать с прошлой версии ))

end

describe 'Performance' do
it 'uses under 30MB of memory' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

это не совсем uses, это allocates

у нас тут речь шла именно про MAX RSS

end.to perform_allocation(31457280).bytes
end

it 'performs under 7 seconds' do
Copy link
Collaborator

Choose a reason for hiding this comment

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

cool!

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