Skip to content

Commit 725972b

Browse files
authored
perf(client): remove redundant default instanceof fallback in ORPCError (#1764)
`ORPCError`'s custom `Symbol.hasInstance` no longer falls back to the default `instanceof` check after the cross-context constructor walk. The walk already subsumes it: any instance the default check would match carries this graph's `ORPCError` constructor in its prototype chain, and that constructor is always registered in the shared WeakSet — so the fallback could never change the result. ### Performance - `instanceof` misses (e.g. `e instanceof ORPCError` on a plain `Error` in catch paths) are ~20% faster: 2.35M → 2.87M ops/sec with a single dependency graph, 2.01M → 2.41M with multiple graphs. - Hit paths and cross-context matching behave exactly as before. ### Testing - New assertions cover the case the removed fallback used to protect: same-graph and extended instances still match while multiple dependency graphs are registered. - Client, contract, and server suites pass (970 tests); lint and `type:check` clean.
1 parent 4b86526 commit 725972b

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/client/src/error.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ describe('oRPCError', () => {
9292
expect(new Error('message') instanceof ORPCError).toBe(false)
9393
expect(new CrossContextORPCError() instanceof ORPCError).toBe(false)
9494
expect(new ExtendedCrossContextORPCError() instanceof ORPCError).toBe(false)
95+
expect(new ORPCError('test') instanceof CrossContextORPCError).toBe(false)
96+
expect(new ORPCError('test') instanceof ExtendedCrossContextORPCError).toBe(false)
9597

9698
const constructors: WeakSet<object> = (globalThis as any)[Symbol.for('ORPC_ERROR_CONSTRUCTORS')]
9799
constructors.add(CrossContextORPCError)
@@ -102,5 +104,14 @@ describe('oRPCError', () => {
102104
expect(new Error('message') instanceof ORPCError).toBe(false)
103105
expect(new CrossContextORPCError() instanceof ORPCError).toBe(true)
104106
expect(new ExtendedCrossContextORPCError() instanceof ORPCError).toBe(true)
107+
expect(new ORPCError('test') instanceof CrossContextORPCError).toBe(false)
108+
expect(new ORPCError('test') instanceof ExtendedCrossContextORPCError).toBe(false)
109+
110+
// same-graph instances still match while multiple graphs exist
111+
class ExtendedORPCError extends ORPCError<any, any> {}
112+
expect(new ORPCError('test') instanceof ORPCError).toBe(true)
113+
expect(new ExtendedORPCError('test') instanceof ORPCError).toBe(true)
114+
expect(new ExtendedORPCError('test') instanceof ExtendedORPCError).toBe(true)
115+
expect(new ORPCError('test') instanceof ExtendedORPCError).toBe(false)
105116
})
106117
})

packages/client/src/error.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ export class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
131131
}
132132
}
133133

134-
// fallback to default instanceof check
135-
return super[Symbol.hasInstance](instance)
134+
return false
136135
}
137136
}
138137

0 commit comments

Comments
 (0)