Suppose I have a Daml Trigger that subscribes to a template Foo
. The trigger API suggests that the “update” function is called once for every transaction that creates or archives a contract of type Foo
, plus once for every completion.
Do I also get the guarantee that the “rule” is called exactly once for every observed transaction? ie is the number of MTransaction
s seen the same as calls to the rule?
I’m asking in part to figure out how to make my Trigger performant. Imagine i observe 100 transactions a second that include creates or archives to Foos
, but my rule
takes more than 10ms to execute. Will my trigger choke? Or will the Trigger start scheduling calls to rule
in some smarter way?
There is no guarantee atm and we could call the rule less frequently. So we could change triggers to run the rule less frequently if the rule is slow. Therefore rules should also generally be written such that they work correctly regardless of how often they’re called.
That said, in practice right now the rule is called once per message (including completions & transactions) and you can choke your trigger.
What you can often do to speed up your rule is to keep an index of the ACS or more generally some precomputed state that you update per transaction in a hopefully relatively cheap way (e.g. in something that only depends on the size of the transaction and not the size of the ACS) and then rule has to do very little computation.
But clearly there are limits to how much you can speed things up that way and if you exceed that triggers right now won’t be able to keep up with sustained load.
2 Likes