Drupal\Core\TypedData\TypedData::getPropertyPath() is slow

Created on 3 December 2018, about 6 years ago
Updated 23 February 2023, almost 2 years ago

Problem/Motivation

In an API-First context, typed data is used A LOT so any micro optimization goes a long way. During profiling in JSON:API i found strlen to be executed too many times. It turned out that the method was used to check whether we have a prefix or not, so we can have that changed to an empty() call instead.

Proposed resolution

I've changed this:

return (strlen($prefix) ? $prefix . '.' : '') . $this->name;

to this

return strlen($prefix) ? "{$prefix}.{$this->name}" : $this->name;

to leverage fast string concatenation - https://blog.blackfire.io/php-7-performance-improvements-encapsed-string...

Remaining tasks

Review, RTBC, commit.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

πŸ“Œ Task
Status

Fixed

Version

10.1 ✨

Component
Typed dataΒ  β†’

Last updated 16 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΉAustria @fago
Created by

πŸ‡§πŸ‡¬Bulgaria ndobromirov

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

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

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.

Production build 0.71.5 2024