Improve backend API when lots of components

Created on 26 March 2025, 7 days ago

Overview

Backend API become slow, when lots of components.
When testing the default xb-page from xb-demo(around 80 components), we can see that the backend takes more than 3s to return an answer when just loading the page. (Not sure also why a POST request is sent at that time from a fresh page load)
POST request on /xb/api/layout/xb_page/1

By profiling the POST request to backend API call with PHP SPX provided by ddev or docker4drupal.
The same POST request takes now 9s in total because of the overhead of the profilling.

We see 32.57 Millions functions calls...

Zoom on the 1.5s:

Full 9s:

Proposed resolution

User interface changes

๐Ÿ“Œ Task
Status

Active

Version

0.0

Component

Page builder

Created by

๐Ÿ‡ฎ๐Ÿ‡ฑIsrael heyyo Jerusalem

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

Comments & Activities

  • Issue created by @heyyo
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Thanks so much for the profiling!

    Yep, the BE is known to be slow with many components. We were already aware, @kristen pol provided me a sample page on Monday too.

    The BE is 0% optimized. 32 million function calls already says as much :D That also means that it will be easy to make it significantly faster.
    (It might be hard to make it fast enough for all scenarios, but faster than today is clearly trivial.)

    โ€œPremature optimization is โ€ฆโ€ and all that :)

    Iโ€™m SUPER stoked to see that the bulk of that time is going to shape matching and everything that calls, because thatโ€™s literally the area Iโ€™m working on next! ๐Ÿ˜„ Specifically: ๐Ÿ“Œ [later phase] Support matching `{type: array, โ€ฆ}` prop shapes Postponed . Which is exactly why not having optimized this makes sense: itโ€™s not yet feature-complete!

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    I had a hunch that ๐Ÿ“Œ Split model values into resolved and raw Active would largely fix this, and it seems correct; tested with xb_demo there is a 230x speed improvement in ::clientModelToInput() which is by far the largest single section of the flamegraph.

  • ๐Ÿ‡ฎ๐Ÿ‡ฑIsrael heyyo Jerusalem

    Wouah 230X faster, impressive, I will have to try this !

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
Production build 0.71.5 2024