Conversation
spajic
approved these changes
Feb 28, 2025
Collaborator
spajic
left a comment
There was a problem hiding this comment.
Супер, спасибо за работу!
| @@ -1,3 +1,11 @@ | |||
| # == Schema Information | |||
| # | ||
| # Indexes | ||
| # | ||
| # index_trips_on_from_id_and_to_id (from_id,to_id) |
| number: bus.number, | ||
| model: bus.model, | ||
| services: bus.services.map(&:name), | ||
| services: bus.services.pluck(:name), |
| def connection | ||
| @connection ||= ActiveRecord::Base.connection.raw_connection | ||
| end | ||
| end |
|
|
||
| Для удобства работы с моделями добавил gem annotate. | ||
|
|
||
| Перед началом оптимизации написал тест который позволит контролировать что после изменений скрипт работает валидно(spec/services/reloader_spec.rb). |
| * {"3.4.1":{"gc":"enabled","time":0.56,"gc_count":24,"memory":"14 MB"}} - medium.json | ||
| * {"3.4.1":{"gc":"enabled","time":2.6,"gc_count":243,"memory":"15 MB"}} - large.json | ||
| * {"3.4.1":{"gc":"enabled","time":24.16,"gc_count":586,"memory":"32 MB"}} - 1M.json | ||
| * {"3.4.1":{"gc":"enabled","time":222.63,"gc_count":5441,"memory":"18 MB"}} - 10M.json |
| * medium.json - 804ms | ||
| * large.json - 5800ms | ||
|
|
||
| Добавил тесты для проверки конторллера и элементов страницы. |
| Добавил тесты для проверки конторллера и элементов страницы. | ||
|
|
||
| ## Поиск точек роста | ||
| - `rack-mini-profiler` показывает более 1700 sql запросов при рендере страницы |
| Время загрузки уменьшилось до 1300ms. | ||
|
|
||
| - В `rack-mini-profiler` вижу два запроса в таблице cities по name. | ||
| Понимаю, что из-за количества запросов добавление индекса не очень скажется на перформансе. |
Collaborator
There was a problem hiding this comment.
да, тут с точки зрения времени рендеринга страницы по профилировщико понятно что ускорения за счёт индексов не добиться
но если бы мы решали задачу оптимизировать БД, то там бы такие индексы могли бы помочь
| <% end %> | ||
| <ul> | ||
| <%= render partial: "trip", collection: @trips, as: :trip %> | ||
| ==================================================== |
Collaborator
There was a problem hiding this comment.
Есть забавная возможность задать spacer параметром: https://guides.rubyonrails.org/layouts_and_rendering.html#spacer-templates
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.