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
Performance chrome dev tools

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...
32Millions of requests

Zoom on the 1.5s:
Zoom 1.5s

Full 9s:
Full 9s

Proposed resolution

User interface changes

CommentFileSizeAuthor
image (5).png711.14 KBheyyo
image (4).png694.97 KBheyyo
image (3).png11.29 KBheyyo
image (2).png450.23 KBheyyo

Comments

heyyo created an issue. See original summary.

wim leers’s picture

Title: Improve backend API when lots of components » [PP-1] Improve backend API performance: add caching to shape matching
Component: Page builder » Shape matching
Priority: Normal » Critical
Issue tags: +Performance, +stable blocker

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: #3467870: Support `{type: array, …}` prop shapes. Which is exactly why not having optimized this makes sense: it’s not yet feature-complete!

wim leers’s picture

longwave’s picture

I had a hunch that #3493943: SDC+JS Component Sources: split default values into `resolved` and `source` 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.

heyyo’s picture

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

wim leers’s picture

Title: [PP-1] Improve backend API performance: add caching to shape matching » Improve backend API performance: add caching to shape matching
Assigned: Unassigned » longwave