Skip to content

Refactor subscription engine#848

Merged
DavidBadura merged 12 commits into
4.0.xfrom
refactor-subscription-engine
Jun 13, 2026
Merged

Refactor subscription engine#848
DavidBadura merged 12 commits into
4.0.xfrom
refactor-subscription-engine

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Apr 26, 2026

Copy link
Copy Markdown
Member

The SubscriptionEngine interface has been changed.
The methods setup, boot, run, teardown, remove, reactivate, pause and refresh have been replaced
by a single execute method that takes a command object.
The ids and groups filters, previously passed via SubscriptionEngineCriteria,
are now constructor parameters of the command objects.
The SubscriptionEngineCriteria is now only used for the subscriptions method.

before:

use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngineCriteria;

/** @var SubscriptionEngine $subscriptionEngine */
$subscriptionEngine->setup(new SubscriptionEngineCriteria(ids: ['profile_1']), skipBooting: true);
$subscriptionEngine->boot(new SubscriptionEngineCriteria(ids: ['profile_1']), limit: 100);
$subscriptionEngine->run(new SubscriptionEngineCriteria(ids: ['profile_1']), limit: 100);
$subscriptionEngine->teardown(new SubscriptionEngineCriteria(ids: ['profile_1']));
$subscriptionEngine->remove(new SubscriptionEngineCriteria(ids: ['profile_1']));
$subscriptionEngine->reactivate(new SubscriptionEngineCriteria(ids: ['profile_1']));
$subscriptionEngine->pause(new SubscriptionEngineCriteria(ids: ['profile_1']));
$subscriptionEngine->refresh(new SubscriptionEngineCriteria(ids: ['profile_1']));

after:

use Patchlevel\EventSourcing\Subscription\Engine\Command\Boot;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Pause;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Reactivate;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Refresh;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Remove;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Run;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Setup;
use Patchlevel\EventSourcing\Subscription\Engine\Command\Teardown;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;

/** @var SubscriptionEngine $subscriptionEngine */
$subscriptionEngine->execute(new Setup(ids: ['profile_1'], skipBooting: true));
$subscriptionEngine->execute(new Boot(ids: ['profile_1'], limit: 100));
$subscriptionEngine->execute(new Run(ids: ['profile_1'], limit: 100));
$subscriptionEngine->execute(new Teardown(ids: ['profile_1']));
$subscriptionEngine->execute(new Remove(ids: ['profile_1']));
$subscriptionEngine->execute(new Reactivate(ids: ['profile_1']));
$subscriptionEngine->execute(new Pause(ids: ['profile_1']));
$subscriptionEngine->execute(new Refresh(ids: ['profile_1']));

Further changes:

  • The CanRefreshSubscriptions interface has been removed. Refresh is now part of the SubscriptionEngine interface via the Refresh command.
  • ProcessedResult now extends Result, so the execute method always returns a Result. The Boot and Run commands return a ProcessedResult.
  • The DefaultSubscriptionEngine accepts an optional EventDispatcherInterface as last constructor argument to hook into the engine with own listeners.

@DavidBadura DavidBadura added this to the 4.0.0 milestone Apr 26, 2026
@DavidBadura DavidBadura changed the base branch from 3.20.x to 4.0.x April 26, 2026 09:07
Comment thread src/Subscription/Engine/LegacyWrapperSubscriptionEngine.php Outdated
@DavidBadura DavidBadura force-pushed the refactor-subscription-engine branch from 3929aca to c7f4ba6 Compare April 26, 2026 09:54
@github-actions

github-actions Bot commented Apr 26, 2026

Copy link
Copy Markdown

Hello 👋

here is the most recent benchmark result:

SplitStreamBench
================

+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                         | time (kde mode)                                     | memory                                     |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                 | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000Events () | 3.539ms (±0.00%)   | 3.465ms (±0.00%)   | +2.15%    | 35.834mb        | 36.286mb   | -1.25%      |
| benchSave10000Events () | 502.689ms (±0.00%) | 513.501ms (±0.00%) | -2.11%    | 35.903mb        | 36.421mb   | -1.42%      |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SubscriptionEngineBatchBench
============================

+---------------------------+--------------------+-------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                    | memory                                     |
+---------------------------+--------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>     | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+--------------------+-------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 103.954ms (±0.00%) | 95.247ms (±0.00%) | +9.14%    | 35.720mb        | 35.720mb   | 0.00%       |
+---------------------------+--------------------+-------------------+-----------+-----------------+------------+-------------+

CommandToQueryBench
===================

+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
|                | time (kde mode)                                 | memory                                     |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
| subject        | Tag: <current>   | Tag: base        | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
| benchCreate () | 2.796ms (±0.00%) | 2.650ms (±0.00%) | +5.51%    | 5.005mb         | 4.727mb    | +5.89%      |
| benchUpdate () | 4.216ms (±0.00%) | 4.320ms (±0.00%) | -2.40%    | 5.014mb         | 4.913mb    | +2.06%      |
| benchBoth ()   | 7.357ms (±0.00%) | 7.203ms (±0.00%) | +2.13%    | 5.752mb         | 5.121mb    | +12.32%     |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+

SimpleSetupTaggableStoreBench
=============================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 1.128ms (±0.00%)   | 1.117ms (±0.00%)   | +0.97%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchLoad10000Events ()                | 72.645ms (±0.00%)  | 74.840ms (±0.00%)  | -2.93%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchSave1Event ()                     | 1.360ms (±0.00%)   | 1.325ms (±0.00%)   | +2.64%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchSave10000Events ()                | 310.184ms (±0.00%) | 310.028ms (±0.00%) | +0.05%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchSave10000Aggregates ()            | 9.239s (±0.00%)    | 9.408s (±0.00%)    | -1.80%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 5.327s (±0.00%)    | 5.308s (±0.00%)    | +0.36%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchAppend1Event ()                   | 1.615ms (±0.00%)   | 1.624ms (±0.00%)   | -0.56%    | 36.306mb        | 36.306mb   | 0.00%       |
| benchAppend100Events ()                | 7.617ms (±0.00%)   | 7.516ms (±0.00%)   | +1.34%    | 36.306mb        | 36.306mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SnapshotsBench
==============

+----------------------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                   | memory                                     |
+----------------------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>    | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| benchLoad10000EventsMissingSnapshot () | 72.884ms (±0.00%) | 74.652ms (±0.00%) | -2.37%    | 35.210mb        | 35.210mb   | 0.00%       |
| benchLoad10000Events ()                | 1.335ms (±0.00%)  | 1.362ms (±0.00%)  | -2.05%    | 35.210mb        | 35.210mb   | 0.00%       |
+----------------------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+

SimpleSetupStreamStoreBench
===========================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 1.201ms (±0.00%)   | 1.210ms (±0.00%)   | -0.77%    | 35.140mb        | 35.140mb   | 0.00%       |
| benchLoad10000Events ()                | 70.740ms (±0.00%)  | 69.003ms (±0.00%)  | +2.52%    | 35.140mb        | 35.140mb   | 0.00%       |
| benchSave1Event ()                     | 1.475ms (±0.00%)   | 1.395ms (±0.00%)   | +5.76%    | 35.140mb        | 35.140mb   | 0.00%       |
| benchSave10000Events ()                | 288.830ms (±0.00%) | 289.958ms (±0.00%) | -0.39%    | 35.140mb        | 35.140mb   | 0.00%       |
| benchSave10000Aggregates ()            | 9.630s (±0.00%)    | 9.135s (±0.00%)    | +5.42%    | 35.140mb        | 35.140mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 5.298s (±0.00%)    | 5.337s (±0.00%)    | -0.73%    | 35.140mb        | 35.140mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

SubscriptionEngineBench
=======================

+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                               | memory                                     |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>  | Tag: base       | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 3.317s (±0.00%) | 3.312s (±0.00%) | +0.15%    | 48.293mb        | 48.293mb   | 0.00%       |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+

PersonalDataBench
=================

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 1.184ms (±0.00%)   | 1.205ms (±0.00%)   | -1.78%    | 35.804mb        | 35.804mb   | 0.00%       |
| benchLoad10000Events ()                | 110.931ms (±0.00%) | 109.836ms (±0.00%) | +1.00%    | 35.804mb        | 35.804mb   | 0.00%       |
| benchSave1Event ()                     | 1.873ms (±0.00%)   | 2.146ms (±0.00%)   | -12.72%   | 35.804mb        | 35.804mb   | 0.00%       |
| benchSave10000Events ()                | 314.526ms (±0.00%) | 324.035ms (±0.00%) | -2.93%    | 35.806mb        | 35.806mb   | 0.00%       |
| benchSave10000Aggregates ()            | 13.332s (±0.00%)   | 13.449s (±0.00%)   | -0.87%    | 35.804mb        | 35.804mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 9.619s (±0.00%)    | 9.608s (±0.00%)    | +0.11%    | 36.044mb        | 36.044mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

This comment gets update everytime a new commit comes in!

@DavidBadura DavidBadura force-pushed the refactor-subscription-engine branch from 56fba2a to f17c3f5 Compare May 22, 2026 07:34
Comment thread src/Subscription/Engine/NextSubscriptionEngine.php Outdated
Comment thread src/Subscription/Engine/Command/Command.php
@DanielBadura DanielBadura added the enhancement New feature or request label Jun 13, 2026
@DavidBadura DavidBadura merged commit 543bd2c into 4.0.x Jun 13, 2026
36 of 39 checks passed
@DavidBadura DavidBadura deleted the refactor-subscription-engine branch June 13, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BC-Break enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants