I am trying to model Ethereum’s EIP 1559, which is a mechanism for pricing blockchain transactions. The idea is that user transactions accumulate over time (the “demand”, like a mempool), while block producers follow a policy for to choose which transactions to include depending on the amount they receive from the transaction (the “tip”). The transactions included in a block are then removed from the demand.
It can be quite elegantly written using cadCAD (e.g., in this notebook). Particularly, I am simulating what happens to the mechanism when demand spikes suddenly, so my state object representing the demand grows quite large.
The simulation becomes quite slow when the spike hits (you can also see a plot of that spike before the run in the notebook). I wanted to check whether this was due to how I manage the demand object, which needs to be sorted and deleted from in each step. I also logged the time it takes for a step to complete (“loop time”):
As you can see from the log above (also in the notebook), around step 32 the loop time starts increasing, while my sorting and deleting operations remain fairly quick.
To compare, I also produced the “same” simulation, this time without cadCAD, in this notebook. The loop time is much quicker, as it doesn’t seem to suffer from the same overhead (apparently I cannot put two images in a post but I left the output of the simulation run in the notebook).
All in all, it seems to me that some of the operations happening in the background of cadCAD’s execution take a bit of time when the state grows.
- This could probably be mitigated by keeping the demand out of the state, but conceptually this is very much part of my system specifications, or at least something I want cadCAD to “track” and feed into my policies.
- Another way might be to only keep in state changes to the demand (as in, differentials), since cadCAD records historical state, so at any step I should be able to reconstruct the current demand based on historical demand and historical included transactions, though this would result in code that I don’t think would be very intuitive and seems to negate the benefits of cadCAD. The simulation without cadCAD records historical state too.
- Maybe there is another much simpler reason why loop times are increasing!
I was wondering if you had more insight into what could be improved or which operations you believe could be causing the overhead. I hope the examples in the notebooks are minimal enough. I also looked into cadCAD’s source though did not do additional logging from there.
Looking forward to your ideas!