Skip to content

Add page aware implementation of an array.#7

Open
mijovic wants to merge 1 commit intocategory-labs:mainfrom
mijovic:page-aware-array-impl
Open

Add page aware implementation of an array.#7
mijovic wants to merge 1 commit intocategory-labs:mainfrom
mijovic:page-aware-array-impl

Conversation

@mijovic
Copy link
Copy Markdown
Collaborator

@mijovic mijovic commented Mar 26, 2026

No description provided.

@mijovic mijovic force-pushed the page-aware-array-impl branch 2 times, most recently from 141acae to f8956b9 Compare March 26, 2026 10:06
Comment thread src/lib/collections/README.md Outdated
Comment thread src/utils/PagedArray.sol
Comment thread src/utils/PagedArray.sol
Comment thread lib/forge-std Outdated
Comment thread src/utils/PagedArray.sol
Comment on lines +9 to +27
/// belongs to a page via:
///
/// page_index(slot) = slot >> 7
/// offset(slot) = slot & 0x7F
///
/// Once any slot on a page is accessed, all subsequent SLOAD/SSTORE on
/// that page are charged at warm cost. This library exploits that property
/// by aligning the array base to a 128-slot page boundary:
///
/// base = and(keccak256(arr.slot), not(0x7f)) — clears low 7 bits
///
/// base + 0 → length
/// base + 1 → arr[0]
/// base + 2 → arr[1]
/// ...
/// base + N → arr[N-1]
///
/// Crucially, the length is stored at `base + 0` — on the same page as
/// the data — rather than at `arr.slot` (as a native Solidity array would).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally we leverage mip-8 for arrays that use second page too, giving that this optimize only when manipulating first 127 items, then it behave with cold cost on second page(as mentioned in Slack)

@mijovic mijovic force-pushed the page-aware-array-impl branch from 31072b5 to 211634e Compare April 1, 2026 11:42
@mijovic mijovic force-pushed the page-aware-array-impl branch from 211634e to 8200243 Compare April 1, 2026 11:47
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.

2 participants