Only initialize computed properties when needed

Created on 13 October 2015, almost 10 years ago
Updated 11 June 2025, about 2 months ago

Just trying to see if we can avoid the costly getPropertyDefinitions() call...

To be completed...

๐Ÿ“Œ Task
Status

Postponed: needs info

Version

11.0 ๐Ÿ”ฅ

Component

entity system

Created by

๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • needs profiling

    It may affect performance, and thus requires in-depth technical reviews and profiling.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • ๐Ÿ‡ช๐Ÿ‡ธSpain psf_ Huelva

    In my use case, I have a computed field whose calculation is relatively expensiveโ€”it takes about 11 seconds every time it is calculated. This happens regardless of whether the computed field is actually used or accessed in the request. As a result, the whole request is delayed by 11 seconds, even when the computed field will not be read at all.

    Most computed fields are used only in specific contexts (for example, when rendering a view or exporting structured data), and not in every code path that loads the entity. However, the current implementation calculates all computed fields for every entity load, causing substantial and unnecessary performance degradation.

    Some key points to consider:

    • As more computed fields are defined throughout a site, performance degrades incrementally, often in hidden or hard-to-detect ways.
    • The impact is often only noticed when there are enough computed fields, or when one of them is slow to compute.
    • Delaying (lazily evaluating) the calculation until field usage would avoid unnecessary work and make the impact of computed fields more predictable and manageable.
    • This would bring Drupal in line with the principle of not doing expensive work unless and until it is explicitly needed by code.

    To sum up:
    Computed fields should not be evaluated unless their value is actually needed.
    Implementing lazy evaluation would avoid hidden and potentially significant slowdowns in any site using computed fields.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain psf_ Huelva

    My point of view is that if a site has 100 modules, and 25 of them add a computed field that takes 20ms to calculate, the site will have a response time that's 500ms slower just because of this.

Production build 0.71.5 2024