-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Improve sortBreadcrumbs() performance
#886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sortBreadcrumbs() performance
There was a problem hiding this comment.
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.
| const visited = new Set<NodeId>(); | ||
| const stack: string[] = [...(flow._root.edges || [])].reverse(); |
There was a problem hiding this comment.
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
| // profile( | ||
| // "Medway RAB template", | ||
| // async () => new DigitalPlanning({ | ||
| // session: mockReportAPlanningBreachSessionMedway, | ||
| // flow: await getMockReportAPlanningBreachFlow(), | ||
| // }) | ||
| // ); No newline at end of file |
There was a problem hiding this comment.
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.
jessicamcinchak
left a comment
There was a problem hiding this 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) | ||
| ); | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handy, thanks ! 🌟
|
Going to merge this into planx-core |
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).Further profiling here points towards
sortBreadcrumbs()as they key issue - taking 98% of the total time.What's the solution?
Applying the same lessons as -
dfs(), not recursive call planx-new#5805removeOrphansFromBreadcrumbs()planx-new#5142sortBreadcrumbs()#183The notable change here is simply tracking already visited nodes, and implementing a stack instead of using recursion.