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
Relation id and afterAll hook performance fixes #8169
Relation id and afterAll hook performance fixes #8169
Conversation
Replace a quadratic runtime with a linear in results transformer
Remove duplicate calculations of fitting subscribers for entity
Use object instead of array for faster access
This would solve a lot of our problems! Any plans on when to merge this? |
Can someone give an update on this? would be great if it gets merged soon |
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.
Not a maintainer, just ideas for improvement
src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts
Outdated
Show resolved
Hide resolved
src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts
Outdated
Show resolved
Hide resolved
src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts
Outdated
Show resolved
Hide resolved
src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts
Outdated
Show resolved
Hide resolved
…o relationId-performance-fixes
Thank you @rluvaton for your little review 👍 |
@pleerock - Since it's already reviewed and mergeable with master, any plans on when to merge this? |
Thank you! |
This PR aims to increase the performance of some very specific typeorm parts.
This includes the entity transformation after a query, when using the
@RelationId
decorator as well as broadcasting theafterAll
event to all subscribers.All it does is refactor some internal class logic for performance optimization. Therefore no new tests are needed, as the results of all the processes are still the same.
Motivation
When using typeorm, we saw that running queries which return > 500 entities are having a very bad performance and in our case, as we are using the
@RelationId
decorator a lot, we even saw a quadratic increase in runtime of the queries when increasing the number of entities.Therefore we did a deep dive and found several performance optimizations. By far the biggest one is in the
RawSqlResultsToEntityTransformer
, as there was a quadratic calculation when using@RelationId
. We were able to get this down to a linear runtime, which helped increase the performance of our queries a lot, around 3 times faster when returning 1000 entities.It is related to the following issues, depending on the used entities, but does not fix them completely:
#2381
#3857
tl;dr
RawSqlResultsToEntityTransformer
with linear runtimeRelationIdLoader
Broadcaster
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000