Skip to content

Conversation

@DafyddLlyr
Copy link
Contributor

@DafyddLlyr DafyddLlyr commented Dec 7, 2025

What's the problem?

A recent change in the RAB template flow has lead to a serious slow down in a number of operations which call the sortBreadcrumbs() function, resulting in timeouts (for example, zip payload generation).

Diagnosis

Profiling within the API points to new DigitalPlanning() as being the bottleneck (~45s of a 50s operation in the example logs below).

image

Further profiling here points towards sortBreadcrumbs() as they key issue - taking 98% of the total time.

image

What's the solution?

Applying the same lessons as -

The notable change here is simply tracking already visited nodes, and implementing a stack instead of using recursion.

@DafyddLlyr DafyddLlyr changed the title dp/sort breadcrumbs perf feat: Improve sortBreadcrumbs() performance Dec 7, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty certain that simply timestamping breadcrumbs would radically simplify and speed this up even more - right now we're iterating over tens of thousands of nodes to order tens (max hundreds?) of breadcrumbs.

This is already on our logic camp to-do list, I'll add a Trello card to just pick this one up as a discrete task asap - any implementations of the timestamp can come once we're certain all active flows reliably have them in place.

Comment on lines +76 to +77
const visited = new Set<NodeId>();
const stack: string[] = [...(flow._root.edges || [])].reverse();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same methodology (copy/pasted!) as theopensystemslab/planx-new#5805

@DafyddLlyr DafyddLlyr requested a review from a team December 7, 2025 13:02
Comment on lines +16 to +22
// profile(
// "Medway RAB template",
// async () => new DigitalPlanning({
// session: mockReportAPlanningBreachSessionMedway,
// flow: await getMockReportAPlanningBreachFlow(),
// })
// ); No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be commented back in and ran once #885 has been merged.

Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

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

Great, thanks for further pin-pointing this !

Really tricky / frustrating lately to remember which logic is duplicated in planx-core across different but very similar contexts, but happy this solution was essentially right under our noses from last week 🙈

"My slow function",
async () => mySlowFunction(mockData)
);
```
Copy link
Member

Choose a reason for hiding this comment

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

Handy, thanks ! 🌟

@jessicamcinchak
Copy link
Member

Going to merge this into planx-core main only today so that I can rebase #885, get passing CI, and then open a planx-new PR accordingly which you can pick up to review / do any final testing first thing Monday morning !

@jessicamcinchak jessicamcinchak merged commit f75e429 into main Dec 7, 2025
4 checks passed
@jessicamcinchak jessicamcinchak deleted the dp/sort-breadcrumbs-perf branch December 7, 2025 18:34
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.

3 participants