Optimise "seen" entity tracking when checking related usage

Created on 10 February 2023, over 1 year ago
Updated 11 February 2023, over 1 year ago

Problem/Motivation

When building and deploying a preview site we would experience OOM issues with just as few as 2 entities. The OOM would occur right at the beginning. I was able to isolate the issue to the method responsible for checking related usage in TomeGenerator. This method tracks entities it's "seen" by adding them to a stack using the entity as the key and its value being whether it applies or not. Entities are large objects and for the purpose of tracking in this context aren't needed, all that is needed is their type and id.

Steps to reproduce

Proposed resolution

Use an array in replacement of an SplObjectStorage and track entities using a combination of their type and id. This process is much more trivial and takes up alot less memory. As we are no longer using SplObjectStorage, convert depth to be a static variable and incremented through recursive function calls.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia mortim07

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mortim07
  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
    +++ b/src/Generate/GeneratePluginBase.php
    @@ -66,7 +66,7 @@ abstract class GeneratePluginBase extends PluginBase implements GeneratePluginIn
    -  public function entityAccess(PreviewSiteBuildInterface $build, ContentEntityInterface $entity, AccountInterface $account, EntityTypeManagerInterface $entityTypeManager): AccessResultInterface {
    +  public function entityAccess(PreviewSiteBuildInterface $build, ContentEntityInterface $entity, AccountInterface $account): AccessResultInterface {
    
    +++ b/src/Generate/GeneratePluginInterface.php
    @@ -98,13 +98,11 @@ interface GeneratePluginInterface extends PreviewSitePluginInterface {
    -   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
    -   *   Entity type manager.
    ...
    -  public function entityAccess(PreviewSiteBuildInterface $build, ContentEntityInterface $entity, AccountInterface $account, EntityTypeManagerInterface $entityTypeManager) : AccessResultInterface;
    +  public function entityAccess(PreviewSiteBuildInterface $build, ContentEntityInterface $entity, AccountInterface $account) : AccessResultInterface;
    

    Ah this we can't do, because its a public API and would be a BC break, let's leave it as is even though we won't use the argument.

    Other than that, this looks great, heaps less astronaut architecture and dramatically less complex

  • πŸ‡¦πŸ‡ΊAustralia mortim07

    @larowlan Thanks for the feedback. Ah, so you're saying that because it's a plugin folks could be calling it directly - I assume it's unlikely but valid. Probably one for a major release.

  • πŸ‡¦πŸ‡ΊAustralia mortim07

    @larowlan Ok, I've restored those files and changed the calling signature back.

  • Status changed to Fixed over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Thanks, fixed, I'll cut a new release with this and πŸ› Optimise "seen" entity tracking when checking related usage Fixed

  • πŸ‡¦πŸ‡ΊAustralia mortim07

    πŸš€

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024