diff --git a/.changeset/stale-dryers-sparkle.md b/.changeset/stale-dryers-sparkle.md new file mode 100644 index 0000000000..50f75e6b3d --- /dev/null +++ b/.changeset/stale-dryers-sparkle.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Improved `.extend` performance with `publicActions` and other large types. diff --git a/biome.json b/biome.json index 643990ae08..46d4ef4d7d 100644 --- a/biome.json +++ b/biome.json @@ -10,6 +10,7 @@ ".vercel", "**/node_modules", "CHANGELOG.md", + "bun.lockb", "cache", "test/contracts", "test/kzg/*.json", diff --git a/src/actions/public/mulitcall.bench-d.ts b/src/actions/public/mulitcall.bench-d.ts new file mode 100644 index 0000000000..354a2c8ba2 --- /dev/null +++ b/src/actions/public/mulitcall.bench-d.ts @@ -0,0 +1,33 @@ +import { bench } from '@arktype/attest' + +import { + baycContractConfig, + 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 { 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']) diff --git a/src/actions/public/readContract.bench-d.ts b/src/actions/public/readContract.bench-d.ts new file mode 100644 index 0000000000..ce0b6c2a06 --- /dev/null +++ b/src/actions/public/readContract.bench-d.ts @@ -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']) diff --git a/src/clients/createTestClient.bench-d.ts b/src/clients/createTestClient.bench-d.ts new file mode 100644 index 0000000000..dfb1d7e2ed --- /dev/null +++ b/src/clients/createTestClient.bench-d.ts @@ -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'])