Change the default depth from 2 to 1 to improve Payload performance out of the box
#15351
MurzNN
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The defaultDepth in Payload CMS is set to
2for now, and I believe that this is too much from the performance point of view!This too deep depth looks convenient from the developers' point of view, because they get all the relationship documents available in the response by default, and no need for additional queries!
But from the performance point of view, the
depth=2produces very heavy and slow queries! But most of developers don't think about the database queries, they just use the default settings, believing that they are optimal and no need to change them. Also, many developers are just not aware of this "depth" setting at all.Just imagine just a simple query "Posts" on a page "Latest posts" that displays 50 recent posts. Each post document contains at least 4 relationship fields (authors, category, tags, media), each of which will lead to additional database query or join/aggregate construction.
In result, with an almost empty database, everything works well, but when their database grows, they start to face performance issues, but decreasing the depth on already working project requires a lot of internal changes, which is hard.
So, I believe that setting the default depth to
1should improve the Payload performance by default, without significantly decreasing the developer experience, especially because developers can set the per-query depth to the desired value on that places, only where the depth>1 is really needed.P.S. In addition to this, I have one more feature request to allow passing the depth value on a per-field basis: #15244 that should give much more flexibility for developers.
Beta Was this translation helpful? Give feedback.
All reactions