WIP: Builder Lag: Massive CPU Spikes when working with dynamic data

My summation is that any editing in that field triggers an update via admin-ajax, but this is compounded if the element is within a tree as all the elements in the tree also trigger a save.

This can be tested pretty easily by copying the dynamic data element causing issues to the root level, testing how many ajax requests are made.

2 Likes

Hi @danieliser,

Thank you so much for the detailed reply :slight_smile:

Could you please share the exact functions you used? I’m unable to replicate the issue shown in your video by using an echo function that simply returns a large integer:


This is the echo function I’m calling:

function random_integer() {
	return '39874298347';
}

As for optimization methods, we’re exploring options like batching AJAX requests and reducing the number of AJAX requests needed on page load to render dynamic data. However, the issue in your video appears to be different from the original report about server CPU usage spikes on page load (which is also caused by dynamic data but not exactly the same situation).

Could you please create a new forum thread (linking to your comment here) or contact us directly at help@bricksbuilder.io?

Thank you again for the detailed report :slight_smile:

Sure thing, here is the code in question.

Also I’ll post a new issue, but I’m gonna go ahead and open an email ticket as well so I can help you get it resolved quickly in the case we need to give more private details.


add_filter("bricks/code/echo_function_names", function () {
    return [
        "date",
        "get_the_title_with_autobreak_subtext",
        "have_rows",
        "echo",
        "FallbackText",
        "HasDiscount",
        "DiscountedPrice",
        "DiscountValue",
        "LifetimeDealsRemaining",
        "NextFriday",
        "wpf_has_tag",
        "wpf_get_tag",
        "PluginActiveInstalls",
        "PluginRatingCount",
        "PluginRating",
        "PluginRatings",
        "PluginDownloads",
        "PluginCurrentVersion",
        "TotalPopupViewsLastCalculated",
        "EstViewsByDateTime",
        "EstPopupViewsPerSecond",
        "TotalPopupsViewed",
        "EstViewsAfterSeconds",
        "EstPopupViewsCurrently",
    ];
});

function TotalPopupsViewed()
{
    return 23075292335;
}

function EstPopupViewsPerSecond($seconds = null)
{
    // Average of 14 million popups per week
    $weeklyViews = 14000000;
    $dailyViews = $weeklyViews / 7;
    $viewsPerSecond = $dailyViews / 86400; // 86400 seconds in a day

    if ($seconds !== null) {
        return $viewsPerSecond * $seconds;
    }

    return $viewsPerSecond;
}

function TotalPopupViewsLastCalculated()
{
    return new DateTime("2024-05-26");
}

function EstViewsByDateTime($date = "today")
{
    $lastCalculated = TotalPopupViewsLastCalculated();
    $targetDate = new DateTime($date);

    $interval = $lastCalculated->diff($targetDate);
    $daysDifference = $interval->days;

    $viewsPerSecond = EstPopupViewsPerSecond();
    $estimatedViews = $daysDifference * 86400 * $viewsPerSecond;

    return TotalPopupsViewed() + $estimatedViews;
}

function EstPopupViewsCurrently()
{
    $new_date = (new DateTime())->format("Y-m-d");

    return EstViewsByDateTime($new_date);
}

function EstViewsAfterSeconds($seconds = 86400)
{
    $newDate = date("Y-m-d", strtotime("+ " . $seconds . " seconds"));

    return EstViewsByDateTime($newDate);
}

2 Likes

New thread here: Dynamic Data causes large numbers of AJAX requests that spike CPU to 100%+