Skip to content

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

Open
thecristen wants to merge 3 commits into
mainfrom
cbj/stop-controller-alerts
Open

refactor(Alerts.Sort): more performant comparison#3311
thecristen wants to merge 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
next_active_period_active_time(rest_of_active_periods, time)

# period hasn't ended yet, but no defined start time -- use the current time
is_nil(start_time) ->

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Some of our tests have alerts involving active periods with a nil start time, so I added this clause to handle those. I'm not sure if this'll ever be encountered in real alerts from Alerts Manager, though.

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'm glad I saw this PR, I have one open with yet a 3rd way of computing the active time period. I'm going to put mine into draft for now. I saw this exact same behavior regarding only our tests having nil start times, thanks for following up with the transit data team about if that's even possible.

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