Skip to content

Allow reading events from a position with AppendStore::query() - #924

Merged
DavidBadura merged 1 commit into
4.0.xfrom
append-store-query-from
Oct 3, 2026
Merged

DavidBadura merged 1 commit into
4.0.xfrom
append-store-query-from

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

The DCB spec says a store "SHOULD provide a way to read Events from a given starting Sequence Position". AppendStore::query() always returned all matching events, so we didn't cover that yet.

query() now takes an optional from index, which is inclusive like in the reference implementation on dcb.events:

$stream = $store->query(new Query(new SubQuery(['hotel:1'])), 1000);

It only limits what is read. What matches is still defined by tags and event types alone, and the append condition is unaffected. Combined with onlyLastEvent, the last matching event is looked up first and dropped if it is before from, the same in both stores.

This is meant as the base for a split stream equivalent in DCB: the decision model builder looks up the last split event of a projection and reads from there, while the store doesn't need to know anything about split events.

The DCB spec says a store should provide a way to read events from a given
starting position. AppendStore::query() always returned all matching events.

query() now takes an optional `from` index (inclusive). It only limits what is
read, the query itself and the append condition stay the same. This is the
base for cutting off irrelevant history when building a decision model.
@DavidBadura DavidBadura added this to the 4.0.0 milestone Oct 3, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 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 () | 2.163ms (±0.00%)   | 2.402ms (±0.00%)   | -9.95%    | 35.774mb        | 36.295mb   | -1.43%      |
| benchSave10000Events () | 564.277ms (±0.00%) | 518.140ms (±0.00%) | +8.90%    | 35.909mb        | 35.909mb   | 0.00%       |
+-------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 911.800μs (±0.00%) | 891.100μs (±0.00%) | +2.32%    | 36.312mb        | 36.312mb   | 0.00%       |
| benchLoad10000Events ()                | 56.421ms (±0.00%)  | 55.909ms (±0.00%)  | +0.92%    | 36.312mb        | 36.312mb   | 0.00%       |
| benchSave1Event ()                     | 1.317ms (±0.00%)   | 10.289ms (±0.00%)  | -87.20%   | 36.312mb        | 36.312mb   | 0.00%       |
| benchSave10000Events ()                | 345.200ms (±0.00%) | 299.504ms (±0.00%) | +15.26%   | 36.312mb        | 36.312mb   | 0.00%       |
| benchSave10000Aggregates ()            | 12.627s (±0.00%)   | 14.679s (±0.00%)   | -13.98%   | 36.312mb        | 36.312mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.664s (±0.00%)    | 4.711s (±0.00%)    | -1.01%    | 36.312mb        | 36.312mb   | 0.00%       |
| benchAppend1Event ()                   | 1.262ms (±0.00%)   | 1.368ms (±0.00%)   | -7.75%    | 36.312mb        | 36.312mb   | 0.00%       |
| benchAppend100Events ()                | 6.210ms (±0.00%)   | 9.137ms (±0.00%)   | -32.04%   | 36.312mb        | 36.312mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                               | memory                                     |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>  | Tag: base       | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 2.512s (±0.00%) | 2.518s (±0.00%) | -0.23%    | 48.301mb        | 48.301mb   | 0.00%       |
+---------------------------+-----------------+-----------------+-----------+-----------------+------------+-------------+

NoopSubscriptionEngineBench
===========================

+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                   | memory                                     |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>    | Tag: base         | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 89.963ms (±0.00%) | 80.703ms (±0.00%) | +11.47%   | 48.301mb        | 48.301mb   | 0.00%       |
+---------------------------+-------------------+-------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 1.076ms (±0.00%)   | 1.042ms (±0.00%)   | +3.23%    | 35.146mb        | 35.146mb   | 0.00%       |
| benchLoad10000Events ()                | 55.600ms (±0.00%)  | 56.947ms (±0.00%)  | -2.36%    | 35.146mb        | 35.146mb   | 0.00%       |
| benchSave1Event ()                     | 1.312ms (±0.00%)   | 1.234ms (±0.00%)   | +6.36%    | 35.146mb        | 35.146mb   | 0.00%       |
| benchSave10000Events ()                | 250.243ms (±0.00%) | 238.732ms (±0.00%) | +4.82%    | 35.146mb        | 35.146mb   | 0.00%       |
| benchSave10000Aggregates ()            | 13.990s (±0.00%)   | 7.769s (±0.00%)    | +80.07%   | 35.146mb        | 35.146mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 4.635s (±0.00%)    | 4.593s (±0.00%)    | +0.91%    | 35.147mb        | 35.147mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+---------------------------+-------------------+--------------------+-----------+-----------------+------------+-------------+
|                           | time (kde mode)                                    | memory                                     |
+---------------------------+-------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                   | Tag: <current>    | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+---------------------------+-------------------+--------------------+-----------+-----------------+------------+-------------+
| benchHandle10000Events () | 90.955ms (±0.00%) | 101.575ms (±0.00%) | -10.46%   | 35.726mb        | 35.726mb   | 0.00%       |
+---------------------------+-------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad1Event ()                     | 709.400μs (±0.00%) | 698.200μs (±0.00%) | +1.60%    | 37.008mb        | 37.008mb   | 0.00%       |
| benchLoad10000Events ()                | 135.088ms (±0.00%) | 136.424ms (±0.00%) | -0.98%    | 37.008mb        | 37.008mb   | 0.00%       |
| benchSave1Event ()                     | 1.740ms (±0.00%)   | 1.738ms (±0.00%)   | +0.07%    | 37.008mb        | 37.008mb   | 0.00%       |
| benchSave10000Events ()                | 343.826ms (±0.00%) | 338.296ms (±0.00%) | +1.63%    | 37.063mb        | 37.063mb   | 0.00%       |
| benchSave10000Aggregates ()            | 15.648s (±0.00%)   | 12.115s (±0.00%)   | +29.17%   | 37.008mb        | 37.008mb   | 0.00%       |
| benchSave10000AggregatesTransaction () | 8.488s (±0.00%)    | 8.450s (±0.00%)    | +0.46%    | 37.008mb        | 37.008mb   | +0.00%      |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
|                                        | time (kde mode)                                     | memory                                     |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| subject                                | Tag: <current>     | Tag: base          | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+
| benchLoad10000EventsMissingSnapshot () | 54.734ms (±0.00%)  | 56.429ms (±0.00%)  | -3.00%    | 35.151mb        | 35.151mb   | 0.00%       |
| benchLoad10000Events ()                | 882.600μs (±0.00%) | 870.000μs (±0.00%) | +1.45%    | 35.151mb        | 35.151mb   | 0.00%       |
+----------------------------------------+--------------------+--------------------+-----------+-----------------+------------+-------------+

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

+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
|                | time (kde mode)                                 | memory                                     |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
| subject        | Tag: <current>   | Tag: base        | time-diff | Tag: <current>  | Tag: base  | memory-diff |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+
| benchCreate () | 2.954ms (±0.00%) | 2.982ms (±0.00%) | -0.95%    | 5.057mb         | 5.057mb    | 0.00%       |
| benchUpdate () | 4.094ms (±0.00%) | 4.039ms (±0.00%) | +1.36%    | 5.067mb         | 5.067mb    | 0.00%       |
| benchBoth ()   | 8.000ms (±0.00%) | 6.804ms (±0.00%) | +17.58%   | 5.389mb         | 5.389mb    | 0.00%       |
+----------------+------------------+------------------+-----------+-----------------+------------+-------------+

This comment gets update everytime a new commit comes in!

@DavidBadura
DavidBadura merged commit 44a9f3b into 4.0.x Oct 3, 2026
37 of 39 checks passed
@DavidBadura
DavidBadura deleted the append-store-query-from branch October 3, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants