Skip to content

Fix ~80s consumer type-checks of client aliases (#500)#525

Merged
plusminushalf merged 1 commit into
mainfrom
fix/smart-account-client-type-perf
Jul 9, 2026
Merged

Fix ~80s consumer type-checks of client aliases (#500)#525
plusminushalf merged 1 commit into
mainfrom
fix/smart-account-client-type-perf

Conversation

@plusminushalf

Copy link
Copy Markdown
Member

Checking a client created by createSmartAccountClient, createPimlicoClient, or createPasskeyServerClient against its bare alias (e.g. useQuery) forced TypeScript to structurally expand the full action surface on every call site: ~82s / 481k type instantiations in the issue's reproduction.

The client aliases now use an inline mapped-type body over a private *Inner alias, with variance annotations on the type parameters (the same pattern viem ships in SimulateContractReturnType, wevm/viem#2557). Both sides of a comparison then carry the alias's identity, so tsc compares instantiations argument-by-argument instead of expanding them: the issue's repro drops to 0.44s / 149k instantiations. rpcSchema is deliberately left unannotated so a pairwise mismatch falls back to the structural check rather than rejecting assignments that compile today. Return-type precision is unchanged.

The mapped types must stay inline: extracting them into a shared helper (e.g. Flatten) re-attaches the helper's alias identity instead and restores the slowdown (measured: 444k instantiations, no improvement).

The type-consumer fixture now guards all of this against the packed tarball: Equal-assertions that account/chain/client stay exactly inferred (what PR #511 would have widened), bare-alias assignability (which fails loudly if the variance fast path ever hard-rejects), and custom-rpcSchema fallback for all three clients.

Closes #500.

Checking a client created by createSmartAccountClient, createPimlicoClient,
or createPasskeyServerClient against its bare alias (e.g.
useQuery<SmartAccountClient>) forced TypeScript to structurally expand the
full action surface on every call site: ~82s / 481k type instantiations in
the issue's reproduction.

The client aliases now use an inline mapped-type body over a private
*Inner alias, with variance annotations on the type parameters (the same
pattern viem ships in SimulateContractReturnType, wevm/viem#2557). Both
sides of a comparison then carry the alias's identity, so tsc compares
instantiations argument-by-argument instead of expanding them: the issue's
repro drops to 0.44s / 149k instantiations. rpcSchema is deliberately left
unannotated so a pairwise mismatch falls back to the structural check
rather than rejecting assignments that compile today. Return-type
precision is unchanged.

The mapped types must stay inline: extracting them into a shared helper
(e.g. Flatten<T>) re-attaches the helper's alias identity instead and
restores the slowdown (measured: 444k instantiations, no improvement).

The type-consumer fixture now guards all of this against the packed
tarball: Equal-assertions that account/chain/client stay exactly inferred
(what PR #511 would have widened), bare-alias assignability (which fails
loudly if the variance fast path ever hard-rejects), and custom-rpcSchema
fallback for all three clients.

Closes #500. Supersedes #511.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f1fb04b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
permissionless Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.41%. Comparing base (f90ee52) to head (f1fb04b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #525   +/-   ##
=======================================
  Coverage   78.41%   78.41%           
=======================================
  Files         105      105           
  Lines        8988     8988           
  Branches      570      570           
=======================================
  Hits         7048     7048           
  Misses       1914     1914           
  Partials       26       26           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
permissionless (esm) 239.99 KB (0%)
permissionless (cjs) 369.11 KB (0%)

@plusminushalf plusminushalf merged commit 31220c4 into main Jul 9, 2026
7 checks passed
@plusminushalf plusminushalf deleted the fix/smart-account-client-type-perf branch July 9, 2026 22:22
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.

createSmartAccountClient` causes ~82s type-checking bottleneck due to deep generic inference

2 participants