Skip to content

Commit

Permalink
perf/refactor: rlp (wevm#1215)
Browse files Browse the repository at this point in the history
* refactor: rlp

* chore: update tests

* tests

* vectors

* chore: format

* fix

* chore: perf boost

Co-authored-by: Sebastian Lorenz <[email protected]>

* update

* vitest

* add deprecations

* Create young-actors-fix.md

* refactor

* size-limit

* snaps

* bump size

* bench: add @ethereumjs/rlp

---------

Co-authored-by: jxom <[email protected]>
Co-authored-by: Sebastian Lorenz <[email protected]>
  • Loading branch information
3 people authored Sep 24, 2023
1 parent d5eb493 commit 6a65c5a
Show file tree
Hide file tree
Showing 38 changed files with 2,525 additions and 752 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-actors-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Refactored RLP coding to be (a lot) more performant.
16 changes: 15 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,18 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}

vectors:
name: Vectors
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Run test vectors
shell: bash
run: bun run vectors
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ tsconfig*.tsbuildinfo
.env.production.local
.envrc

# @wagmi/cli
# tests
generated.ts
vectors/**/*.json
14 changes: 7 additions & 7 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
{
"name": "viem (esm)",
"path": "./src/_esm/index.js",
"limit": "58 kB",
"limit": "59 kB",
"import": "*"
},
{
"name": "viem (cjs)",
"path": "./src/_cjs/index.js",
"limit": "73 kB"
"limit": "78 kB"
},
{
"name": "viem (minimal surface - tree-shaking)",
"path": "./src/_esm/index.js",
"limit": "4 kB",
"limit": "4.1 kB",
"import": "{ createClient, http }"
},
{
"name": "viem/accounts",
"path": "./src/_esm/accounts/index.js",
"limit": "91 kB",
"limit": "92 kB",
"import": "*"
},
{
Expand All @@ -43,7 +43,7 @@
{
"name": "viem/chains",
"path": "./src/_esm/chains/index.js",
"limit": "17 kB",
"limit": "17.3 kB",
"import": "*"
},
{
Expand All @@ -55,13 +55,13 @@
{
"name": "viem/chains/utils",
"path": "./src/_esm/chains/utils/index.js",
"limit": "8 kB",
"limit": "8.3 kB",
"import": "*"
},
{
"name": "viem/chains/utils (tree-shaking)",
"path": "./src/_esm/chains/utils/index.js",
"limit": "5 kB",
"limit": "5.5 kB",
"import": "{ parseTransactionCelo }"
},
{
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"coverage",
"tsconfig.json",
"tsconfig.*.json",
"generated.ts"
"generated.ts",
"vectors/*.json"
]
},
"formatter": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"test:ci": "CI=true vitest -c ./test/vitest.config.ts --coverage --retry=3 --bail=1",
"test:typecheck": "SKIP_GLOBAL_SETUP=true vitest typecheck -c ./test/vitest.config.ts",
"test:ui": "vitest dev -c ./test/vitest.config.ts --ui",
"vectors": "bun test vectors/**/*.test.ts",
"vectors:generate": "bun vectors/generate.ts",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
Expand All @@ -35,6 +37,7 @@
"@biomejs/biome": "^1.0.0",
"@changesets/changelog-github": "^0.4.5",
"@changesets/cli": "^2.23.2",
"@ethereumjs/rlp": "^5.0.0",
"@size-limit/preset-big-lib": "^8.2.4",
"@types/fs-extra": "^9.0.13",
"@types/which-pm-runs": "^1.0.0",
Expand Down
17 changes: 17 additions & 0 deletions src/errors/cursor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BaseError } from './base.js'

export class NegativeOffsetError extends BaseError {
override name = 'NegativeOffsetError'
constructor({ offset }: { offset: number }) {
super(`Offset \`${offset}\` cannot be negative.`)
}
}

export class PositionOutOfBoundsError extends BaseError {
override name = 'PositionOutOfBoundsError'
constructor({ length, position }: { length: number; position: number }) {
super(
`Position \`${position}\` is out of bounds (\`0 < position < ${length}\`).`,
)
}
}
5 changes: 4 additions & 1 deletion src/errors/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ByteArray, Hex } from '../types/misc.js'

import { BaseError } from './base.js'

/** @deprecated */
export class DataLengthTooLongError extends BaseError {
override name = 'DataLengthTooLongError'
constructor({ consumed, length }: { consumed: number; length: number }) {
Expand All @@ -13,11 +14,12 @@ export class DataLengthTooLongError extends BaseError {
}
}

/** @deprecated */
export class DataLengthTooShortError extends BaseError {
override name = 'DataLengthTooShortError'
constructor({ length, dataLength }: { length: number; dataLength: number }) {
super(
`Data length (${dataLength - 1}) is shorter than prefix length (${
`Data length (${dataLength - 1}) is shorter than consumed bytes length (${
length - 1
}).`,
)
Expand Down Expand Up @@ -74,6 +76,7 @@ export class InvalidHexValueError extends BaseError {
}
}

/** @deprecated */
export class OffsetOutOfBoundsError extends BaseError {
override name = 'OffsetOutOfBoundsError'
constructor({ nextOffset, offset }: { nextOffset: number; offset: number }) {
Expand Down
Loading

0 comments on commit 6a65c5a

Please sign in to comment.