Skip to content

refactor(Alerts.Sort): more performant comparison#3311

Merged
thecristen merged 3 commits into
mainfrom
cbj/stop-controller-alerts
Jul 6, 2026
Merged

refactor(Alerts.Sort): more performant comparison#3311
thecristen merged 3 commits into
mainfrom
cbj/stop-controller-alerts

Conversation

@thecristen

Copy link
Copy Markdown
Collaborator

Scope

While tackling #3310 I noticed that Alerts.Sort.sort/2 was featuring prominently in my flame charts, and I wanted to see if I could do anything about that.

Implementation

First of all. /stops/<mode> pages don't even show alerts. So the first commit moves the call which assigns alerts to conn to the specific method behind rendering the individual stop pages, instead of being invoked for every page handled by DotcomWeb.StopController.

Then when debugging Alerts.Sort.sort/2, I noticed the sorting logic included assessing the next active period start time. And I remembered we'd later implemented a different function for computing that, over at Dotcom.Alerts.StartTime.next_active_time/2! So I wanted to see if reusing that was more performant (and looks like it is!).

These charts were generated from loading South Station page with an already warmed cache.

Before (6.5MB) After (3.3MB)
flame_on (alert before) flame_on (alert after)

How to test

We could verify if the subway Planned Work section still sorts those alerts in the same way as before.

@thecristen thecristen requested a review from a team as a code owner July 1, 2026 17:18
@thecristen thecristen requested a review from lvachon1 July 1, 2026 17:18
Comment thread lib/dotcom/alerts/start_time.ex

@lvachon1 lvachon1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I only found one place where the sorting of alerts wasn't quite the same between prod and this branch. I don't think it's relevant though, the alerts seem to be for the same timeframe.

Image

@thecristen thecristen merged commit 2c03660 into main Jul 6, 2026
27 checks passed
@thecristen thecristen deleted the cbj/stop-controller-alerts branch July 6, 2026 18:55
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