ENH Cache $item->ID for eager loading #10840
Merged
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.
Issue silverstripe/silverstripe-elemental#1067
This small change makes a remarkably large difference to eager loading performance.
Every call to $item->ID in the loop will call ViewableData::__get(), which in turns ends up creating a new object via Injector. While this is a fast operation, if you have a huge number of calls, such as in my case where I was working on the highly unoptimized cms site search, with 1000 pages and 5000 content blocks, this saved over a million calls per search. All this PHP object creation was so bad it made enabling eager loading actually slower despite the drop in database calls.
This change makes it so that eager loading now faster in this particular operation, as would be expected