Skip to content

Commit

Permalink
Merge branch 'main' into holic/indexed-table-arg
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 16, 2023
2 parents f5b3dce + 708b49c commit 97c1f3c
Show file tree
Hide file tree
Showing 68 changed files with 4,681 additions and 570 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-rings-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Added `Storage.loadField` to optimize loading 32 bytes or less from storage (which is always the case when loading data for static fields).
34 changes: 34 additions & 0 deletions .changeset/sour-cycles-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@latticexyz/cli": patch
"@latticexyz/store": minor
"@latticexyz/world": patch
---

`StoreCore` and `IStore` now expose specific functions for `getStaticField` and `getDynamicField` in addition to the general `getField`.
Using the specific functions reduces gas overhead because more optimized logic can be executed.

```solidity
interface IStore {
/**
* Get a single static field from the given tableId and key tuple, with the given value field layout.
* Note: the field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out.
* Consumers are expected to truncate the returned value as needed.
*/
function getStaticField(
bytes32 tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) external view returns (bytes32);
/**
* Get a single dynamic field from the given tableId and key tuple at the given dynamic field index.
* (Dynamic field index = field index - number of static fields)
*/
function getDynamicField(
bytes32 tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) external view returns (bytes memory);
}
```
23 changes: 23 additions & 0 deletions .changeset/thin-terms-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@latticexyz/cli": patch
"@latticexyz/common": minor
"@latticexyz/store": minor
"@latticexyz/world": patch
---

Generated table libraries now have a set of functions prefixed with `_` that always use their own storage for read/write.
This saves gas for use cases where the functionality to dynamically determine which `Store` to use for read/write is not needed, e.g. root systems in a `World`, or when using `Store` without `World`.

We decided to continue to always generate a set of functions that dynamically decide which `Store` to use, so that the generated table libraries can still be imported by non-root systems.

```solidity
library Counter {
// Dynamically determine which store to write to based on the context
function set(uint32 value) internal;
// Always write to own storage
function _set(uint32 value) internal;
// ... equivalent functions for all other Store methods
}
```
111 changes: 103 additions & 8 deletions e2e/packages/contracts/src/codegen/tables/Multi.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 34 additions & 4 deletions e2e/packages/contracts/src/codegen/tables/Number.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97c1f3c

Please sign in to comment.