-
Notifications
You must be signed in to change notification settings - Fork 18
Cache parsed SQL in buildDiagram Function
#1418
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
base: main
Are you sure you want to change the base?
Conversation
e6b6fbc to
5d6f222
Compare
|
Take a look at
|
packages/models/src/event.js
Outdated
| // This class supercedes `CallTree` and `CallNode`. Events are stored in a flat | ||
| // array and can also be traversed like a tree via `parent` and `children`. | ||
| export default class Event { | ||
| static parsedSqlCache = {}; |
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.
Consider a Map instead of Object.
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.
It’s problematic to keep a cache of every SQL query in memory because tools that process many AppMaps will end up consuming a lot of memory doing this. That’s why the scanner uses an LRU cache.
Adding a cache to the Event will impact a lot of code in addition to the code we are trying to optimize.
Can we add the cache we need in a way that’s more specific to the use case. Eg in the DiagramComponent, or an LRU cache in buildDiagram.
76ca47a to
e6e3cdd
Compare
kgilpin
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.
It’s problematic to keep a cache of every SQL query in memory because tools that process many AppMaps will end up consuming a lot of memory doing this. That’s why the scanner uses an LRU cache.
Adding a cache to the Event will impact a lot of code in addition to the code we are trying to optimize.
Can we add the cache we need in a way that’s more specific to the use case. Eg in the DiagramComponent, or an LRU cache in buildDiagram.
I just changed how this works, so now I'm creating an LRU cache in |
e6e3cdd to
a6b3766
Compare
buildDiagram Function
Fixes #1417
When loading a sequence diagram, the
buildDiagramfunction is one of the most expensive function calls. When it uses thehashgetter on an instance ofEvent, thebuildStableHashfunction is called, which ultimately ends up parsing SQL if the event has any. It turns out that parsing SQL is a relatively expensive operation, so this can add up to a lot of computation if there are a lot of events with SQL in the sequence diagram. In this flame graph you can see thatpeg$parseRuleaccounts for 41% ofbuildDiagram:This PR creates an LRU cache in the
buildDiagrammethod, and then passes it into thegetHashWithSqlCachemethod on theEventclass so that we don't repeat the computation needlessly.This will need to be split up into two PRs so that we can release a version of
@appland/modelsthat will get used in@appland/sequence-diagram.