Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a static cache for the UUID enabled check #7094

Open
bnomei opened this issue Mar 27, 2025 · 4 comments
Open

Add a static cache for the UUID enabled check #7094

bnomei opened this issue Mar 27, 2025 · 4 comments
Assignees

Comments

@bnomei
Copy link

bnomei commented Mar 27, 2025

Description

The enabled check for UUIDs is call on every creation of every UUID object. On setups with many content pages that thousands of roundtrips to the app instance can be avoided.

Adding a simple static cache here will vastly improve that.

current

public static function enabled(): bool
	{
		return App::instance()->option('content.uuid') !== false;
	}

proposed

private static ?bool $is_enabled = null;
public static function enabled(): bool
	{
                if (static::$is_enabled !== null) {
                      return static::$is_enabled;
                }
		return static::$is_enabled = App::instance()->option('content.uuid') !== false;
	}

public static function enabled(): bool

@distantnative distantnative self-assigned this Mar 29, 2025
@distantnative
Copy link
Member

It's a bit trickier as the app instance can be cloned with new options. In that case, calling Uuids::enabled() could return a value that doesn't match the config option anymore (which happens a lot in our unit tests). And I am a bit hesitant to unset the static property of Uuid from e.g. inside App::clone().

@bnomei
Copy link
Author

bnomei commented Mar 29, 2025

just my 2c... the call is executed very often and the clone probably not, right? i mean in a regular website installation. i would argue to handle the special case in the clone method.

@bnomei
Copy link
Author

bnomei commented Mar 30, 2025

In my 20k pages testsuite Uuids:: enabled will be called 25.7k times amounting to 6.5% of all execution time. This would be a huge performance boost for the core.

@distantnative
Copy link
Member

I am not arguing against it. Just trying to find a good sustainable way as the clone method isn't the only way a new app object with different config option could be introduced during the same request. Not super likely outside of the unit tests, but it still has to work for those scenarios as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants