Improve clone performance

Created on 4 June 2025, 3 months ago

Problem/Motivation

For complex pages with many paragraph elements on it we were facing a performance degradation for cloning.
Nodes cloning was done by Entity Clone module.

Steps to reproduce

  • Create a node with multiple various paragraphs
  • Ideally if attached paragraphs are using entity_reference fields
  • Using entity_clone (possibly replicate module would give similar result) clone a node
  • Observe time required for clone
๐Ÿ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

๐Ÿ‡ต๐Ÿ‡ฑPoland relim

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

Merge Requests

Comments & Activities

  • Issue created by @relim
  • Merge request !2043528346: Improve clone performance โ†’ (Open) created by relim
  • Pipeline finished with Failed
    3 months ago
    Total: 989s
    #514085
  • ๐Ÿ‡ต๐Ÿ‡ฑPoland relim
  • Issue was unassigned.
  • Status changed to Needs review 25 days ago
  • First commit to issue fork.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States andrewmriv Southern California

    The previous MR in #2 was on the right track โ€” caching the UUID delta maps so we donโ€™t rebuild them for every paragraph save is a big win on large nodes.

    However, the original change used request-wide static caches. This caused cross-field data leakage when cloning nodes that have more than one layout_paragraphs reference field (e.g., a โ€œcontentโ€ field and a โ€œmodalsโ€ field). In those cases, the maps built for the first field were reused for subsequent fields, breaking the parent/child structure in the second field.

    This MR in #5 keeps the performance improvement while avoiding that regression by:
    - Introducing a LayoutParagraphsParentUuidCloneMapper service to encapsulate the mapping logic.
    - Caching maps per clone context โ€” keyed by (source host, destination host, field name) โ€” so maps are only reused when itโ€™s actually safe.
    - Falling back to an unscoped (*) map only if the scoped map does not contain the required UUID, preserving compatibility for edge cases.
    - This approach still builds the source and destination maps only once per context, so cloning large, complex nodes remains fast, while ensuring multiple layout_paragraphs fields on the same node clone correctly.

Production build 0.71.5 2024