Skip to content

Commit

Permalink
test(types): bench
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed May 28, 2024
1 parent c3fa400 commit 9f9780f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-dryers-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

Improved `.extend` performance with `publicActions` and other large types.
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
".vercel",
"**/node_modules",
"CHANGELOG.md",
"bun.lockb",
"cache",
"test/contracts",
"test/kzg/*.json",
Expand Down
33 changes: 33 additions & 0 deletions src/actions/public/mulitcall.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { bench } from '@arktype/attest'

import {
baycContractConfig,
usdcContractConfig,
} from '../../../test/src/abis.js'

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Size

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Verify / Test Environments (bun)

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Verify / Test Environments (node-20)

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Verify / Test Environments (node-latest)

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Verify / Test Environments (node-18)

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.

Check failure on line 6 in src/actions/public/mulitcall.bench-d.ts

View workflow job for this annotation

GitHub Actions / Verify / Build

File '/home/runner/work/viem/viem/test/src/abis.ts' is not under 'rootDir' '/home/runner/work/viem/viem/src'. 'rootDir' is expected to contain all source files.
import { anvil } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { http } from '../../clients/transports/http.js'
import { multicall } from './multicall.js'

bench('multicall return type', async () => {
const client = createClient({ chain: anvil, transport: http() })
const res = multicall(client, {
allowFailure: false,
contracts: [
{
...usdcContractConfig,
functionName: 'totalSupply',
},
{
...usdcContractConfig,
functionName: 'balanceOf',
args: ['0x...'],
},
{
...baycContractConfig,
functionName: 'name',
},
],
})
return {} as typeof res
}).types([192503, 'instantiations'])
17 changes: 17 additions & 0 deletions src/actions/public/readContract.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { bench } from '@arktype/attest'

import { usdcContractConfig } from '../../../test/src/abis.js'
import { anvil } from '../../chains/index.js'
import { createClient } from '../../clients/createClient.js'
import { http } from '../../clients/transports/http.js'
import { readContract } from './readContract.js'

bench('readContract return type', async () => {
const client = createClient({ chain: anvil, transport: http() })
const res = readContract(client, {
...usdcContractConfig,
functionName: 'balanceOf',
args: ['0x...'],
})
return {} as typeof res
}).types([152288, 'instantiations'])
18 changes: 18 additions & 0 deletions src/clients/createTestClient.bench-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bench } from '@arktype/attest'

import { createClient } from './createClient.js'
import { createTestClient } from './createTestClient.js'
import { testActions } from './decorators/test.js'
import { http } from './transports/http.js'

bench('createTestClient', () => {
const client = createTestClient({ mode: 'anvil', transport: http() })
return {} as typeof client
}).types([668, 'instantiations'])

bench('createClient.extend + testActions', () => {
const client = createClient({ transport: http() }).extend(
testActions({ mode: 'anvil' }),
)
return {} as typeof client
}).types([6275, 'instantiations'])

0 comments on commit 9f9780f

Please sign in to comment.