Skip to content

[midnight adapter] unordered array - #921

Draft
adhusson wants to merge 41 commits into
feat/adapter-v2from
unsorted
Draft

[midnight adapter] unordered array#921
adhusson wants to merge 41 commits into
feat/adapter-v2from
unsorted

Conversation

@adhusson

@adhusson adhusson commented May 20, 2026

Copy link
Copy Markdown
Contributor

Simpler to think about than linked list code.

For gas there is an extra cost of having to open <= 10 additional slots over the lifetime of the contract (the max slots used by the array).

Then we get those gas numbers:

approx. average number of cold reads

operation                         linked list             unsorted
----------------------------------------------------------------------
accrual, == 0 maturities reached  ~1                     ~1
accrual, >= 1 maturity reached    ~reached               ~10 + reached
insert new maturity               ~future maturities/2   ~1
delete maturity to 0              ~1                     ~1

adhusson added 5 commits May 16, 2026 00:38
# Conflicts:
#	src/adapters/MidnightAdapter.sol
#	src/adapters/interfaces/IMidnightAdapter.sol
#	test/MidnightAdapterTest.sol
@adhusson adhusson changed the title Unsorted [midnight adapter] unordered array May 20, 2026
@adhusson adhusson mentioned this pull request May 20, 2026
3 tasks
Comment on lines +13 to +14
uint8 durationCount;
uint8 index; // index in pendingMaturities

@adhusson adhusson Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have uint120 growth, pack growth with durationCount, remove index, and scan the pending maturities every time we remove one (max 22k gas) to get 1 less slot used per maturity.

Done here #932

@adhusson adhusson self-assigned this Jun 12, 2026
# Conflicts:
#	test/MidnightAdapterTest.sol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant