Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change should improve the
/identities
endpoint performance. Right now it usesEager()
method to load identity model associations n times (where n is the number of identities fetched per request, default is 100). This causes 100+1 SQL queries. It is a tradeoff between memory and speed/queries. I found out that on our setup (yes, our DEV DB have significant lag due to some infrastructure setup but it is not crazy high ~100ms which can happen in some low tier setups as well).Currently queries looks like this:
We propose to use
EagerPreload()
which will do only one query to fetch associations.Now the queries would look like this:
Performance on
master
:performance after the change:
Memory usage: https://ibb.co/2YS8sgP (those two bumps are tests on the branch with changes so I guess it does require more memory).
docs: https://gobuffalo.io/en/docs/db/relations#loading-associations
That said I'm not 100% sure this is a good change but it should help with high latency DBs and require more memory to operate (still using Argon2Id could mean Kratos will need more memory anyway). Your call!
Related issue(s)
I don't think there is an issue but I'm pretty sure someone mentioned this on Slack one day.
Checklist
contributing code guidelines.
vulnerability. If this pull request addresses a security. vulnerability, I
confirm that I got green light (please contact
security@ory.sh) from the maintainers to push
the changes.
works.