Optimize BigPipe::getPlaceholderOrder()

Created on 6 February 2021, almost 4 years ago
Updated 15 February 2023, almost 2 years ago

Motivation

BigPipe currently uses explode() and multiple loops to find big-pipe placeholders to determine the processing order.

This issue is about optimizing that method.

📌 Task
Status

Closed: works as designed

Version

10.1

Component
BigPipe 

Last updated 3 days ago

Created by

🇳🇱Netherlands casey

Live updates comments and jobs are added and updated live.
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.

  • The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Interface previews/skeleton screens through optional "preview" or "placeholder" templates Fixed changed the BigPipe::getPlaceholderOrder() logic.

    1. +++ b/core/modules/big_pipe/src/Render/BigPipe.php
      @@ -735,20 +715,44 @@ protected function getPlaceholderOrder($html, $placeholders) {
      +    $ordered_placeholders = [];
      +
      +    $needle = '<span data-big-pipe-placeholder-id="';
      +    $needle_len = strlen($needle);
      +    $end = 0;
      +    while (($start = strpos($html, $needle, $end)) !== FALSE) {
      +      $start += $needle_len;
      +      $end = strpos($html, '"', $start);
      +      if ($end === FALSE) {
      +        break;
      +      }
      

      This is irrelevant since Interface previews/skeleton screens through optional "preview" or "placeholder" templates Fixed .

    2. +++ b/core/modules/big_pipe/src/Render/BigPipe.php
      @@ -735,20 +715,44 @@ protected function getPlaceholderOrder($html, $placeholders) {
      +      // Skip unknown placeholders.
      +      if (!isset($placeholders[$placeholder_id])) {
      +        continue;
      +      }
      +      // If the placeholder occurs multiple times, only keep the first.
      +      if (isset($ordered_placeholders[$placeholder_id]) || isset($message_placeholders[$placeholder_id])) {
      +        continue;
      +      }
      

      I think this is the remaining optimization potential.

  • Status changed to Closed: works as designed almost 2 years ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I wanted to reroll #11.2 on HEAD, but:

    1. +      // If the placeholder occurs multiple times, only keep the first.
      +      if (isset($ordered_placeholders[$placeholder_id]) || isset($message_placeholders[$placeholder_id])) {
      +        continue;
      +      }
      

      This is already handled by

      $placeholder_ids = array_unique($placeholder_ids);
      

      in HEAD.

    2. +      // Skip unknown placeholders.
      +      if (!isset($placeholders[$placeholder_id])) {
      +        continue;
      +      }
      

      This is only possible in theory — if somebody literally hardcoded a BigPipe placeholder in their theme's or module's markup. That'd be a bug there. I'd rather have BigPipe fail in that case. Also, I've yet to see the very first bug report for this (I just finished triaging the BigPipe module's issue queue).

  • 🇮🇳India nikhil_110

    Attached patch against Drupal 10.1.x

Production build 0.71.5 2024