Skip to content

Performance improvements while processing PurgeOn #94

@Brajk19

Description

@Brajk19

Currently, when using #[PurgeOn] with routes where at least on route parameter is mandatory, Purgatory determines whether a subscription should be skipped after resolving all route parameters.

However, if the configuration provided to PurgeOn includes expressions that may return null, the route cannot be generated, leading Purgatory to skip the subscription entirely. The inefficiency lies in the fact that all route parameters are resolved before this decision is made.

Proposed Improvement
Instead of resolving all parameters first and then deciding whether to skip the purge, we can optimize this process by:

  1. Early Termination – If a resolved route parameter is null, and the corresponding parameter is mandatory in the route, we should immediately skip the subscription without resolving any remaining parameters.
  2. Optimized Evaluation Order – Route parameters containing nullsafe operators (e.g. assoc1?.id) should be evaluated first. If such an expression results in null, we can potentially skip the subscription earlier, avoiding unnecessary processing.

Example:

#[PurgeOn(Event::class,
    routeParams: [
        'param1' => 'id',
        'param2' => 'assoc1?.id',
        'param3' => 'assoc2?.id'
    ] 
)]

If resolving param2 returns null, there is no need to resolve param3, as the entire subscription will be skipped. Additionaly, we can move resolving param1 to the end because it does not contain nullsafe operators.

Currently, subscription is skipped here:

if (array_any($routeParamValues, static fn (array $value): bool => [] === $value)) {
return []; // skip entire subscription if a certain param value is missing
}

This check should be made after each route parameter is resolved

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions